def onProviderUpdated(self, media_provider: xbmcmediaimport.MediaProvider):
        self._add_observer(media_provider)

        # make sure the media provider is being observed
        if media_provider.isActive():
            self._start_observer(media_provider)
        else:
            self._stop_observer(media_provider)
    def _stop_observer(self, media_provider: xbmcmediaimport.MediaProvider):
        if not media_provider:
            raise ValueError("cannot stop invalid media provider")

        media_provider_id = media_provider.getIdentifier()
        if media_provider_id not in self._observers:
            return

        self._observers[media_provider_id].stop()
    def _start_observer(self, media_provider: xbmcmediaimport.MediaProvider):
        if not media_provider:
            raise ValueError("cannot start invalid media provider")

        # make sure the media provider has been added
        self._add_observer(media_provider)

        # start observing the media provider
        self._observers[media_provider.getIdentifier()].start(media_provider)
    def __init__(self, provider: xbmcmediaimport.MediaProvider):
        if not provider:
            raise ValueError('Invalid provider')

        self._id = provider.getIdentifier()
        self._url = provider.getBasePath()

        settings = provider.getSettings()
        if not settings:
            raise ValueError('Invalid provider without settings')

        self._localOnly = bool(
            settings.getInt(SETTINGS_PROVIDER_AUTHENTICATION) ==
            SETTINGS_PROVIDER_AUTHENTICATION_OPTION_LOCAL)
        self._token = ""
        if not self._localOnly:
            self._token = settings.getString(SETTINGS_PROVIDER_TOKEN)
        self._plex = None
    def __init__(self, provider: xbmcmediaimport.MediaProvider):
        if not provider:
            raise ValueError('Invalid provider')

        self._id = provider.getIdentifier()

        settings = provider.getSettings()
        if not settings:
            raise ValueError('Invalid provider without settings')

        self._url = ProviderSettings.GetUrl(settings)

        self._localOnly = bool(
            ProviderSettings.GetAuthenticationMethod(settings) ==
            SETTINGS_PROVIDER_AUTHENTICATION_OPTION_LOCAL)
        self._token = ""
        if not self._localOnly:
            self._token = ProviderSettings.GetAccessToken(settings)
        self._plex = None
Exemple #6
0
def getMediaImport(mediaProvider: xbmcmediaimport.MediaProvider, item: ListItem) -> xbmcmediaimport.MediaImport:
    videoInfoTag = item.getVideoInfoTag()
    if not videoInfoTag:
        return None

    mediaType = videoInfoTag.getMediaType()
    if not mediaType:
        return None

    mediaImports = mediaProvider.getImports()
    return next((mediaImport for mediaImport in mediaImports if mediaType in mediaImport.getMediaTypes()), None)
    def _remove_observer(self, media_provider: xbmcmediaimport.MediaProvider):
        if not media_provider:
            raise ValueError("cannot remove invalid media provider")

        self._player.RemoveProvider(media_provider)

        media_provider_id = media_provider.getIdentifier()
        if media_provider_id not in self._observers:
            return

        del self._observers[media_provider_id]
    def RemoveProvider(self, mediaProvider: xbmcmediaimport.MediaProvider):
        """Removes a media provider from the player

        :param mediaProvider: Media provider to remove from the player
        :type mediaProvider: :class:`xbmcmediaimport.MediaProvider`
        """
        if not mediaProvider:
            raise ValueError('invalid mediaProvider')

        with self._lock:
            del self._providers[mediaProvider.getIdentifier()]
    def AddProvider(self, mediaProvider: xbmcmediaimport.MediaProvider):
        """Adds a media provider to the player

        :param mediaProvider: Media provider to add to the player
        :type mediaProvider: :class:`xbmcmediaimport.MediaProvider`
        """
        if not mediaProvider:
            raise ValueError('invalid mediaProvider')

        with self._lock:
            self._providers[mediaProvider.getIdentifier()] = mediaProvider
    def onProviderUpdated(self, mediaProvider: xbmcmediaimport.MediaProvider):
        """Event handler: triggered when a provider is updated in the system, make sure it is being observed

        :param mediaProvider: MediaProvider that was added to the system
        :type mediaProvider: :class:`xbmcmediaimport.MediaProvider`
        """
        self._addObserver(mediaProvider)

        # make sure the media provider is being observed
        if mediaProvider.isActive():
            self._startObserver(mediaProvider)
        else:
            self._stopObserver(mediaProvider)
    def _add_observer(self, media_provider: xbmcmediaimport.MediaProvider):
        if not media_provider:
            raise ValueError("cannot add invalid media provider")

        self._player.AddProvider(media_provider)

        # check if we already know about the media provider
        media_provider_id = media_provider.getIdentifier()
        if media_provider_id in self._observers:
            return

        # create the observer
        self._observers[media_provider_id] = ProviderObserver()
    def _stopObserver(self, mediaProvider: xbmcmediaimport.MediaProvider):
        """Stp[ observation on the provided MediaProvider (Plex server)

        :param mediaProvider: Plex Server MediaProvider object to stop observation of
        :type mediaProvider: :class:`xbmcmediaimport.MediaProvider`
        """
        if not mediaProvider:
            raise ValueError('cannot stop invalid media provider')

        mediaProviderId = mediaProvider.getIdentifier()
        if mediaProviderId not in self._observers:
            return

        self._observers[mediaProviderId].Stop()
    def _startObserver(self, mediaProvider: xbmcmediaimport.MediaProvider):
        """Start observation on the provided MediaProvider (Plex server)

        :param mediaProvider: Plex Server MediaProvider object to observe
        :type mediaProvider: :class:`xbmcmediaimport.MediaProvider`
        """
        if not mediaProvider:
            raise ValueError('cannot start invalid media provider')

        # make sure the media provider has been added
        self._addObserver(mediaProvider)

        # start observing the media provider
        self._observers[mediaProvider.getIdentifier()].Start(mediaProvider)
    def _removeObserver(self, mediaProvider: xbmcmediaimport.MediaProvider):
        """Remove a registered observer (Plex sever) from the observation process

        :param mediaProvider: Plex Server MediaProvider object to remove from observation
        :type mediaProvider: :class:`xbmcmediaimport.MediaProvider`
        """
        if not mediaProvider:
            raise ValueError('cannot remove invalid media provider')

        self._player.RemoveProvider(mediaProvider)

        mediaProviderId = mediaProvider.getIdentifier()
        if mediaProviderId not in self._observers:
            return

        del self._observers[mediaProviderId]
    def _addObserver(self, mediaProvider: xbmcmediaimport.MediaProvider):
        """Register a new observer (Plex server) in the observation process

        :param mediaProvider: Plex Server MediaProvider object to observe
        :type mediaProvider: :class:`xbmcmediaimport.MediaProvider`
        """
        if not mediaProvider:
            raise ValueError('cannot add invalid media provider')

        self._player.AddProvider(mediaProvider)

        # check if we already know about the media provider
        mediaProviderId = mediaProvider.getIdentifier()
        if mediaProviderId in self._observers:
            return

        # create the observer
        self._observers[mediaProviderId] = ProviderObserver()