Skip to content

Commit

Permalink
Merge pull request #2623 from jurialmunkey/nexus.script.module.infota…
Browse files Browse the repository at this point in the history
…gger

[script.module.infotagger] 0.0.8
  • Loading branch information
basrieter authored Jun 14, 2024
2 parents ca401c7 + 54374c0 commit 1853cf9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
15 changes: 15 additions & 0 deletions script.module.infotagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,18 @@ stream_details = {
info_tag.set_stream_details(stream_details)
```


Currently there are no setters for the size, count, and date infolabels. The optional `set_info_tag` method will first set these infolabels using `setInfo()` method of the listitem before passing through the remainer of the dictionary to the `set_info` method of ListItemInfoTag. The method then returns the ListItemInfoTag object for further use.

Using this method is not recommended unless these infolabels are essential. It has additional overhead costs in rerouting the dictionary, and it may not remain backwards compatible in future versions of Kodi when the setInfo method is eventually depreciated entirely.

```python
from infotagger.listitem import set_info_tag

# Make your listitem as normal
li = xbmcgui.ListItem()

# Pass listitem to the method and specify tag type
info_tag = set_info_tag(li, infolabels, 'video')
```

2 changes: 1 addition & 1 deletion script.module.infotagger/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.infotagger" name="InfoTagger" provider-name="jurialmunkey" version="0.0.7">
<addon id="script.module.infotagger" name="InfoTagger" provider-name="jurialmunkey" version="0.0.8">
<requires>
<import addon="xbmc.python" version="3.0.1"/>
</requires>
Expand Down
26 changes: 22 additions & 4 deletions script.module.infotagger/resources/modules/infotagger/listitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ def set_info(self, infolabels: dict):
raise TypeError
func(v)

except AttributeError:
""" InfoTag setter doesnt exist for that key so skip.
Occurs when user is on Kodi version before that particular setter was added.
Error caught without raising to maintain backwards compatibility without versioning.
"""
continue

except KeyError:
if _tag_attr.get('skip'):
if 'skip' in _tag_attr:
continue

if 'route' in _tag_attr:
Expand All @@ -84,13 +91,17 @@ def set_info(self, infolabels: dict):
except TypeError:
func(_tag_attr['convert'](v)) # Attempt to force conversion to correct type

def set_datetime(self, label: str, *args, **kwargs):
""" Wrapper for ListItem.setInfo() to ListItem.setDateTime() """
self._listitem.setDateTime(label)


class _ListItemInfoTagVideo(_ListItemInfoTag):
_tag_gttr = 'getVideoInfoTag'
_tag_attr = {
'size': {'skip': True}, # Currently no infoTag setter for this property
'count': {'skip': True}, # Currently no infoTag setter for this property
'date': {'attr': 'setDateAdded', 'convert': str, 'classinfo': str}, # Unsure if this is the correct place to route this generic value
'date': {'route': 'set_datetime'},
'genre': {'attr': 'setGenres', 'convert': lambda x: [x], 'classinfo': (list, tuple)},
'country': {'attr': 'setCountries', 'convert': lambda x: [x], 'classinfo': (list, tuple)},
'year': {'attr': 'setYear', 'convert': int, 'classinfo': int},
Expand Down Expand Up @@ -193,8 +204,14 @@ def add_stream_info(self, stream_type, stream_values):
def set_resume_point(self, infoproperties: dict, resume_key='ResumeTime', total_key='TotalTime', pop_keys=True):
""" Wrapper to get/pop resumetime and totaltime properties for InfoTagVideo.setResumePoint() """
getter_func = infoproperties.pop if pop_keys else infoproperties.get
resume_time = getter_func(resume_key, None)
total_time = getter_func(total_key, None)
try:
resume_time = float(getter_func(resume_key, 0.0))
except ValueError:
resume_time = None
try:
total_time = float(getter_func(total_key, 0.0))
except ValueError:
total_time = None
if resume_time and total_time:
self._info_tag.setResumePoint(resume_time, total_time)
elif resume_time:
Expand Down Expand Up @@ -232,6 +249,7 @@ class _ListItemInfoTagMusic(_ListItemInfoTag):
'musicbrainzartistid': {'attr': 'setMusicBrainzArtistID', 'convert': lambda x: [x], 'classinfo': (list, tuple)},
'musicbrainzalbumid': {'attr': 'setMusicBrainzAlbumID', 'convert': str, 'classinfo': str},
'musicbrainzalbumartistid': {'attr': 'setMusicBrainzAlbumArtistID', 'convert': lambda x: [x], 'classinfo': (list, tuple)},
'songvideourl': {'attr': 'setSongVideoURL', 'convert': str, 'classinfo': str},
'comment': {'attr': 'setComment', 'convert': str, 'classinfo': str},
'albumartist': {'attr': 'setAlbumArtist', 'convert': str, 'classinfo': str}, # Not listed in setInfo docs but included for forward compatibility
}
Expand Down

0 comments on commit 1853cf9

Please sign in to comment.