mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-25 21:20:18 +00:00
More f-string changes (#1025)
This commit is contained in:
parent
52b3abfe69
commit
9b0c8e5fd3
10 changed files with 44 additions and 40 deletions
|
@ -105,7 +105,7 @@ Usage Examples
|
||||||
|
|
||||||
# Example 5: List all content with the word 'Game' in the title.
|
# Example 5: List all content with the word 'Game' in the title.
|
||||||
for video in plex.search('Game'):
|
for video in plex.search('Game'):
|
||||||
print('%s (%s)' % (video.title, video.TYPE))
|
print(f'{video.title} ({video.TYPE})')
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
|
@ -812,8 +812,8 @@ class Playable:
|
||||||
durationStr = durationStr + str(duration)
|
durationStr = durationStr + str(duration)
|
||||||
else:
|
else:
|
||||||
durationStr = durationStr + str(self.duration)
|
durationStr = durationStr + str(self.duration)
|
||||||
key = '/:/timeline?ratingKey=%s&key=%s&identifier=com.plexapp.plugins.library&time=%d&state=%s%s'
|
key = (f'/:/timeline?ratingKey={self.ratingKey}&key={self.key}&'
|
||||||
key %= (self.ratingKey, self.key, time, state, durationStr)
|
f'identifier=com.plexapp.plugins.library&time={int(time)}&state={state}{durationStr}')
|
||||||
self._server.query(key)
|
self._server.query(key)
|
||||||
self._reload(_overwriteNone=False)
|
self._reload(_overwriteNone=False)
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ class PlexClient(PlexObject):
|
||||||
controller = command.split('/')[0]
|
controller = command.split('/')[0]
|
||||||
headers = {'X-Plex-Target-Client-Identifier': self.machineIdentifier}
|
headers = {'X-Plex-Target-Client-Identifier': self.machineIdentifier}
|
||||||
if controller not in self.protocolCapabilities:
|
if controller not in self.protocolCapabilities:
|
||||||
log.debug(f"Client {self.title} doesn't support {controller} controller. What your trying might not work")
|
log.debug("Client %s doesn't support %s controller. What your trying might not work", self.title, controller)
|
||||||
|
|
||||||
proxy = self._proxyThroughServer if proxy is None else proxy
|
proxy = self._proxyThroughServer if proxy is None else proxy
|
||||||
query = self._server.query if proxy else self.query
|
query = self._server.query if proxy else self.query
|
||||||
|
|
|
@ -550,9 +550,8 @@ class Collection(
|
||||||
sync_item.metadataType = self.metadataType
|
sync_item.metadataType = self.metadataType
|
||||||
sync_item.machineIdentifier = self._server.machineIdentifier
|
sync_item.machineIdentifier = self._server.machineIdentifier
|
||||||
|
|
||||||
sync_item.location = 'library:///directory/%s' % quote_plus(
|
key = quote_plus(f'{self.key}/children?excludeAllLeaves=1')
|
||||||
'%s/children?excludeAllLeaves=1' % (self.key)
|
sync_item.location = f'library:///directory/{key}'
|
||||||
)
|
|
||||||
sync_item.policy = Policy.create(limit, unwatched)
|
sync_item.policy = Policy.create(limit, unwatched)
|
||||||
|
|
||||||
if self.isVideo:
|
if self.isVideo:
|
||||||
|
|
|
@ -483,8 +483,8 @@ class LibrarySection(PlexObject):
|
||||||
xpath = (
|
xpath = (
|
||||||
'./MediaProvider[@identifier="com.plexapp.plugins.library"]'
|
'./MediaProvider[@identifier="com.plexapp.plugins.library"]'
|
||||||
'/Feature[@type="content"]'
|
'/Feature[@type="content"]'
|
||||||
'/Directory[@id="%s"]'
|
f'/Directory[@id="{self.key}"]'
|
||||||
) % self.key
|
)
|
||||||
directory = next(iter(data.findall(xpath)), None)
|
directory = next(iter(data.findall(xpath)), None)
|
||||||
if directory:
|
if directory:
|
||||||
self._totalDuration = utils.cast(int, directory.attrib.get('durationTotal'))
|
self._totalDuration = utils.cast(int, directory.attrib.get('durationTotal'))
|
||||||
|
@ -710,7 +710,7 @@ class LibrarySection(PlexObject):
|
||||||
""" Edit a library's advanced settings. """
|
""" Edit a library's advanced settings. """
|
||||||
data = {}
|
data = {}
|
||||||
idEnums = {}
|
idEnums = {}
|
||||||
key = 'prefs[%s]'
|
key = 'prefs[{}]'
|
||||||
|
|
||||||
for setting in self.settings():
|
for setting in self.settings():
|
||||||
if setting.type != 'bool':
|
if setting.type != 'bool':
|
||||||
|
@ -724,7 +724,7 @@ class LibrarySection(PlexObject):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NotFound(f'{value} not found in {list(idEnums.keys())}')
|
raise NotFound(f'{value} not found in {list(idEnums.keys())}')
|
||||||
if value in enums:
|
if value in enums:
|
||||||
data[key % settingID] = value
|
data[key.format(settingID)] = value
|
||||||
else:
|
else:
|
||||||
raise NotFound(f'{value} not found in {enums}')
|
raise NotFound(f'{value} not found in {enums}')
|
||||||
|
|
||||||
|
@ -733,12 +733,12 @@ class LibrarySection(PlexObject):
|
||||||
def defaultAdvanced(self):
|
def defaultAdvanced(self):
|
||||||
""" Edit all of library's advanced settings to default. """
|
""" Edit all of library's advanced settings to default. """
|
||||||
data = {}
|
data = {}
|
||||||
key = 'prefs[%s]'
|
key = 'prefs[{}]'
|
||||||
for setting in self.settings():
|
for setting in self.settings():
|
||||||
if setting.type == 'bool':
|
if setting.type == 'bool':
|
||||||
data[key % setting.id] = int(setting.default)
|
data[key.format(setting.id)] = int(setting.default)
|
||||||
else:
|
else:
|
||||||
data[key % setting.id] = setting.default
|
data[key.format(setting.id)] = setting.default
|
||||||
|
|
||||||
return self.edit(**data)
|
return self.edit(**data)
|
||||||
|
|
||||||
|
@ -988,7 +988,7 @@ class LibrarySection(PlexObject):
|
||||||
field = 'genre' # Available filter field from listFields()
|
field = 'genre' # Available filter field from listFields()
|
||||||
filterField = next(f for f in library.listFields() if f.key.endswith(field))
|
filterField = next(f for f in library.listFields() if f.key.endswith(field))
|
||||||
availableOperators = [o.key for o in library.listOperators(filterField.type)]
|
availableOperators = [o.key for o in library.listOperators(filterField.type)]
|
||||||
print("Available operators for %s:" % field, availableOperators)
|
print(f"Available operators for {field}:", availableOperators)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.getFieldType(fieldType).operators
|
return self.getFieldType(fieldType).operators
|
||||||
|
@ -1015,7 +1015,7 @@ class LibrarySection(PlexObject):
|
||||||
|
|
||||||
field = 'genre' # Available filter field from listFilters()
|
field = 'genre' # Available filter field from listFilters()
|
||||||
availableChoices = [f.title for f in library.listFilterChoices(field)]
|
availableChoices = [f.title for f in library.listFilterChoices(field)]
|
||||||
print("Available choices for %s:" % field, availableChoices)
|
print(f"Available choices for {field}:", availableChoices)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(field, str):
|
if isinstance(field, str):
|
||||||
|
|
|
@ -95,7 +95,7 @@ class Media(PlexObject):
|
||||||
try:
|
try:
|
||||||
return self._server.query(part, method=self._server._session.delete)
|
return self._server.query(part, method=self._server._session.delete)
|
||||||
except BadRequest:
|
except BadRequest:
|
||||||
log.error(f"Failed to delete {part}. This could be because you haven't allowed items to be deleted")
|
log.error("Failed to delete %s. This could be because you haven't allowed items to be deleted", part)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -598,7 +598,7 @@ class MyPlexAccount(PlexObject):
|
||||||
values = []
|
values = []
|
||||||
for key, vals in filterDict.items():
|
for key, vals in filterDict.items():
|
||||||
if key not in ('contentRating', 'label', 'contentRating!', 'label!'):
|
if key not in ('contentRating', 'label', 'contentRating!', 'label!'):
|
||||||
raise BadRequest('Unknown filter key: %s', key)
|
raise BadRequest(f'Unknown filter key: {key}')
|
||||||
values.append(f"{key}={'%2C'.join(vals)}")
|
values.append(f"{key}={'%2C'.join(vals)}")
|
||||||
return '|'.join(values)
|
return '|'.join(values)
|
||||||
|
|
||||||
|
@ -615,7 +615,7 @@ class MyPlexAccount(PlexObject):
|
||||||
return self.setWebhooks(urls)
|
return self.setWebhooks(urls)
|
||||||
|
|
||||||
def setWebhooks(self, urls):
|
def setWebhooks(self, urls):
|
||||||
log.info(f'Setting webhooks: {urls}')
|
log.info('Setting webhooks: %s', urls)
|
||||||
data = {'urls[]': urls} if len(urls) else {'urls': ''}
|
data = {'urls[]': urls} if len(urls) else {'urls': ''}
|
||||||
data = self.query(self.WEBHOOKS, self._session.post, data=data)
|
data = self.query(self.WEBHOOKS, self._session.post, data=data)
|
||||||
self._webhooks = self.listAttrs(data, 'url', etag='webhook')
|
self._webhooks = self.listAttrs(data, 'url', etag='webhook')
|
||||||
|
@ -686,7 +686,7 @@ class MyPlexAccount(PlexObject):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not client:
|
if not client:
|
||||||
raise BadRequest('Unable to find client by clientId=%s', clientId)
|
raise BadRequest(f'Unable to find client by clientId={clientId}')
|
||||||
|
|
||||||
if 'sync-target' not in client.provides:
|
if 'sync-target' not in client.provides:
|
||||||
raise BadRequest("Received client doesn't provides sync-target")
|
raise BadRequest("Received client doesn't provides sync-target")
|
||||||
|
@ -1037,7 +1037,7 @@ class MyPlexUser(PlexObject):
|
||||||
if utils.cast(int, item.attrib.get('userID')) == self.id:
|
if utils.cast(int, item.attrib.get('userID')) == self.id:
|
||||||
return item.attrib.get('accessToken')
|
return item.attrib.get('accessToken')
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(f'Failed to get access token for {self.title}')
|
log.exception('Failed to get access token for %s', self.title)
|
||||||
|
|
||||||
def server(self, name):
|
def server(self, name):
|
||||||
""" Returns the :class:`~plexapi.myplex.MyPlexServerShare` that matches the name specified.
|
""" Returns the :class:`~plexapi.myplex.MyPlexServerShare` that matches the name specified.
|
||||||
|
|
|
@ -911,8 +911,7 @@ class PlexServer(PlexObject):
|
||||||
gigabytes = round(bandwidth.bytes / 1024**3, 3)
|
gigabytes = round(bandwidth.bytes / 1024**3, 3)
|
||||||
local = 'local' if bandwidth.lan else 'remote'
|
local = 'local' if bandwidth.lan else 'remote'
|
||||||
date = bandwidth.at.strftime('%Y-%m-%d')
|
date = bandwidth.at.strftime('%Y-%m-%d')
|
||||||
print('%s used %s GB of %s bandwidth on %s from %s'
|
print(f'{account.name} used {gigabytes} GB of {local} bandwidth on {date} from {device.name}')
|
||||||
% (account.name, gigabytes, local, date, device.name))
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
params = {}
|
params = {}
|
||||||
|
@ -1149,12 +1148,14 @@ class StatisticsBandwidth(PlexObject):
|
||||||
self.timespan = utils.cast(int, data.attrib.get('timespan'))
|
self.timespan = utils.cast(int, data.attrib.get('timespan'))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s>' % ':'.join([p for p in [
|
return '<{}>'.format(
|
||||||
|
':'.join([p for p in [
|
||||||
self.__class__.__name__,
|
self.__class__.__name__,
|
||||||
self._clean(self.accountID),
|
self._clean(self.accountID),
|
||||||
self._clean(self.deviceID),
|
self._clean(self.deviceID),
|
||||||
self._clean(int(self.at.timestamp()))
|
self._clean(int(self.at.timestamp()))
|
||||||
] if p])
|
] if p])
|
||||||
|
)
|
||||||
|
|
||||||
def account(self):
|
def account(self):
|
||||||
""" Returns the :class:`~plexapi.server.SystemAccount` associated with the bandwidth data. """
|
""" Returns the :class:`~plexapi.server.SystemAccount` associated with the bandwidth data. """
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Settings(PlexObject):
|
||||||
params = {}
|
params = {}
|
||||||
for setting in self.all():
|
for setting in self.all():
|
||||||
if setting._setValue:
|
if setting._setValue:
|
||||||
log.info(f'Saving PlexServer setting {setting.id} = {setting._setValue}')
|
log.info('Saving PlexServer setting %s = %s', setting.id, setting._setValue)
|
||||||
params[setting.id] = quote(setting._setValue)
|
params[setting.id] = quote(setting._setValue)
|
||||||
if not params:
|
if not params:
|
||||||
raise BadRequest('No setting have been modified.')
|
raise BadRequest('No setting have been modified.')
|
||||||
|
|
|
@ -671,11 +671,13 @@ class Season(
|
||||||
yield episode
|
yield episode
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s>' % ':'.join([p for p in [
|
return '<{}>'.format(
|
||||||
|
':'.join([p for p in [
|
||||||
self.__class__.__name__,
|
self.__class__.__name__,
|
||||||
self.key.replace('/library/metadata/', '').replace('/children', ''),
|
self.key.replace('/library/metadata/', '').replace('/children', ''),
|
||||||
'%s-s%s' % (self.parentTitle.replace(' ', '-')[:20], self.seasonNumber),
|
f"{self.parentTitle.replace(' ', '-')[:20]}-{self.seasonNumber}",
|
||||||
] if p])
|
] if p])
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def isPlayed(self):
|
def isPlayed(self):
|
||||||
|
@ -862,11 +864,13 @@ class Episode(
|
||||||
self.parentKey = f'/library/metadata/{self.parentRatingKey}'
|
self.parentKey = f'/library/metadata/{self.parentRatingKey}'
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s>' % ':'.join([p for p in [
|
return '<{}>'.format(
|
||||||
|
':'.join([p for p in [
|
||||||
self.__class__.__name__,
|
self.__class__.__name__,
|
||||||
self.key.replace('/library/metadata/', '').replace('/children', ''),
|
self.key.replace('/library/metadata/', '').replace('/children', ''),
|
||||||
'%s-%s' % (self.grandparentTitle.replace(' ', '-')[:20], self.seasonEpisode),
|
f"{self.grandparentTitle.replace(' ', '-')[:20]}-{self.seasonEpisode}",
|
||||||
] if p])
|
] if p])
|
||||||
|
)
|
||||||
|
|
||||||
def _prettyfilename(self):
|
def _prettyfilename(self):
|
||||||
""" Returns a filename for use in download. """
|
""" Returns a filename for use in download. """
|
||||||
|
|
Loading…
Reference in a new issue