def run(action): item = sys.listitem # pylint: disable=no-member if not item: contextLog('missing ListItem', xbmc.LOGERROR) return itemId = Api.getItemIdFromListItem(item) if not itemId: contextLog(f'cannot determine the Emby identifier of "{item.getLabel()}"', xbmc.LOGERROR) return mediaProviderId = item.getMediaProviderId() if not mediaProviderId: contextLog(f"cannot determine the media provider identifier of {listItem2str(item, itemId)}", xbmc.LOGERROR) return # get the media provider mediaProvider = xbmcmediaimport.getProviderById(mediaProviderId) if not mediaProvider: contextLog( f"cannot determine the media provider ({mediaProviderId}) of {listItem2str(item, itemId)}", xbmc.LOGERROR) return # prepare the media provider settings if not mediaProvider.prepareSettings(): contextLog( f"cannot prepare media provider ({mediaProvider2str(mediaProvider)}) settings of {listItem2str(item, itemId)}", xbmc.LOGERROR) return if action == ContextAction.Play: play(item, itemId, mediaProvider) elif action == ContextAction.Synchronize: synchronize(item, itemId, mediaProvider) elif action == ContextAction.RefreshMetadata: refreshMetadata(item, itemId, mediaProvider) else: raise ValueError(f"unknown action {action}")
def updateOnProvider(handle, options): # retrieve the media import mediaImport = xbmcmediaimport.getImport(handle) if not mediaImport: log('cannot retrieve media import', xbmc.LOGERROR) return # retrieve the media provider mediaProvider = mediaImport.getProvider() if not mediaProvider: log('cannot retrieve media provider', xbmc.LOGERROR) return # prepare the media provider settings if not mediaProvider.prepareSettings(): log('cannot prepare media provider settings', xbmc.LOGERROR) return # prepare and get the media import settings importSettings = mediaImport.prepareSettings() if not importSettings: log('cannot prepare media import settings', xbmc.LOGERROR) return item = xbmcmediaimport.getUpdatedItem(handle) if not item: log('cannot retrieve updated item', xbmc.LOGERROR) return itemVideoInfoTag = item.getVideoInfoTag() if not itemVideoInfoTag: log('updated item is not a video item', xbmc.LOGERROR) return # determine the item's identifier / ratingKey itemId = Api.getItemIdFromListItem(item) if not itemId: log('cannot determine the identifier of the updated item: {}'.format(itemVideoInfoTag.getPath()), xbmc.LOGERROR) return # create a Plex server instance server = Server(mediaProvider) if not server.Authenticate(): log('failed to connect to Plex Media Server for {}'.format(mediaProvider2str(mediaProvider)), xbmc.LOGWARNING) return plexItem = Api.getPlexItemDetails(server.PlexServer(), itemId, Api.getPlexMediaClassFromMediaType(itemVideoInfoTag.getMediaType())) if not plexItem: log('cannot retrieve details of updated item {} with id {}'.format(itemVideoInfoTag.getPath(), itemId), xbmc.LOGERROR) return # check / update watched state playcount = itemVideoInfoTag.getPlayCount() watched = playcount > 0 if watched != plexItem.isWatched: if watched: plexItem.markWatched() else: plexItem.markUnwatched() # TODO(Montellese): check / update last played # TODO(Montellese): check / update resume point xbmcmediaimport.finishUpdateOnProvider(handle)
def updateOnProvider(handle: int, _options: dict): """Perform update/export of library items from Kodi into conifigured PMS (watch status, resume points, etc.) :param handle: Handle id from input :type handle: int :param _options: Options/parameters passed in with the call, Unused :type _options: dict """ # retrieve the media import mediaImport = xbmcmediaimport.getImport(handle) if not mediaImport: log("cannot retrieve media import", xbmc.LOGERROR) return # retrieve the media provider mediaProvider = mediaImport.getProvider() if not mediaProvider: log("cannot retrieve media provider", xbmc.LOGERROR) return # prepare the media provider settings if not mediaProvider.prepareSettings(): log("cannot prepare media provider settings", xbmc.LOGERROR) return # prepare and get the media import settings importSettings = mediaImport.prepareSettings() if not importSettings: log("cannot prepare media import settings", xbmc.LOGERROR) return item = xbmcmediaimport.getUpdatedItem(handle) if not item: log("cannot retrieve updated item", xbmc.LOGERROR) return itemVideoInfoTag = item.getVideoInfoTag() if not itemVideoInfoTag: log("updated item is not a video item", xbmc.LOGERROR) return # determine the item's identifier / ratingKey itemId = Api.getItemIdFromListItem(item) if not itemId: log( f"cannot determine the identifier of the updated item: {itemVideoInfoTag.getPath()}", xbmc.LOGERROR) return # create a Plex server instance server = Server(mediaProvider) if not server.Authenticate(): log( f"failed to connect to Plex Media Server for {mediaProvider2str(mediaProvider)}", xbmc.LOGWARNING) return plexItem = Api.getPlexItemDetails( server.PlexServer(), itemId, Api.getPlexMediaClassFromMediaType(itemVideoInfoTag.getMediaType())) if not plexItem: log( f"cannot retrieve details of updated item {itemVideoInfoTag.getPath()} with id {itemId}", xbmc.LOGERROR) return # check / update watched state playcount = itemVideoInfoTag.getPlayCount() watched = playcount > 0 if watched != plexItem.isWatched: if watched: plexItem.markWatched() else: plexItem.markUnwatched() # TODO(Montellese): check / update last played # TODO(Montellese): check / update resume point xbmcmediaimport.finishUpdateOnProvider(handle)