mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-22 11:43:13 +00:00
fix tests for download logs/dbs
fix clients. Clients now tries to get info from plex.tv resources in the port is missing. add quote_plus to compat
This commit is contained in:
parent
baeedcebbf
commit
53fab6239a
4 changed files with 38 additions and 13 deletions
|
@ -17,6 +17,11 @@ try:
|
|||
except ImportError:
|
||||
from urllib import quote
|
||||
|
||||
try:
|
||||
from urllib.parse import quote_plus
|
||||
except ImportError:
|
||||
from urllib import quote_plus
|
||||
|
||||
try:
|
||||
from urllib.parse import unquote
|
||||
except ImportError:
|
||||
|
@ -31,4 +36,3 @@ try:
|
|||
from xml.etree import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
from xml.etree import ElementTree
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from plexapi import utils
|
||||
from plexapi.base import PlexObject
|
||||
from plexapi.compat import quote_plus
|
||||
from plexapi.exceptions import BadRequest
|
||||
from plexapi.utils import cast
|
||||
|
||||
|
@ -283,6 +284,10 @@ class TranscodeSession(PlexObject):
|
|||
self.videoDecision = data.attrib.get('videoDecision')
|
||||
self.width = cast(int, data.attrib.get('width'))
|
||||
|
||||
def stop(self, reason=''):
|
||||
key = '/status/sessions/terminate?sessionId=%s&reason=%s' % (self.key, quote_plus(reason))
|
||||
return self._server.query(key)
|
||||
|
||||
|
||||
class MediaTag(PlexObject):
|
||||
""" Base class for media tags used for filtering and searching your library
|
||||
|
|
|
@ -174,12 +174,28 @@ class PlexServer(PlexObject):
|
|||
|
||||
def clients(self):
|
||||
""" Returns a list of all :class:`~plexapi.client.PlexClient` objects
|
||||
connected to this server.
|
||||
"""
|
||||
connected to this server."""
|
||||
|
||||
items = []
|
||||
cache_resource = None
|
||||
from plexapi.myplex import MyPlexResource
|
||||
for elem in self.query('/clients'):
|
||||
baseurl = 'http://%s:%s' % (elem.attrib['host'], elem.attrib['port'])
|
||||
items.append(PlexClient(baseurl, server=self, data=elem))
|
||||
# Some shitty clients dont include a port..
|
||||
port = elem.attrib.get('port')
|
||||
if port is None:
|
||||
log.debug("%s didn't provide a port. Checking https://plex.tv/devices.xml" % elem.attrib.get('name'))
|
||||
data = cache_resource or self._server._session.get('https://plex.tv/devices.xml?X-Plex-Token=%s' % self.token)
|
||||
cache_resource = data
|
||||
resources = MyPlexResource(self, data)
|
||||
for resource in resources:
|
||||
if resource.clientIdentifier == elem.attrib.get('machineIdentifier'):
|
||||
for conn in resource.connection:
|
||||
if conn.local is True:
|
||||
port = conn.port
|
||||
break
|
||||
|
||||
baseurl = 'http://%s:%s' % (elem.attrib['host'], port)
|
||||
items.append(PlexClient(baseurl=baseurl, server=self, data=elem))
|
||||
return items
|
||||
|
||||
def client(self, name):
|
||||
|
@ -326,14 +342,14 @@ class PlexServer(PlexObject):
|
|||
return '%s%s%sX-Plex-Token=%s' % (self._baseurl, key, delim, self._token)
|
||||
return '%s%s' % (self._baseurl, key)
|
||||
|
||||
def downloadLog(self, savepath=None, unpack=False):
|
||||
def downloadLogs(self, savepath=None, unpack=False):
|
||||
url = self.url('/diagnostics/databases')
|
||||
fp = utils.download(url, filename=None, savepath=savepath, unpack=unpack)
|
||||
fp = utils.download(url, filename=None, savepath=savepath, unpack=unpack, session=self._session)
|
||||
return fp
|
||||
|
||||
def downloadDB(self, savepath=None, unpack=False):
|
||||
def downloadDBS(self, savepath=None, unpack=False):
|
||||
url = self.url('/diagnostics/logs')
|
||||
fp = utils.download(url, filename=None, savepath=savepath, unpack=unpack)
|
||||
fp = utils.download(url, filename=None, savepath=savepath, unpack=unpack, session=self._session)
|
||||
return fp
|
||||
|
||||
|
||||
|
|
|
@ -209,10 +209,10 @@ def test_server_account(pms):
|
|||
|
||||
|
||||
def test_server_downloadLogs(tmpdir, pms):
|
||||
pms.downloadLogs(savepath=tmpdir, unpack=True)
|
||||
assert len(os.listdir(tmpdir)) > 1
|
||||
pms.downloadLogs(savepath=str(tmpdir), unpack=True)
|
||||
assert len(tmpdir.listdir()) > 1
|
||||
|
||||
|
||||
def test_server_downloadDB(tmpdir, pms):
|
||||
pms.downloadDB(savepath=tmpdir, unpack=True)
|
||||
assert len(os.listdir(tmpdir)) > 1
|
||||
pms.downloadDBS(savepath=str(tmpdir), unpack=True)
|
||||
assert len(tmpdir.listdir()) > 1
|
||||
|
|
Loading…
Reference in a new issue