예제 #1
0
def dicsoverProviderLocally(handle, options):
    dialog = xbmcgui.Dialog()

    baseUrl = dialog.input(localise(32051))
    if not baseUrl:
        return None

    plexServer = PlexServer(baseUrl, timeout=plex.constants.REQUEST_TIMEOUT)
    if not plexServer:
        return None

    providerId = Server.BuildProviderId(plexServer.machineIdentifier)
    providerIconUrl = Server.BuildIconUrl(baseUrl)

    provider = xbmcmediaimport.MediaProvider(providerId,baseUrl, plexServer.friendlyName, providerIconUrl, plex.constants.SUPPORTED_MEDIA_TYPES, handle=handle)

    # store local authentication in settings
    providerSettings = provider.prepareSettings()
    if not providerSettings:
        return None

    providerSettings.setInt(plex.constants.SETTINGS_PROVIDER_AUTHENTICATION, plex.constants.SETTINGS_PROVIDER_AUTHENTICATION_OPTION_LOCAL)
    providerSettings.save()

    return provider
예제 #2
0
    def _addServer(self, server: PlexServer):
        """Add a discovered PMS server as a MediaProvider to the Kodi mediaimport system

        :param server: The discovered PlexServer to add into the Kodi mediaimport system
        :type server: :class:`PlexServer`
        """
        registerServer = False

        # check if the server is already known
        if server.id not in self._servers:
            self._servers[server.id] = server
            registerServer = True
        else:
            # check if the server has already been registered or if some of its properties have changed
            if (
                    not self._servers[server.id].registered
                    or self._servers[server.id].name != server.name
                    or self._servers[server.id].address != server.address
            ):
                self._servers[server.id] = server
                registerServer = True
            else:
                # simply update the server's last seen property
                self._servers[server.id].lastseen = server.lastseen

        # if the server doesn't need to be registered there's nothing else to do
        if not registerServer:
            return

        providerId = Server.BuildProviderId(server.id)
        providerIconUrl = Server.BuildIconUrl(server.address)

        provider = xbmcmediaimport.MediaProvider(
            providerId,
            server.address,
            server.name,
            providerIconUrl,
            plex.constants.SUPPORTED_MEDIA_TYPES
        )

        # store local authentication in settings
        providerSettings = provider.prepareSettings()
        if not providerSettings:
            return

        providerSettings.setInt(
            plex.constants.SETTINGS_PROVIDER_AUTHENTICATION,
            plex.constants.SETTINGS_PROVIDER_AUTHENTICATION_OPTION_LOCAL
        )
        providerSettings.save()

        if xbmcmediaimport.addAndActivateProvider(provider):
            self._servers[server.id].registered = True
            log(f"Plex Media Server {mediaProvider2str(provider)} successfully added and activated", xbmc.LOGINFO)
        else:
            self._servers[server.id].registered = False
            log(f"failed to add and/or activate Plex Media Server {mediaProvider2str(provider)}", xbmc.LOGINFO)
예제 #3
0
    def _addServer(self, server):
        registerServer = False

        # check if the server is already known
        if not server.id in self._servers:
            self._servers[server.id] = server
            registerServer = True
        else:
            # check if the server has already been registered or if some of its properties have changed
            if not self._servers[server.id].registered or self._servers[
                    server.id].name != server.name or self._servers[
                        server.id].address != server.address:
                self._servers[server.id] = server
                registerServer = True
            else:
                # simply update the server's last seen property
                self._servers[server.id].lastseen = server.lastseen

        # if the server doesn't need to be registered there's nothing else to do
        if not registerServer:
            return

        providerId = Server.BuildProviderId(server.id)
        providerIconUrl = Server.BuildIconUrl(server.address)

        provider = xbmcmediaimport.MediaProvider(
            providerId, server.address, server.name, providerIconUrl,
            plex.constants.SUPPORTED_MEDIA_TYPES)

        # store local authentication in settings
        providerSettings = provider.prepareSettings()
        if not providerSettings:
            return None

        providerSettings.setInt(
            plex.constants.SETTINGS_PROVIDER_AUTHENTICATION,
            plex.constants.SETTINGS_PROVIDER_AUTHENTICATION_OPTION_LOCAL)
        providerSettings.save()

        if xbmcmediaimport.addAndActivateProvider(provider):
            self._servers[server.id].registered = True
            log('Plex Media Server {} successfully added and activated'.format(
                mediaProvider2str(provider)))
        else:
            self._servers[server.id].registered = False
            log('failed to add and/or activate Plex Media Server {}'.format(
                mediaProvider2str(provider)))
예제 #4
0
def discoverProviderLocally(handle: int,
                            _options: dict) -> xbmcmediaimport.MediaProvider:
    """Set up a Plex server provider from user-provided URL

    :param handle: Handle id from input
    :type handle: int
    :param _options: Options/parameters passed in with the call, unused
    :type _options: dict
    :return: Fully setup and populated mediaProvider object for the PMS
    :rtype: xbmcmediaimport.MediaProvider
    """
    dialog = xbmcgui.Dialog()

    baseUrl = dialog.input(localize(32051))
    if not baseUrl:
        return None

    plexServer = PlexServer(baseUrl, timeout=plex.constants.REQUEST_TIMEOUT)
    if not plexServer:
        return None

    providerId = Server.BuildProviderId(plexServer.machineIdentifier)
    providerIconUrl = Server.BuildIconUrl(baseUrl)

    provider = xbmcmediaimport.MediaProvider(
        identifier=providerId,
        basePath=baseUrl,
        friendlyName=plexServer.friendlyName,
        iconUrl=providerIconUrl,
        mediaTypes=plex.constants.SUPPORTED_MEDIA_TYPES,
        handle=handle)

    # store local authentication in settings
    providerSettings = provider.prepareSettings()
    if not providerSettings:
        return None

    providerSettings.setInt(
        plex.constants.SETTINGS_PROVIDER_AUTHENTICATION,
        plex.constants.SETTINGS_PROVIDER_AUTHENTICATION_OPTION_LOCAL)
    providerSettings.save()

    return provider