mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +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. """
|
||||
return '%s - %s - %s' % (self.grandparentTitle, self.parentTitle, self.title)
|
||||
|
||||
def getWebURL(self, base=None):
|
||||
""" Returns the Plex Web URL for the track's album.
|
||||
|
||||
Parameters:
|
||||
base (str): The base URL before the fragment (``#!``).
|
||||
Default is https://app.plex.tv/desktop.
|
||||
"""
|
||||
return self._buildWebURL(base=base, key=self.parentKey)
|
||||
def _getWebURL(self, base=None):
|
||||
""" Get the Plex Web URL with the correct parameters. """
|
||||
return self._server._buildWebURL(base=base, endpoint='details', key=self.parentKey)
|
||||
|
|
|
@ -582,37 +582,20 @@ class PlexPartialObject(PlexObject):
|
|||
"""
|
||||
return self._server.history(maxresults=maxresults, mindate=mindate, ratingKey=self.ratingKey)
|
||||
|
||||
def _buildWebURL(self, base=None, endpoint='details', key='', legacy=False):
|
||||
""" Build the Plex Web URL for the item.
|
||||
|
||||
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.
|
||||
def _getWebURL(self, base=None):
|
||||
""" Get the Plex Web URL with the correct parameters.
|
||||
Private method to allow overriding parameters from subclasses.
|
||||
"""
|
||||
if base is None:
|
||||
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)
|
||||
)
|
||||
return self._server._buildWebURL(base=base, endpoint='details', key=self.key)
|
||||
|
||||
def getWebURL(self, base=None):
|
||||
""" Returns the Plex Web URL for the item.
|
||||
""" Returns the Plex Web URL for a media item.
|
||||
|
||||
Parameters:
|
||||
base (str): The base URL before the fragment (``#!``).
|
||||
Default is https://app.plex.tv/desktop.
|
||||
"""
|
||||
return self._buildWebURL(base=base)
|
||||
return self._getWebURL(base=base)
|
||||
|
||||
|
||||
class Playable(object):
|
||||
|
|
|
@ -1465,19 +1465,13 @@ class LibrarySection(PlexObject):
|
|||
tab (str): The library tab (recommended, library, collections, playlists, timeline).
|
||||
key (str): A hub key.
|
||||
"""
|
||||
if base is None:
|
||||
base = 'https://app.plex.tv/desktop/'
|
||||
|
||||
params = {'source': self.key}
|
||||
if tab is not None:
|
||||
params['pivot'] = tab
|
||||
if key is not None:
|
||||
params['key'] = key
|
||||
params['pageType'] = 'list'
|
||||
|
||||
return '%s#!/media/%s/com.plexapp.plugins.library%s' % (
|
||||
base, self._server.machineIdentifier, utils.joinArgs(params)
|
||||
)
|
||||
return self._server._buildWebURL(base=base, **params)
|
||||
|
||||
|
||||
class MovieSection(LibrarySection):
|
||||
|
@ -1899,15 +1893,6 @@ class Hub(PlexObject):
|
|||
self._section = self._server.library.sectionByID(self.librarySectionID)
|
||||
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):
|
||||
""" Base class of hub media tag search results.
|
||||
|
|
|
@ -137,14 +137,9 @@ class Photoalbum(PlexPartialObject, ArtMixin, PosterMixin, RatingMixin):
|
|||
filepaths.append(filepath)
|
||||
return filepaths
|
||||
|
||||
def getWebURL(self, base=None):
|
||||
""" Returns the Plex Web URL for the photoalbum.
|
||||
|
||||
Parameters:
|
||||
base (str): The base URL before the fragment (``#!``).
|
||||
Default is https://app.plex.tv/desktop.
|
||||
"""
|
||||
return self._buildWebURL(base=base, legacy=True)
|
||||
def _getWebURL(self, base=None):
|
||||
""" Get the Plex Web URL with the correct parameters. """
|
||||
return self._server._buildWebURL(base=base, endpoint='details', key=self.key, legacy=1)
|
||||
|
||||
|
||||
@utils.registerPlexObject
|
||||
|
@ -311,11 +306,6 @@ class Photo(PlexPartialObject, Playable, ArtUrlMixin, PosterUrlMixin, RatingMixi
|
|||
filepaths.append(filepath)
|
||||
return filepaths
|
||||
|
||||
def getWebURL(self, base=None):
|
||||
""" Returns the Plex Web URL for the photo's photoalbum.
|
||||
|
||||
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)
|
||||
def _getWebURL(self, base=None):
|
||||
""" Get the Plex Web URL with the correct parameters. """
|
||||
return self._server._buildWebURL(base=base, endpoint='details', key=self.parentKey, legacy=1)
|
||||
|
|
|
@ -460,11 +460,6 @@ class Playlist(PlexPartialObject, Playable, ArtMixin, PosterMixin, SmartFilterMi
|
|||
|
||||
return myplex.sync(sync_item, client=client, clientId=clientId)
|
||||
|
||||
def getWebURL(self, base=None):
|
||||
""" Returns the Plex Web URL for the playlist.
|
||||
|
||||
Parameters:
|
||||
base (str): The base URL before the fragment (``#!``).
|
||||
Default is https://app.plex.tv/desktop.
|
||||
"""
|
||||
return self._buildWebURL(base=base, endpoint='playlist')
|
||||
def _getWebURL(self, base=None):
|
||||
""" Get the Plex Web URL with the correct parameters. """
|
||||
return self._server._buildWebURL(base=base, endpoint='playlist', key=self.key)
|
||||
|
|
|
@ -890,24 +890,41 @@ class PlexServer(PlexObject):
|
|||
key = '/statistics/resources?timespan=6'
|
||||
return self.fetchItems(key, StatisticsResources)
|
||||
|
||||
def getPlaylistsWebURL(self, base=None, tab=None):
|
||||
""" Returns the Plex Web URL for the server playlists page.
|
||||
def _buildWebURL(self, base=None, endpoint=None, **kwargs):
|
||||
""" Build the Plex Web URL for the object.
|
||||
|
||||
Parameters:
|
||||
base (str): The base URL before the fragment (``#!``).
|
||||
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:
|
||||
base = 'https://app.plex.tv/desktop/'
|
||||
|
||||
params = {'source': 'playlists'}
|
||||
if tab is not None:
|
||||
params['pivot'] = 'playlists.%s' % tab
|
||||
if endpoint:
|
||||
return '%s#!/server/%s/%s%s' % (
|
||||
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' % (
|
||||
base, self._server.machineIdentifier, utils.joinArgs(params)
|
||||
)
|
||||
def getWebURL(self, base=None, playlistTab=None):
|
||||
""" 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):
|
||||
|
|
Loading…
Reference in a new issue