diff --git a/script.module.infotagger/README.md b/script.module.infotagger/README.md index 3ee0e00ee..fcd7c4aa9 100644 --- a/script.module.infotagger/README.md +++ b/script.module.infotagger/README.md @@ -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') +``` + diff --git a/script.module.infotagger/addon.xml b/script.module.infotagger/addon.xml index 269723139..079b6be33 100644 --- a/script.module.infotagger/addon.xml +++ b/script.module.infotagger/addon.xml @@ -1,5 +1,5 @@ - + diff --git a/script.module.infotagger/resources/modules/infotagger/listitem.py b/script.module.infotagger/resources/modules/infotagger/listitem.py index 8adee8f2b..5194ca2e4 100644 --- a/script.module.infotagger/resources/modules/infotagger/listitem.py +++ b/script.module.infotagger/resources/modules/infotagger/listitem.py @@ -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: @@ -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}, @@ -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: @@ -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 }