当前位置: 首页>>代码示例>>Python>>正文


Python server.PlexServer方法代码示例

本文整理汇总了Python中plexapi.server.PlexServer方法的典型用法代码示例。如果您正苦于以下问题:Python server.PlexServer方法的具体用法?Python server.PlexServer怎么用?Python server.PlexServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plexapi.server的用法示例。


在下文中一共展示了server.PlexServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: notify_plex

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def notify_plex(self):
        """If plex notifications enabled, tell it to refresh"""

        if self.configfile.plex_server is not None and not pytranscoder.dry_run:
            plex_server = self.configfile.plex_server
            try:
                from plexapi.server import PlexServer

                plex = PlexServer('http://{}'.format(plex_server))
                plex.library.update()
            except ModuleNotFoundError:
                print(
                    'Library not installed. To use Plex notifications please install the Python 3 Plex API ' +
                    '("pip3 install plexapi")')
            except Exception as ex2:
                print(f'Unable to connect to Plex server at {plex_server}')
                if pytranscoder.verbose:
                    print(str(ex2)) 
开发者ID:mlsmithjr,项目名称:transcoder,代码行数:20,代码来源:transcode.py

示例2: _getSectionIds

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def _getSectionIds(self, server, sections):
        """ Converts a list of section objects or names to sectionIds needed for library sharing. """
        if not sections: return []
        # Get a list of all section ids for looking up each section.
        allSectionIds = {}
        machineIdentifier = server.machineIdentifier if isinstance(server, PlexServer) else server
        url = self.PLEXSERVERS.replace('{machineId}', machineIdentifier)
        data = self.query(url, self._session.get)
        for elem in data[0]:
            allSectionIds[elem.attrib.get('id', '').lower()] = elem.attrib.get('id')
            allSectionIds[elem.attrib.get('title', '').lower()] = elem.attrib.get('id')
            allSectionIds[elem.attrib.get('key', '').lower()] = elem.attrib.get('id')
        log.debug(allSectionIds)
        # Convert passed in section items to section ids from above lookup
        sectionIds = []
        for section in sections:
            sectionKey = section.key if isinstance(section, LibrarySection) else section
            sectionIds.append(allSectionIds[sectionKey.lower()])
        return sectionIds 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:21,代码来源:myplex.py

示例3: create

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def create(cls, server, title, items=None, section=None, limit=None, smart=False, **kwargs):
        """Create a playlist.

        Parameters:
            server (:class:`~plexapi.server.PlexServer`): Server your connected to.
            title (str): Title of the playlist.
            items (Iterable): Iterable of objects that should be in the playlist.
            section (:class:`~plexapi.library.LibrarySection`, str):
            limit (int): default None.
            smart (bool): default False.

            **kwargs (dict): is passed to the filters. For a example see the search method.

        Returns:
            :class:`plexapi.playlist.Playlist`: an instance of created Playlist.
        """
        if smart:
            return cls._createSmart(server, title, section, limit, **kwargs)

        else:
            return cls._create(server, title, items) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:23,代码来源:playlist.py

示例4: test_server_check_for_update

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def test_server_check_for_update(plex, mocker):
    class R:
        def __init__(self, **kwargs):
            self.download_key = "plex.tv/release/1337"
            self.version = "1337"
            self.added = "gpu transcode"
            self.fixed = "fixed rare bug"
            self.downloadURL = "http://path-to-update"
            self.state = "downloaded"

    with utils.patch('plexapi.server.PlexServer.check_for_update', return_value=R()):
        rel = plex.check_for_update(force=False, download=True)
        assert rel.download_key == "plex.tv/release/1337"
        assert rel.version == "1337"
        assert rel.added == "gpu transcode"
        assert rel.fixed == "fixed rare bug"
        assert rel.downloadURL == "http://path-to-update"
        assert rel.state == "downloaded" 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:20,代码来源:test_server.py

示例5: fetch_plex_instance

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def fetch_plex_instance(pkmeter, username=None, password=None, host=None):
    username = username or pkmeter.config.get('plexserver', 'username', from_keyring=True)
    password = password or pkmeter.config.get('plexserver', 'password', from_keyring=True)
    host = host or pkmeter.config.get('plexserver', 'host', '')
    if username:
        log.info('Logging into MyPlex with user %s', username)
        user = MyPlexAccount.signin(username, password)
        return user.resource(host).connect()
    log.info('Connecting to Plex host: %s', host)
    return PlexServer(host) 
开发者ID:pkkid,项目名称:pkmeter,代码行数:12,代码来源:plexserver.py

示例6: __init__

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def __init__(self, 
                 server, 
                 token, 
                 clients, 
                 controllerServerPath = '', 
                 controllerServerPort = '8000', 
                 debugMode = False,
                 htmlPseudoTitle = "Daily PseudoChannel"
                 ):

        self.PLEX = PlexServer(server, token)
        self.BASE_URL = server
        self.TOKEN = token
        self.PLEX_CLIENTS = clients
        self.CONTROLLER_SERVER_PATH = controllerServerPath
        self.CONTROLLER_SERVER_PORT = controllerServerPort if controllerServerPort != '' else '80'
        self.DEBUG = debugMode
        self.webserverStarted = False
        self.HTML_PSEUDO_TITLE = htmlPseudoTitle
        try: 
            self.my_logger = logging.getLogger('MyLogger')
            self.my_logger.setLevel(logging.DEBUG)
            self.handler = logging.handlers.SysLogHandler(address = '/dev/log')
            self.my_logger.addHandler(self.handler)
        except:
            pass 
开发者ID:justinemter,项目名称:pseudo-channel,代码行数:28,代码来源:PseudoDailyScheduleController.py

示例7: __init__

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def __init__(self):
        if PLEX_URL and PLEX_TOKEN:
            self.server = PlexServer(PLEX_URL, PLEX_TOKEN)
        else:
            self.account = self.get_account()
            self.server = self.get_account_server(self.account)

        self.section = self.get_server_section(self.server)
        self.media = self.get_flat_media(self.section) 
开发者ID:alex-phillips,项目名称:plex-autocollections,代码行数:11,代码来源:main.py

示例8: inviteFriend

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def inviteFriend(self, user, server, sections=None, allowSync=False, allowCameraUpload=False,
                     allowChannels=False, filterMovies=None, filterTelevision=None, filterMusic=None):
        """ Share library content with the specified user.

            Parameters:
                user (str): MyPlexUser, username, email of the user to be added.
                server (PlexServer): PlexServer object or machineIdentifier containing the library sections to share.
                sections ([Section]): Library sections, names or ids to be shared (default None).
                    [Section] must be defined in order to update shared sections.
                allowSync (Bool): Set True to allow user to sync content.
                allowCameraUpload (Bool): Set True to allow user to upload photos.
                allowChannels (Bool): Set True to allow user to utilize installed channels.
                filterMovies (Dict): Dict containing key 'contentRating' and/or 'label' each set to a list of
                    values to be filtered. ex: {'contentRating':['G'], 'label':['foo']}
                filterTelevision (Dict): Dict containing key 'contentRating' and/or 'label' each set to a list of
                    values to be filtered. ex: {'contentRating':['G'], 'label':['foo']}
                filterMusic (Dict): Dict containing key 'label' set to a list of values to be filtered.
                    ex: {'label':['foo']}
        """
        username = user.username if isinstance(user, MyPlexUser) else user
        machineId = server.machineIdentifier if isinstance(server, PlexServer) else server
        sectionIds = self._getSectionIds(machineId, sections)
        params = {
            'server_id': machineId,
            'shared_server': {'library_section_ids': sectionIds, 'invited_email': username},
            'sharing_settings': {
                'allowSync': ('1' if allowSync else '0'),
                'allowCameraUpload': ('1' if allowCameraUpload else '0'),
                'allowChannels': ('1' if allowChannels else '0'),
                'filterMovies': self._filterDictToStr(filterMovies or {}),
                'filterTelevision': self._filterDictToStr(filterTelevision or {}),
                'filterMusic': self._filterDictToStr(filterMusic or {}),
            },
        }
        headers = {'Content-Type': 'application/json'}
        url = self.FRIENDINVITE.format(machineId=machineId)
        return self.query(url, self._session.post, json=params, headers=headers) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:39,代码来源:myplex.py

示例9: connect

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def connect(self, ssl=None, timeout=None):
        """ Returns a new :class:`~server.PlexServer` or :class:`~client.PlexClient` object.
            Often times there is more than one address specified for a server or client.
            This function will prioritize local connections before remote and HTTPS before HTTP.
            After trying to connect to all available addresses for this resource and
            assuming at least one connection was successful, the PlexServer object is built and returned.

            Parameters:
                ssl (optional): Set True to only connect to HTTPS connections. Set False to
                    only connect to HTTP connections. Set None (default) to connect to any
                    HTTP or HTTPS connection.

            Raises:
                :class:`plexapi.exceptions.NotFound`: When unable to connect to any addresses for this resource.
        """
        # Sort connections from (https, local) to (http, remote)
        # Only check non-local connections unless we own the resource
        connections = sorted(self.connections, key=lambda c: c.local, reverse=True)
        owned_or_unowned_non_local = lambda x: self.owned or (not self.owned and not x.local)
        https = [c.uri for c in connections if owned_or_unowned_non_local(c)]
        http = [c.httpuri for c in connections if owned_or_unowned_non_local(c)]
        cls = PlexServer if 'server' in self.provides else PlexClient
        # Force ssl, no ssl, or any (default)
        if ssl is True: connections = https
        elif ssl is False: connections = http
        else: connections = https + http
        # Try connecting to all known resource connections in parellel, but
        # only return the first server (in order) that provides a response.
        listargs = [[cls, url, self.accessToken, timeout] for url in connections]
        log.info('Testing %s resource connections..', len(listargs))
        results = utils.threaded(_connect, listargs)
        return _chooseConnection('Resource', self.name, results) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:34,代码来源:myplex.py

示例10: _connect

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def _connect(cls, url, token, timeout, results, i, job_is_done_event=None):
    """ Connects to the specified cls with url and token. Stores the connection
        information to results[i] in a threadsafe way.

        Arguments:
            cls: the class which is responsible for establishing connection, basically it's
                 :class:`~plexapi.client.PlexClient` or :class:`~plexapi.server.PlexServer`
            url (str): url which should be passed as `baseurl` argument to cls.__init__()
            token (str): authentication token which should be passed as `baseurl` argument to cls.__init__()
            timeout (int): timeout which should be passed as `baseurl` argument to cls.__init__()
            results (list): pre-filled list for results
            i (int): index of current job, should be less than len(results)
            job_is_done_event (:class:`~threading.Event`): is X_PLEX_ENABLE_FAST_CONNECT is True then the
                  event would be set as soon the connection is established
    """
    starttime = time.time()
    try:
        device = cls(baseurl=url, token=token, timeout=timeout)
        runtime = int(time.time() - starttime)
        results[i] = (url, token, device, runtime)
        if X_PLEX_ENABLE_FAST_CONNECT and job_is_done_event:
            job_is_done_event.set()
    except Exception as err:
        runtime = int(time.time() - starttime)
        log.error('%s: %s', url, err)
        results[i] = (url, token, None, runtime) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:28,代码来源:myplex.py

示例11: _chooseConnection

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def _chooseConnection(ctype, name, results):
    """ Chooses the first (best) connection from the given _connect results. """
    # At this point we have a list of result tuples containing (url, token, PlexServer, runtime)
    # or (url, token, None, runtime) in the case a connection could not be established.
    for url, token, result, runtime in results:
        okerr = 'OK' if result else 'ERR'
        log.info('%s connection %s (%ss): %s?X-Plex-Token=%s', ctype, okerr, runtime, url, token)
    results = [r[2] for r in results if r and r[2] is not None]
    if results:
        log.info('Connecting to %s: %s?X-Plex-Token=%s', ctype, results[0]._baseurl, results[0]._token)
        return results[0]
    raise NotFound('Unable to connect to %s: %s' % (ctype.lower(), name)) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:14,代码来源:myplex.py

示例12: copyToUser

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def copyToUser(self, user):
        """ Copy playlist to another user account. """
        from plexapi.server import PlexServer
        myplex = self._server.myPlexAccount()
        user = myplex.user(user)
        # Get the token for your machine.
        token = user.get_token(self._server.machineIdentifier)
        # Login to your server using your friends credentials.
        user_server = PlexServer(self._server._baseurl, token)
        return self.create(user_server, self.title, self.items()) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:12,代码来源:playlist.py

示例13: test_server_Server_session

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def test_server_Server_session(account):
    # Mock Sesstion
    class MySession(Session):
        def __init__(self):
            super(self.__class__, self).__init__()
            self.plexapi_session_test = True

    # Test Code
    plex = PlexServer(
        utils.SERVER_BASEURL, account.authenticationToken, session=MySession()
    )
    assert hasattr(plex._session, "plexapi_session_test") 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:14,代码来源:test_server.py

示例14: test_server_allowMediaDeletion

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def test_server_allowMediaDeletion(account):
    plex = PlexServer(utils.SERVER_BASEURL, account.authenticationToken)
    # Check server current allowMediaDeletion setting
    if plex.allowMediaDeletion:
        # If allowed then test disallowed
        plex._allowMediaDeletion(False)
        time.sleep(1)
        plex = PlexServer(utils.SERVER_BASEURL, account.authenticationToken)
        assert plex.allowMediaDeletion is None
        # Test redundant toggle
        with pytest.raises(BadRequest):
            plex._allowMediaDeletion(False)

        plex._allowMediaDeletion(True)
        time.sleep(1)
        plex = PlexServer(utils.SERVER_BASEURL, account.authenticationToken)
        assert plex.allowMediaDeletion is True
        # Test redundant toggle
        with pytest.raises(BadRequest):
            plex._allowMediaDeletion(True)
    else:
        # If disallowed then test allowed
        plex._allowMediaDeletion(True)
        time.sleep(1)
        plex = PlexServer(utils.SERVER_BASEURL, account.authenticationToken)
        assert plex.allowMediaDeletion is True
        # Test redundant toggle
        with pytest.raises(BadRequest):
            plex._allowMediaDeletion(True)

        plex._allowMediaDeletion(False)
        time.sleep(1)
        plex = PlexServer(utils.SERVER_BASEURL, account.authenticationToken)
        assert plex.allowMediaDeletion is None
        # Test redundant toggle
        with pytest.raises(BadRequest):
            plex._allowMediaDeletion(False) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:39,代码来源:test_server.py

示例15: plex

# 需要导入模块: from plexapi import server [as 别名]
# 或者: from plexapi.server import PlexServer [as 别名]
def plex(request):
    assert SERVER_BASEURL, "Required SERVER_BASEURL not specified."
    session = requests.Session()
    if request.param == TEST_AUTHENTICATED:
        token = get_account().authenticationToken
    else:
        token = None
    return PlexServer(SERVER_BASEURL, token, session=session) 
开发者ID:pkkid,项目名称:python-plexapi,代码行数:10,代码来源:conftest.py


注:本文中的plexapi.server.PlexServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。