def _get_item(mediatype, filename): # To ensure compatibility with previously exported items, # make the filename legal fname = xbmc.makeLegalFilename(filename) untranslated_path = os.path.dirname(fname).decode("utf-8") translated_path = os.path.dirname( xbmc.translatePath(fname).decode("utf-8")) shortname = os.path.basename(xbmc.translatePath(fname).decode("utf-8")) # We get the data from Kodi library using filters. # This is much faster than loading all episodes in memory # First build the path filter, we may have to search in both special and translated path path_filter = {'field': 'path', 'operator': 'startswith', 'value': translated_path} \ if fname[:10] != 'special://' \ else {'or': [ {'field': 'path', 'operator': 'startswith', 'value': translated_path}, {'field': 'path', 'operator': 'startswith', 'value': untranslated_path} ]} # Now build the all request and call the json-rpc function through common.get_library_items library_item = common.get_library_items( mediatype, { 'and': [ path_filter, { 'field': 'filename', 'operator': 'is', 'value': shortname } ] })[0] if not library_item: raise ItemNotFound return common.get_library_item_details(mediatype, library_item[mediatype + 'id'])
def _get_item(mediatype, filename): exported_filepath = os.path.normcase(xbmc.translatePath(filename).decode("utf-8")) for library_item in common.get_library_items(mediatype): if os.path.normcase(library_item['file']) == exported_filepath: return common.get_library_item_details( mediatype, library_item[mediatype + 'id']) raise ItemNotFound
def _remove_from_kodi_library(videoid): """Remove an item from the Kodi library.""" common.info('Removing {} videoid from Kodi library', videoid) try: kodi_library_items = [get_item(videoid)] if videoid.mediatype == common.VideoId.SHOW or videoid.mediatype == common.VideoId.SEASON: # Retrieve the all episodes in the export folder filters = { 'and': [{ 'field': 'path', 'operator': 'startswith', 'value': os.path.dirname(kodi_library_items[0]['file']) }, { 'field': 'filename', 'operator': 'endswith', 'value': '.strm' }] } if videoid.mediatype == common.VideoId.SEASON: # Add a season filter in case we just want to remove a season filters['and'].append({ 'field': 'season', 'operator': 'is', 'value': str(kodi_library_items[0]['season']) }) kodi_library_items = common.get_library_items( common.VideoId.EPISODE, filters) for item in kodi_library_items: rpc_params = { 'movie': ['VideoLibrary.RemoveMovie', 'movieid'], # We should never remove an entire show # 'show': ['VideoLibrary.RemoveTVShow', 'tvshowid'], # Instead we delete all episodes listed in the JSON query above 'show': ['VideoLibrary.RemoveEpisode', 'episodeid'], 'season': ['VideoLibrary.RemoveEpisode', 'episodeid'], 'episode': ['VideoLibrary.RemoveEpisode', 'episodeid'] }[videoid.mediatype] common.debug(item) common.json_rpc(rpc_params[0], {rpc_params[1]: item[rpc_params[1]]}) except ItemNotFound: common.warn('Cannot remove {} from Kodi library, item not present', videoid) except KeyError as exc: ui.show_notification(common.get_local_string(30120), time=7500) common.warn( 'Cannot remove {} from Kodi library, Kodi does not support this (yet)', exc)
def _get_item(mediatype, filename): # To ensure compatibility with previously exported items, # make the filename legal fname = xbmc.makeLegalFilename(filename) path = os.path.dirname(xbmc.translatePath(fname).decode("utf-8")) shortname = os.path.basename(xbmc.translatePath(fname).decode("utf-8")) # We get the data from Kodi library using filters. # This is much faster than loading all episodes in memory library_item = common.get_library_items( mediatype, {'and': [ {'field': 'path', 'operator': 'startswith', 'value': path}, {'field': 'filename', 'operator': 'is', 'value': shortname} ]})[0] return common.get_library_item_details( mediatype, library_item[mediatype + 'id']) raise ItemNotFound