mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-13 23:47:06 +00:00
Refactor getWebURL
This commit is contained in:
parent
8a0b03c841
commit
49ce2f9bb4
6 changed files with 45 additions and 80 deletions
|
@ -416,11 +416,6 @@ class Track(Audio, Playable, ArtUrlMixin, PosterUrlMixin, RatingMixin,
|
||||||
""" Returns str, default title for a new syncItem. """
|
""" Returns str, default title for a new syncItem. """
|
||||||
return '%s - %s - %s' % (self.grandparentTitle, self.parentTitle, self.title)
|
return '%s - %s - %s' % (self.grandparentTitle, self.parentTitle, self.title)
|
||||||
|
|
||||||
def getWebURL(self, base=None):
|
def _getWebURL(self, base=None):
|
||||||
""" Returns the Plex Web URL for the track's album.
|
""" Get the Plex Web URL with the correct parameters. """
|
||||||
|
return self._server._buildWebURL(base=base, endpoint='details', key=self.parentKey)
|
||||||
Parameters:
|
|
||||||
base (str): The base URL before the fragment (``#!``).
|
|
||||||
Default is https://app.plex.tv/desktop.
|
|
||||||
"""
|
|
||||||
return self._buildWebURL(base=base, key=self.parentKey)
|
|
||||||
|
|
|
@ -582,37 +582,20 @@ class PlexPartialObject(PlexObject):
|
||||||
"""
|
"""
|
||||||
return self._server.history(maxresults=maxresults, mindate=mindate, ratingKey=self.ratingKey)
|
return self._server.history(maxresults=maxresults, mindate=mindate, ratingKey=self.ratingKey)
|
||||||
|
|
||||||
def _buildWebURL(self, base=None, endpoint='details', key='', legacy=False):
|
def _getWebURL(self, base=None):
|
||||||
""" Build the Plex Web URL for the item.
|
""" Get the Plex Web URL with the correct parameters.
|
||||||
|
Private method to allow overriding parameters from subclasses.
|
||||||
Parameters:
|
|
||||||
base (str): The base URL before the fragment (``#!``).
|
|
||||||
Default is https://app.plex.tv/desktop.
|
|
||||||
endpoint (str): The Plex Web URL endpoint.
|
|
||||||
'playlist' for playlists, 'details' for all other media types.
|
|
||||||
key (str): The Plex API URL for the item (/library/metadata/<ratingKey>).
|
|
||||||
legacy (bool): True or False to use the legacy URL.
|
|
||||||
Photoalbum and Photo use the legacy URL.
|
|
||||||
"""
|
"""
|
||||||
if base is None:
|
return self._server._buildWebURL(base=base, endpoint='details', key=self.key)
|
||||||
base = 'https://app.plex.tv/desktop/'
|
|
||||||
|
|
||||||
params = {'key': key or self.key}
|
|
||||||
if legacy:
|
|
||||||
params['legacy'] = 1
|
|
||||||
|
|
||||||
return '%s#!/server/%s/%s%s' % (
|
|
||||||
base, self._server.machineIdentifier, endpoint, utils.joinArgs(params)
|
|
||||||
)
|
|
||||||
|
|
||||||
def getWebURL(self, base=None):
|
def getWebURL(self, base=None):
|
||||||
""" Returns the Plex Web URL for the item.
|
""" Returns the Plex Web URL for a media item.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
base (str): The base URL before the fragment (``#!``).
|
base (str): The base URL before the fragment (``#!``).
|
||||||
Default is https://app.plex.tv/desktop.
|
Default is https://app.plex.tv/desktop.
|
||||||
"""
|
"""
|
||||||
return self._buildWebURL(base=base)
|
return self._getWebURL(base=base)
|
||||||
|
|
||||||
|
|
||||||
class Playable(object):
|
class Playable(object):
|
||||||
|
|
|
@ -1465,19 +1465,13 @@ class LibrarySection(PlexObject):
|
||||||
tab (str): The library tab (recommended, library, collections, playlists, timeline).
|
tab (str): The library tab (recommended, library, collections, playlists, timeline).
|
||||||
key (str): A hub key.
|
key (str): A hub key.
|
||||||
"""
|
"""
|
||||||
if base is None:
|
|
||||||
base = 'https://app.plex.tv/desktop/'
|
|
||||||
|
|
||||||
params = {'source': self.key}
|
params = {'source': self.key}
|
||||||
if tab is not None:
|
if tab is not None:
|
||||||
params['pivot'] = tab
|
params['pivot'] = tab
|
||||||
if key is not None:
|
if key is not None:
|
||||||
params['key'] = key
|
params['key'] = key
|
||||||
params['pageType'] = 'list'
|
params['pageType'] = 'list'
|
||||||
|
return self._server._buildWebURL(base=base, **params)
|
||||||
return '%s#!/media/%s/com.plexapp.plugins.library%s' % (
|
|
||||||
base, self._server.machineIdentifier, utils.joinArgs(params)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class MovieSection(LibrarySection):
|
class MovieSection(LibrarySection):
|
||||||
|
@ -1899,15 +1893,6 @@ class Hub(PlexObject):
|
||||||
self._section = self._server.library.sectionByID(self.librarySectionID)
|
self._section = self._server.library.sectionByID(self.librarySectionID)
|
||||||
return self._section
|
return self._section
|
||||||
|
|
||||||
def getWebURL(self, base=None):
|
|
||||||
""" Returns the Plex Web URL for the library.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
base (str): The base URL before the fragment (``#!``).
|
|
||||||
Default is https://app.plex.tv/desktop.
|
|
||||||
"""
|
|
||||||
return self.section().getWebURL(base=base, key=self.key)
|
|
||||||
|
|
||||||
|
|
||||||
class HubMediaTag(PlexObject):
|
class HubMediaTag(PlexObject):
|
||||||
""" Base class of hub media tag search results.
|
""" Base class of hub media tag search results.
|
||||||
|
|
|
@ -137,14 +137,9 @@ class Photoalbum(PlexPartialObject, ArtMixin, PosterMixin, RatingMixin):
|
||||||
filepaths.append(filepath)
|
filepaths.append(filepath)
|
||||||
return filepaths
|
return filepaths
|
||||||
|
|
||||||
def getWebURL(self, base=None):
|
def _getWebURL(self, base=None):
|
||||||
""" Returns the Plex Web URL for the photoalbum.
|
""" Get the Plex Web URL with the correct parameters. """
|
||||||
|
return self._server._buildWebURL(base=base, endpoint='details', key=self.key, legacy=1)
|
||||||
Parameters:
|
|
||||||
base (str): The base URL before the fragment (``#!``).
|
|
||||||
Default is https://app.plex.tv/desktop.
|
|
||||||
"""
|
|
||||||
return self._buildWebURL(base=base, legacy=True)
|
|
||||||
|
|
||||||
|
|
||||||
@utils.registerPlexObject
|
@utils.registerPlexObject
|
||||||
|
@ -311,11 +306,6 @@ class Photo(PlexPartialObject, Playable, ArtUrlMixin, PosterUrlMixin, RatingMixi
|
||||||
filepaths.append(filepath)
|
filepaths.append(filepath)
|
||||||
return filepaths
|
return filepaths
|
||||||
|
|
||||||
def getWebURL(self, base=None):
|
def _getWebURL(self, base=None):
|
||||||
""" Returns the Plex Web URL for the photo's photoalbum.
|
""" Get the Plex Web URL with the correct parameters. """
|
||||||
|
return self._server._buildWebURL(base=base, endpoint='details', key=self.parentKey, legacy=1)
|
||||||
Parameters:
|
|
||||||
base (str): The base URL before the fragment (``#!``).
|
|
||||||
Default is https://app.plex.tv/desktop.
|
|
||||||
"""
|
|
||||||
return self._buildWebURL(base=base, key=self.parentKey, legacy=True)
|
|
||||||
|
|
|
@ -460,11 +460,6 @@ class Playlist(PlexPartialObject, Playable, ArtMixin, PosterMixin, SmartFilterMi
|
||||||
|
|
||||||
return myplex.sync(sync_item, client=client, clientId=clientId)
|
return myplex.sync(sync_item, client=client, clientId=clientId)
|
||||||
|
|
||||||
def getWebURL(self, base=None):
|
def _getWebURL(self, base=None):
|
||||||
""" Returns the Plex Web URL for the playlist.
|
""" Get the Plex Web URL with the correct parameters. """
|
||||||
|
return self._server._buildWebURL(base=base, endpoint='playlist', key=self.key)
|
||||||
Parameters:
|
|
||||||
base (str): The base URL before the fragment (``#!``).
|
|
||||||
Default is https://app.plex.tv/desktop.
|
|
||||||
"""
|
|
||||||
return self._buildWebURL(base=base, endpoint='playlist')
|
|
||||||
|
|
|
@ -890,24 +890,41 @@ class PlexServer(PlexObject):
|
||||||
key = '/statistics/resources?timespan=6'
|
key = '/statistics/resources?timespan=6'
|
||||||
return self.fetchItems(key, StatisticsResources)
|
return self.fetchItems(key, StatisticsResources)
|
||||||
|
|
||||||
def getPlaylistsWebURL(self, base=None, tab=None):
|
def _buildWebURL(self, base=None, endpoint=None, **kwargs):
|
||||||
""" Returns the Plex Web URL for the server playlists page.
|
""" Build the Plex Web URL for the object.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
base (str): The base URL before the fragment (``#!``).
|
base (str): The base URL before the fragment (``#!``).
|
||||||
Default is https://app.plex.tv/desktop.
|
Default is https://app.plex.tv/desktop.
|
||||||
tab (str): The playlist tab (audio, video, photo).
|
endpoint (str): The Plex Web URL endpoint.
|
||||||
|
None for server, 'playlist' for playlists, 'details' for all other media types.
|
||||||
|
**kwargs (dict): Dictionary of URL parameters.
|
||||||
"""
|
"""
|
||||||
if base is None:
|
if base is None:
|
||||||
base = 'https://app.plex.tv/desktop/'
|
base = 'https://app.plex.tv/desktop/'
|
||||||
|
|
||||||
params = {'source': 'playlists'}
|
if endpoint:
|
||||||
if tab is not None:
|
return '%s#!/server/%s/%s%s' % (
|
||||||
params['pivot'] = 'playlists.%s' % tab
|
base, self.machineIdentifier, endpoint, utils.joinArgs(kwargs)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return '%s#!/media/%s/com.plexapp.plugins.library%s' % (
|
||||||
|
base, self.machineIdentifier, utils.joinArgs(kwargs)
|
||||||
|
)
|
||||||
|
|
||||||
return '%s#!/media/%s/com.plexapp.plugins.library%s' % (
|
def getWebURL(self, base=None, playlistTab=None):
|
||||||
base, self._server.machineIdentifier, utils.joinArgs(params)
|
""" Returns the Plex Web URL for the server.
|
||||||
)
|
|
||||||
|
Parameters:
|
||||||
|
base (str): The base URL before the fragment (``#!``).
|
||||||
|
Default is https://app.plex.tv/desktop.
|
||||||
|
playlistTab (str): The playlist tab (audio, video, photo). Only used for the playlist URL.
|
||||||
|
"""
|
||||||
|
if playlistTab is not None:
|
||||||
|
params = {'source': 'playlists', 'pivot': 'playlists.%s' % playlistTab}
|
||||||
|
else:
|
||||||
|
params = {'key': '/hubs', 'pageType': 'hub'}
|
||||||
|
return self._buildWebURL(base=base, **params)
|
||||||
|
|
||||||
|
|
||||||
class Account(PlexObject):
|
class Account(PlexObject):
|
||||||
|
|
Loading…
Reference in a new issue