mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
Rename _root back to _server but keep it private
This commit is contained in:
parent
76c0cb55a1
commit
83a8c5733e
8 changed files with 48 additions and 48 deletions
|
@ -52,15 +52,15 @@ class Audio(PlexPartialObject):
|
|||
def thumbUrl(self):
|
||||
""" Returns the URL to this items thumbnail image. """
|
||||
if self.thumb:
|
||||
return self._root._url(self.thumb)
|
||||
return self._server._url(self.thumb)
|
||||
|
||||
def refresh(self):
|
||||
""" Tells Plex to refresh the metadata for this and all subitems. """
|
||||
self._root._query('%s/refresh' % self.key, method=self._root.session.put)
|
||||
self._server._query('%s/refresh' % self.key, method=self._server.session.put)
|
||||
|
||||
def section(self):
|
||||
""" Returns the :class:`~plexapi.library.LibrarySection` this item belongs to. """
|
||||
return self._root.library.sectionByID(self.librarySectionID)
|
||||
return self._server.library.sectionByID(self.librarySectionID)
|
||||
|
||||
|
||||
@utils.register_libtype
|
||||
|
@ -291,8 +291,8 @@ class Track(Audio, Playable):
|
|||
# data for active sessions and history
|
||||
self.sessionKey = utils.cast(int, data.attrib.get('sessionKey'))
|
||||
self.username = utils.findUsername(data)
|
||||
self.player = utils.findPlayer(self._root, data)
|
||||
self.transcodeSession = utils.findTranscodeSession(self._root, data)
|
||||
self.player = utils.findPlayer(self._server, data)
|
||||
self.transcodeSession = utils.findTranscodeSession(self._server, data)
|
||||
|
||||
def _prettyfilename(self):
|
||||
""" Returns a filename for use in download. """
|
||||
|
@ -302,7 +302,7 @@ class Track(Audio, Playable):
|
|||
def thumbUrl(self):
|
||||
""" Returns the URL thumbnail image for this track's album. """
|
||||
if self.parentThumb:
|
||||
return self._root._url(self.parentThumb)
|
||||
return self._server._url(self.parentThumb)
|
||||
|
||||
def album(self):
|
||||
""" Return this track's :class:`~plexapi.audio.Album`. """
|
||||
|
|
|
@ -12,7 +12,7 @@ class PlexObject(object):
|
|||
key = None
|
||||
|
||||
def __init__(self, root, data, initpath=None):
|
||||
self._root = root # Root MyPlexAccount or PlexServer
|
||||
self._server = root # Root MyPlexAccount or PlexServer
|
||||
self._data = data # XML data needed to build object
|
||||
self._initpath = initpath or self.key # Request path used to fetch data
|
||||
self._loadData(data)
|
||||
|
@ -44,10 +44,10 @@ class PlexObject(object):
|
|||
if libtype == 'photo' and elem.tag == 'Directory':
|
||||
libtype = 'photoalbum'
|
||||
if cls and libtype == cls.TYPE:
|
||||
return cls(self._root, elem, initpath)
|
||||
return cls(self._server, elem, initpath)
|
||||
if libtype in utils.LIBRARY_TYPES:
|
||||
cls = utils.LIBRARY_TYPES[libtype]
|
||||
return cls(self._root, elem, initpath)
|
||||
return cls(self._server, elem, initpath)
|
||||
raise UnknownType("Unknown library type <%s type='%s'../>" % (elem.tag, libtype))
|
||||
|
||||
def _buildItemOrNone(self, elem, cls=None, initpath=None, bytag=False):
|
||||
|
@ -78,7 +78,7 @@ class PlexObject(object):
|
|||
specified tag and attrs. If no tag or attrs are specified then
|
||||
the first item in the result set is returned.
|
||||
"""
|
||||
for elem in self._root._query(key):
|
||||
for elem in self._server._query(key):
|
||||
if tag and elem.tag != tag or not self._checkAttrs(elem, **kwargs):
|
||||
continue
|
||||
return self._buildItem(elem, cls, key, bytag)
|
||||
|
@ -89,7 +89,7 @@ class PlexObject(object):
|
|||
specified tag and attrs.
|
||||
"""
|
||||
items = []
|
||||
for elem in self._root._query(key):
|
||||
for elem in self._server._query(key):
|
||||
if tag and elem.tag != tag or not self._checkAttrs(elem, **kwargs):
|
||||
continue
|
||||
items.append(self._buildItemOrNone(elem, cls, key, bytag))
|
||||
|
@ -110,7 +110,7 @@ class PlexObject(object):
|
|||
if safe: return None
|
||||
raise Unsupported('Cannot reload an object not built from a URL.')
|
||||
self._initpath = self.key
|
||||
data = self._root._query(self.key)
|
||||
data = self._server._query(self.key)
|
||||
self._loadData(data[0])
|
||||
return self
|
||||
|
||||
|
@ -176,8 +176,8 @@ class Playable(object):
|
|||
# Load data for active sessions (/status/sessions)
|
||||
self.sessionKey = utils.cast(int, data.attrib.get('sessionKey'))
|
||||
self.username = utils.findUsername(data)
|
||||
self.player = utils.findPlayer(self._root, data)
|
||||
self.transcodeSession = utils.findTranscodeSession(self._root, data)
|
||||
self.player = utils.findPlayer(self._server, data)
|
||||
self.transcodeSession = utils.findTranscodeSession(self._server, data)
|
||||
# Load data for history details (/status/sessions/history/all)
|
||||
self.viewedAt = utils.toDatetime(data.attrib.get('viewedAt'))
|
||||
# Load data for playlist items
|
||||
|
@ -213,7 +213,7 @@ class Playable(object):
|
|||
streamtype = 'audio' if self.TYPE in ('track', 'album') else 'video'
|
||||
# sort the keys since the randomness fucks with my tests..
|
||||
sorted_params = sorted(params.items(), key=lambda val: val[0])
|
||||
return self._root._url('/%s/:/transcode/universal/start.m3u8?%s' %
|
||||
return self._server._url('/%s/:/transcode/universal/start.m3u8?%s' %
|
||||
(streamtype, urlencode(sorted_params)))
|
||||
|
||||
def iterParts(self):
|
||||
|
@ -254,9 +254,9 @@ class Playable(object):
|
|||
if kwargs:
|
||||
download_url = self.getStreamURL(**kwargs)
|
||||
else:
|
||||
download_url = self._root._url('%s?download=1' % location.key)
|
||||
download_url = self._server._url('%s?download=1' % location.key)
|
||||
filepath = utils.download(download_url, filename=filename,
|
||||
savepath=savepath, session=self._root._session)
|
||||
savepath=savepath, session=self._server._session)
|
||||
if filepath:
|
||||
filepaths.append(filepath)
|
||||
return filepaths
|
||||
|
|
|
@ -159,7 +159,7 @@ class PlexClient(PlexObject):
|
|||
params['commandID'] = self._commandId
|
||||
proxy = self._proxyThroughServer if proxy is None else proxy
|
||||
if proxy:
|
||||
return self._root._query(key, headers=headers)
|
||||
return self._server._query(key, headers=headers)
|
||||
return self._query(key, headers=headers)
|
||||
|
||||
#---------------------
|
||||
|
|
|
@ -39,11 +39,11 @@ class Library(PlexObject):
|
|||
MusicSection.TYPE: MusicSection, PhotoSection.TYPE: PhotoSection}
|
||||
items = []
|
||||
key = '/library/sections'
|
||||
for elem in self._root._query(key):
|
||||
for elem in self._server._query(key):
|
||||
stype = elem.attrib['type']
|
||||
if stype in SECTION_TYPES:
|
||||
cls = SECTION_TYPES[stype]
|
||||
section = cls(self._root, elem, key)
|
||||
section = cls(self._server, elem, key)
|
||||
self._sectionsByID[section.key] = section
|
||||
items.append(section)
|
||||
return items
|
||||
|
@ -112,7 +112,7 @@ class Library(PlexObject):
|
|||
server will automatically clean up old bundles once a week as part of Scheduled Tasks.
|
||||
"""
|
||||
# TODO: Should this check the response for success or the correct mediaprefix?
|
||||
self._root._query('/library/clean/bundles')
|
||||
self._server._query('/library/clean/bundles')
|
||||
|
||||
def emptyTrash(self):
|
||||
""" If a library has items in the Library Trash, use this option to empty the Trash. """
|
||||
|
@ -124,13 +124,13 @@ class Library(PlexObject):
|
|||
For example, if you have deleted or added an entire library or many items in a
|
||||
library, you may like to optimize the database.
|
||||
"""
|
||||
self._root._query('/library/optimize')
|
||||
self._server._query('/library/optimize')
|
||||
|
||||
def refresh(self):
|
||||
""" Refresh the metadata for the entire library. This will fetch fresh metadata for
|
||||
all contents in the library, including items that already have metadata.
|
||||
"""
|
||||
self._root._query('/library/sections/all/refresh')
|
||||
self._server._query('/library/sections/all/refresh')
|
||||
|
||||
|
||||
class LibrarySection(PlexObject):
|
||||
|
@ -218,19 +218,19 @@ class LibrarySection(PlexObject):
|
|||
def analyze(self):
|
||||
""" Run an analysis on all of the items in this library section. """
|
||||
key = '/library/sections/%s/analyze' % self.key
|
||||
self._root._query(key, method=self._root._session.put)
|
||||
self._server._query(key, method=self._server._session.put)
|
||||
|
||||
def emptyTrash(self):
|
||||
""" If a section has items in the Trash, use this option to empty the Trash. """
|
||||
key = '/library/sections/%s/emptyTrash' % self.key
|
||||
self._root._query(key)
|
||||
self._server._query(key)
|
||||
|
||||
def refresh(self):
|
||||
""" Refresh the metadata for this library section. This will fetch fresh metadata for
|
||||
all contents in the section, including items that already have metadata.
|
||||
"""
|
||||
key = '/library/sections/%s/refresh' % self.key
|
||||
self._root._query(key)
|
||||
self._server._query(key)
|
||||
|
||||
def listChoices(self, category, libtype=None, **kwargs):
|
||||
""" Returns a list of :class:`~plexapi.library.FilterChoice` objects for the
|
||||
|
@ -498,5 +498,5 @@ class Hub(PlexObject):
|
|||
def _buildItems(self, data):
|
||||
if self.type in self.FILTERTYPES:
|
||||
cls = self.FILTERTYPES[self.type]
|
||||
return [cls(self._root, elem, self._initpath) for elem in data]
|
||||
return [cls(self._server, elem, self._initpath) for elem in data]
|
||||
return super(Hub, self)._buildItems(data)
|
||||
|
|
|
@ -87,7 +87,7 @@ class MediaPart(PlexObject):
|
|||
for elem in data:
|
||||
for cls in (VideoStream, AudioStream, SubtitleStream):
|
||||
if elem.attrib.get('streamType') == str(cls.STREAMTYPE):
|
||||
streams.append(cls(self._root, elem, self._initpath))
|
||||
streams.append(cls(self._server, elem, self._initpath))
|
||||
return streams
|
||||
|
||||
@property
|
||||
|
|
|
@ -62,7 +62,7 @@ class Photoalbum(PlexPartialObject):
|
|||
|
||||
def section(self):
|
||||
""" Returns the :class:`~plexapi.library.LibrarySection` this item belongs to. """
|
||||
return self._root.library.sectionByID(self.librarySectionID)
|
||||
return self._server.library.sectionByID(self.librarySectionID)
|
||||
|
||||
|
||||
@utils.register_libtype
|
||||
|
@ -118,4 +118,4 @@ class Photo(PlexPartialObject):
|
|||
|
||||
def section(self):
|
||||
""" Returns the :class:`~plexapi.library.LibrarySection` this item belongs to. """
|
||||
return self._root.library.sectionByID(self.photoalbum().librarySectionID)
|
||||
return self._server.library.sectionByID(self.photoalbum().librarySectionID)
|
||||
|
|
|
@ -47,32 +47,32 @@ class Playlist(PlexPartialObject, Playable):
|
|||
key = '%s/items%s' % (self.key, utils.joinArgs({
|
||||
'uri': 'library://%s/directory//library/metadata/%s' % (uuid, ratingKeys)
|
||||
}))
|
||||
return self._root._query(key, method=self._root._session.put)
|
||||
return self._server._query(key, method=self._server._session.put)
|
||||
|
||||
def removeItem(self, item):
|
||||
"""Remove a file from a playlist."""
|
||||
key = '%s/items/%s' % (self.key, item.playlistItemID)
|
||||
return self._root._query(key, method=self._root._session.delete)
|
||||
return self._server._query(key, method=self._server._session.delete)
|
||||
|
||||
def moveItem(self, item, after=None):
|
||||
"""Move a to a new position in playlist."""
|
||||
key = '%s/items/%s/move' % (self.key, item.playlistItemID)
|
||||
if after:
|
||||
key += '?after=%s' % after.playlistItemID
|
||||
return self._root._query(key, method=self._root._session.put)
|
||||
return self._server._query(key, method=self._server._session.put)
|
||||
|
||||
def edit(self, title=None, summary=None):
|
||||
"""Edit playlist."""
|
||||
key = '/library/metadata/%s%s' % (self.ratingKey, utils.joinArgs({'title':title, 'summary':summary}))
|
||||
return self._root._query(key, method=self._root._session.put)
|
||||
return self._server._query(key, method=self._server._session.put)
|
||||
|
||||
def delete(self):
|
||||
"""Delete playlist."""
|
||||
return self._root._query(self.key, method=self._root._session.delete)
|
||||
return self._server._query(self.key, method=self._server._session.delete)
|
||||
|
||||
def playQueue(self, *args, **kwargs):
|
||||
""" Create a playqueue from this playlist. """
|
||||
return PlayQueue.create(self._root, self, *args, **kwargs)
|
||||
return PlayQueue.create(self._server, self, *args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def create(cls, server, title, items):
|
||||
|
|
|
@ -28,7 +28,7 @@ class Video(PlexPartialObject):
|
|||
def thumbUrl(self):
|
||||
"""Return url to thumb image."""
|
||||
if self.thumb:
|
||||
return self._root._url(self.thumb)
|
||||
return self._server._url(self.thumb)
|
||||
|
||||
def analyze(self):
|
||||
"""The primary purpose of media analysis is to gather information about
|
||||
|
@ -37,28 +37,28 @@ class Video(PlexPartialObject):
|
|||
a music track, or one of your photos.
|
||||
"""
|
||||
key = '/%s/analyze' % self.key.lstrip('/')
|
||||
self._root._query(key, method=self._root._session.put)
|
||||
self._server._query(key, method=self._server._session.put)
|
||||
|
||||
def markWatched(self):
|
||||
"""Mark a items as watched."""
|
||||
key = '/:/scrobble?key=%s&identifier=com.plexapp.plugins.library' % self.ratingKey
|
||||
self._root._query(key)
|
||||
self._server._query(key)
|
||||
self.reload()
|
||||
|
||||
def markUnwatched(self):
|
||||
"""Mark a item as unwatched."""
|
||||
key = '/:/unscrobble?key=%s&identifier=com.plexapp.plugins.library' % self.ratingKey
|
||||
self._root._query(key)
|
||||
self._server._query(key)
|
||||
self.reload()
|
||||
|
||||
def refresh(self):
|
||||
"""Refresh a item."""
|
||||
key = '%s/refresh' % self.key
|
||||
self._root._query(key, method=self._root._session.put)
|
||||
self._server._query(key, method=self._server._session.put)
|
||||
|
||||
def section(self):
|
||||
"""Library section."""
|
||||
return self._root.library.sectionByID(self.librarySectionID)
|
||||
return self._server.library.sectionByID(self.librarySectionID)
|
||||
|
||||
|
||||
@utils.register_libtype
|
||||
|
@ -133,8 +133,8 @@ class Movie(Video, Playable):
|
|||
if kwargs:
|
||||
download_url = self.getStreamURL(**kwargs)
|
||||
else:
|
||||
download_url = self._root._url('%s?download=1' % loc.key)
|
||||
dl = utils.download(download_url, filename=name, savepath=savepath, session=self._root._session)
|
||||
download_url = self._server._url('%s?download=1' % loc.key)
|
||||
dl = utils.download(download_url, filename=name, savepath=savepath, session=self._server._session)
|
||||
if dl:
|
||||
downloaded.append(dl)
|
||||
return downloaded
|
||||
|
@ -254,7 +254,7 @@ class Show(Video):
|
|||
|
||||
def refresh(self):
|
||||
"""Refresh the metadata."""
|
||||
self._root._query('/library/metadata/%s/refresh' % self.ratingKey, method=self._root._session.put)
|
||||
self._server._query('/library/metadata/%s/refresh' % self.ratingKey, method=self._server._session.put)
|
||||
|
||||
def download(self, savepath=None, keep_orginal_name=False, **kwargs):
|
||||
downloaded = []
|
||||
|
@ -395,8 +395,8 @@ class Episode(Video, Playable):
|
|||
# data for active sessions and history
|
||||
self.sessionKey = utils.cast(int, data.attrib.get('sessionKey'))
|
||||
self.username = utils.findUsername(data)
|
||||
self.player = utils.findPlayer(self._root, data)
|
||||
self.transcodeSession = utils.findTranscodeSession(self._root, data)
|
||||
self.player = utils.findPlayer(self._server, data)
|
||||
self.transcodeSession = utils.findTranscodeSession(self._server, data)
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s>' % ':'.join([p for p in [
|
||||
|
@ -421,7 +421,7 @@ class Episode(Video, Playable):
|
|||
def thumbUrl(self):
|
||||
"""Return url to thumb image."""
|
||||
if self.grandparentThumb:
|
||||
return self._root._url(self.grandparentThumb)
|
||||
return self._server._url(self.grandparentThumb)
|
||||
|
||||
def season(self):
|
||||
"""Return this episode Season"""
|
||||
|
|
Loading…
Reference in a new issue