Esempio n. 1
0
 def _connect(self):
     """Used for fetching the attributes for __init__."""
     try:
         return self.query('/')
     except Exception as err:
         log.error('%s: %s', self.baseurl, err)
         raise NotFound('No server found at: %s' % self.baseurl)
Esempio n. 2
0
 def connect(self):
     try:
         data = self.query("/resources")[0]
         self._loadData(data)
     except Exception as err:
         log.error("%s: %s", self.baseurl, err)
         raise NotFound("No client found at: %s" % self.baseurl)
Esempio n. 3
0
 def connect(self):
     try:
         data = self.query('/resources')[0]
         self._loadData(data)
     except Exception as err:
         log.error('%s: %s', self.baseurl, err)
         raise NotFound('No client found at: %s' % self.baseurl)
Esempio n. 4
0
 def _connect(self):
     try:
         return self.query('/')
     except Exception as err:
         log.error('%s:%s: %s', self.address, self.port, err)
         raise NotFound('No server found at: %s:%s' %
                        (self.address, self.port))
Esempio n. 5
0
 def delete(self):
     try:
         return self._server.query(self.key, method=self._server._session.delete)
     except BadRequest:
         log.error("Failed to delete %s. This could be because you havn't allowed "
                   "items to be deleted" % self.key)
         raise
Esempio n. 6
0
 def connect(self):
     try:
         data = self.query('/resources')[0]
         self._loadData(data)
     except Exception as err:
         log.error('%s: %s', self.baseurl, err)
         raise NotFound('No client found at: %s' % self.baseurl)
Esempio n. 7
0
 def _connect(self, url, results, i):
     try:
         results[i] = (url, self.accessToken,
                       PlexServer(url, self.accessToken))
     except Exception as err:
         log.error('%s: %s', url, err)
         results[i] = (url, self.accessToken, None)
Esempio n. 8
0
 def _connect(self, url, results, i):
     try:
         results[i] = (url, self.token,
                       PlexClient(baseurl=url, token=self.token))
     except Exception as err:
         log.error('%s: %s', url, err)
         results[i] = (url, self.token, None)
Esempio n. 9
0
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)
Esempio n. 10
0
 def reload(self):
     """ Reload attribute values from Plex XML response.  """
     try:
         data = self.query('/')
         self._loadData(data)
     except Exception as err:
         log.error('%s: %s', self.baseurl, err)
         raise NotFound('No server found at: %s' % self.baseurl)
Esempio n. 11
0
 def delete(self):
     part = self._initpath + '/media/%s' % self.id
     try:
         return self._server.query(part, method=self._server._session.delete)
     except BadRequest:
         log.error("Failed to delete %s. This could be because you havn't allowed "
                   "items to be deleted" % part)
         raise
Esempio n. 12
0
 def delete(self):
     part = self._initpath + '/media/%s' % self.id
     try:
         return self._server.query(part, method=self._server._session.delete)
     except BadRequest:
         log.error("Failed to delete %s. This could be because you havn't allowed "
                   "items to be deleted" % part)
         raise
Esempio n. 13
0
 def delete(self):
     """ Delete a media element. This has to be enabled under settings > server > library in plex webui. """
     try:
         return self._server.query(self.key, method=self._server._session.delete)
     except BadRequest:  # pragma: no cover
         log.error('Failed to delete %s. This could be because you '
             'havnt allowed items to be deleted' % self.key)
         raise
Esempio n. 14
0
 def delete(self):
     """ Delete a media element. This has to be enabled under settings > server > library in plex webui. """
     try:
         return self._server.query(self.key, method=self._server._session.delete)
     except BadRequest:  # pragma: no cover
         log.error('Failed to delete %s. This could be because you '
             'havnt allowed items to be deleted' % self.key)
         raise
Esempio n. 15
0
 def delete(self):
     """ Delete a library section. """
     try:
         return self._server.query('/library/sections/%s' % self.key, method=self._server._session.delete)
     except BadRequest:  # pragma: no cover
         msg = 'Failed to delete library %s' % self.key
         msg += 'You may need to allow this permission in your Plex settings.'
         log.error(msg)
         raise
Esempio n. 16
0
 def delete(self):
     """ Delete a library section. """
     try:
         return self._server.query('/library/sections/%s' % self.key, method=self._server._session.delete)
     except BadRequest:  # pragma: no cover
         msg = 'Failed to delete library %s' % self.key
         msg += 'You may need to allow this permission in your Plex settings.'
         log.error(msg)
         raise
Esempio n. 17
0
 def _onMessage(self, ws, message):
     """ Called when websocket message is recieved. """
     try:
         data = json.loads(message)['NotificationContainer']
         log.debug('Alert: %s %s %s', *data)
         if self._callback:
             self._callback(data)
     except Exception as err:  # pragma: no cover
         log.error('AlertListener Msg Error: %s', err)
Esempio n. 18
0
 def _onMessage(self, ws, message):
     """ Called when websocket message is recieved. """
     try:
         data = json.loads(message)['NotificationContainer']
         log.debug('Alert: %s %s %s', *data)
         if self._callback:
             self._callback(data)
     except Exception as err:  # pragma: no cover
         log.error('AlertListener Msg Error: %s', err)
Esempio n. 19
0
 def _onError(self, *args):  # pragma: no cover
     """ Called when websocket error is received.
         In earlier releases, websocket-client returned a tuple of two parameters: a websocket.app.WebSocketApp
         object and the error. Current releases appear to only return the error.
         We are assuming the last argument in the tuple is the message.
         This is to support compatibility with current and previous releases of websocket-client.
     """
     err = args[-1]
     log.error('AlertListener Error: %s' % err)
Esempio n. 20
0
 def connect(self):
     """ Connects to the client and reloads all class attributes.
         
         Raises:
             :class:`~plexapi.exceptions.NotFound`: No client found at the specified url.
     """
     try:
         data = self.query('/resources')[0]
         self._loadData(data)
     except Exception as err:
         log.error('%s: %s', self.baseurl, err)
         raise NotFound('No client found at: %s' % self.baseurl)
Esempio n. 21
0
def _connect(cls, url, token, timeout, results, i):
    """ Connects to the specified cls with url and token. Stores the connection
        information to results[i] in a threadsafe way.
    """
    starttime = time.time()
    try:
        device = cls(baseurl=url, token=token, timeout=timeout)
        runtime = int(time.time() - starttime)
        results[i] = (url, token, device, runtime)
    except Exception as err:
        runtime = int(time.time() - starttime)
        log.error('%s: %s', url, err)
        results[i] = (url, token, None, runtime)
Esempio n. 22
0
def _connect(cls, url, token, timeout, results, i):
    """ Connects to the specified cls with url and token. Stores the connection
        information to results[i] in a threadsafe way.
    """
    starttime = time.time()
    try:
        device = cls(baseurl=url, token=token, timeout=timeout)
        runtime = int(time.time() - starttime)
        results[i] = (url, token, device, runtime)
    except Exception as err:
        runtime = int(time.time() - starttime)
        log.error('%s: %s', url, err)
        results[i] = (url, token, None, runtime)
Esempio n. 23
0
 def _onMessage(self, *args):
     """ Called when websocket message is received.
         In earlier releases, websocket-client returned a tuple of two parameters: a websocket.app.WebSocketApp
         object and the message as a STR. Current releases appear to only return the message.
         We are assuming the last argument in the tuple is the message.
         This is to support compatibility with current and previous releases of websocket-client.
     """
     message = args[-1]
     try:
         data = json.loads(message)['NotificationContainer']
         log.debug('Alert: %s %s %s', *data)
         if self._callback:
             self._callback(data)
     except Exception as err:  # pragma: no cover
         log.error('AlertListener Msg Error: %s', err)
Esempio n. 24
0
 def _connect(self):
     try:
         return self.query('/')
     except Exception as err:
         log.error('%s: %s', self.baseuri, err)
         raise NotFound('No server found at: %s' % self.baseuri)
Esempio n. 25
0
 def _connect(self):
     try:
         return self.query('/')
     except Exception as err:
         log.error('%s:%s: %s', self.address, self.port, err)
         raise NotFound('No server found at: %s:%s' % (self.address, self.port))
Esempio n. 26
0
 def _onError(self, ws, err):  # pragma: no cover
     """ Called when websocket error is recieved. """
     log.error('AlertListener Error: %s' % err)
Esempio n. 27
0
 def _connect(self):
     try:
         return self.query('/resources')[0]
     except Exception as err:
         log.error('%s: %s', self.baseurl, err)
         raise NotFound('No client found at: %s' % self.baseurl)
Esempio n. 28
0
 def _onError(self, ws, err):  # pragma: no cover
     """ Called when websocket error is recieved. """
     log.error('AlertListener Error: %s' % err)
Esempio n. 29
0
 def _connect(self):
     try:
         return self.query('/')
     except Exception as err:
         log.error('%s: %s', self.baseurl, err)
         raise NotFound('No server found at: %s' % self.baseurl)