Ejemplo n.º 1
0
    def _ChangeItems(self, changedItems):
        # map the changed items to their media import
        changedItemsMap = {}
        for (changesetType, item, itemId) in changedItems:
            if not item:
                continue

            # find a matching import for the changed item
            mediaImport = self._FindImportForItem(item)
            if not mediaImport:
                ProviderObserver.log(
                    'failed to determine media import for changed item with id "{}" from {}'
                    .format(itemId, mediaProvider2str(self._mediaProvider)),
                    xbmc.LOGWARNING)
                continue

            if mediaImport not in changedItemsMap:
                changedItemsMap[mediaImport] = []

            changedItemsMap[mediaImport].append((changesetType, item))

        # finally pass the changed items grouped by their media import to Kodi
        for (mediaImport, changedItems) in changedItemsMap.items():
            if xbmcmediaimport.changeImportedItems(mediaImport, changedItems):
                ProviderObserver.log(
                    'changed {} imported items for media import {} from {}'.
                    format(len(changedItems), mediaImport2str(mediaImport),
                           mediaProvider2str(self._mediaProvider)))
            else:
                ProviderObserver.log(
                    'failed to change {} imported items for media import {} from {}'
                    .format(len(changedItems), mediaImport2str(mediaImport),
                            mediaProvider2str(self._mediaProvider)),
                    xbmc.LOGWARNING)
    def _change_items(self, items: Tuple[int, xbmcgui.ListItem, str]):
        # map the changed items to their media import
        changed_items_map = {}
        for (changeset_type, item, item_id) in items:
            if not item:
                continue

            # find a matching import for the changed item
            media_import = self._find_import_for_item(item)
            if not media_import:
                ProviderObserver.log(
                    (f'failed to determine media import for changed item with id "{item_id}" '
                     f"from {provider2str(self._media_provider)}"),
                    xbmc.LOGWARNING,
                )
                continue

            if media_import not in changed_items_map:
                changed_items_map[media_import] = []

            changed_items_map[media_import].append((changeset_type, item))

        # finally pass the changed items grouped by their media import to Kodi
        for (media_import, changedItems) in changed_items_map.items():
            if xbmcmediaimport.changeImportedItems(media_import, changedItems):
                ProviderObserver.log((
                    f"changed {len(changedItems)} imported items for media import {import2str(media_import)} "
                    f"from {provider2str(self._media_provider)}"))
            else:
                ProviderObserver.log(
                    (f"failed to change {len(changedItems)} imported items for media import "
                     f"{import2str(media_import)} from {provider2str(self._media_provider)}"
                     ),
                    xbmc.LOGWARNING,
                )
    def _ChangeItems(self, changedItems: List[tuple]):
        """Send change details to Kodi to perform library updates

        :param changedItems: List of change detail tuples to process
        :type changedItems: list
        """
        # map the changed items to their media import
        changedItemsMap = {}
        for (changesetType, item, plexItemId) in changedItems:
            if not item:
                continue

            # find a matching import for the changed item
            mediaImport = self._FindImportForItem(item)
            if not mediaImport:
                log(
                    f"failed to determine media import for changed item with id {plexItemId}",
                    xbmc.LOGWARNING)
                continue

            if mediaImport not in changedItemsMap:
                changedItemsMap[mediaImport] = []

            changedItemsMap[mediaImport].append((changesetType, item))

        # finally pass the changed items grouped by their media import to Kodi
        for (mediaImport, itemsByImport) in changedItemsMap.items():
            if xbmcmediaimport.changeImportedItems(mediaImport, itemsByImport):
                log(
                    f"changed {len(itemsByImport)} imported items for media import {mediaImport2str(mediaImport)}",
                    xbmc.LOGINFO)
            else:
                log((f"failed to change {len(itemsByImport)} imported items "
                     f"for media import {mediaImport2str(mediaImport)}"),
                    xbmc.LOGWARNING)
Ejemplo n.º 4
0
def synchronize(item, itemId, mediaProvider):
    # find the matching media import
    mediaImport = getMediaImport(mediaProvider, item)
    if not mediaImport:
        log(
            '[context/sync] cannot find the media import of {} from {}'.format(
                listItem2str(item, itemId), mediaProvider2str(mediaProvider)),
            xbmc.LOGERROR)
        return

    # determine whether Direct Play is allowed
    mediaProviderSettings = mediaProvider.getSettings()
    allowDirectPlay = mediaProviderSettings.getBool(
        emby.constants.SETTING_PROVIDER_PLAYBACK_ALLOW_DIRECT_PLAY)

    # create an Emby server instance
    embyServer = Server(mediaProvider)

    # synchronize the active item
    syncedItem = synchronizeItem(item,
                                 itemId,
                                 mediaProvider,
                                 embyServer,
                                 allowDirectPlay=allowDirectPlay)
    if not syncedItem:
        return
    syncedItems = [(xbmcmediaimport.MediaImportChangesetTypeChanged,
                    syncedItem)]

    if xbmcmediaimport.changeImportedItems(mediaImport, syncedItems):
        log('[context/sync] synchronized {} from {}'.format(
            listItem2str(item, itemId), mediaProvider2str(mediaProvider)))
    else:
        log(
            '[context/sync] failed to synchronize {} from {}'.format(
                listItem2str(item, itemId), mediaProvider2str(mediaProvider)),
            xbmc.LOGWARNING)
Ejemplo n.º 5
0
def synchronize(item: ListItem, itemId: int, mediaProvider):
    # find the matching media import
    mediaImport = getMediaImport(mediaProvider, item)
    if not mediaImport:
        contextLog(
            f"cannot find the media import of {listItem2str(item, itemId)} from {mediaProvider2str(mediaProvider)}",
            xbmc.LOGERROR, entry='sync')
        return

    # determine whether Direct Play is allowed
    mediaProviderSettings = mediaProvider.getSettings()
    allowDirectPlay = mediaProviderSettings.getBool(SETTINGS_PROVIDER_PLAYBACK_ALLOW_DIRECT_PLAY)

    # create a Plex server instance
    server = Server(mediaProvider)
    if not server.Authenticate():
        contextLog(
            f"failed to connect to Plex Media Server for {mediaProvider2str(mediaProvider)}",
            xbmc.LOGWARNING, entry='sync')
        return

    plexItemClass = Api.getPlexMediaClassFromListItem(item)

    # synchronize the active item
    syncedItem = synchronizeItem(item, itemId, mediaProvider, server.PlexServer(), plexItemClass=plexItemClass,
                                 allowDirectPlay=allowDirectPlay)
    if not syncedItem:
        return
    syncedItems = [(xbmcmediaimport.MediaImportChangesetTypeChanged, syncedItem)]

    if xbmcmediaimport.changeImportedItems(mediaImport, syncedItems):
        contextLog(f"synchronized {listItem2str(item, itemId)} from {mediaProvider2str(mediaProvider)}", entry='sync')
    else:
        contextLog(
            f"failed to synchronize {listItem2str(item, itemId)} from {mediaProvider2str(mediaProvider)}",
            xbmc.LOGWARNING, entry='sync')