mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-25 05:00:22 +00:00
Replace format strings with explicit call to format() for backward compatibility (fixes #576) (#577)
This commit is contained in:
parent
737401be0e
commit
14b8d0e8c8
3 changed files with 26 additions and 22 deletions
|
@ -88,10 +88,10 @@ class PlayQueue(PlexObject):
|
|||
return matches[0]
|
||||
elif len(matches) > 1:
|
||||
raise BadRequest(
|
||||
f"{item} occurs multiple times in this PlayQueue, provide exact item"
|
||||
"{item} occurs multiple times in this PlayQueue, provide exact item".format(item=item)
|
||||
)
|
||||
else:
|
||||
raise BadRequest(f"{item} not valid for this PlayQueue")
|
||||
raise BadRequest("{item} not valid for this PlayQueue".format(item=item))
|
||||
|
||||
@classmethod
|
||||
def create(
|
||||
|
@ -130,8 +130,8 @@ class PlayQueue(PlexObject):
|
|||
|
||||
if isinstance(items, list):
|
||||
item_keys = ",".join([str(x.ratingKey) for x in items])
|
||||
uri_args = quote_plus(f"/library/metadata/{item_keys}")
|
||||
args["uri"] = f"library:///directory/{uri_args}"
|
||||
uri_args = quote_plus("/library/metadata/{item_keys}".format(item_keys=item_keys))
|
||||
args["uri"] = "library:///directory/{uri_args}".format(uri_args=uri_args)
|
||||
args["type"] = items[0].listType
|
||||
elif items.type == "playlist":
|
||||
args["playlistID"] = items.ratingKey
|
||||
|
@ -139,12 +139,12 @@ class PlayQueue(PlexObject):
|
|||
else:
|
||||
uuid = items.section().uuid
|
||||
args["type"] = items.listType
|
||||
args["uri"] = f"library://{uuid}/item/{items.key}"
|
||||
args["uri"] = "library://{uuid}/item/{key}".format(uuid=uuid, key=items.key)
|
||||
|
||||
if startItem:
|
||||
args["key"] = startItem.key
|
||||
|
||||
path = f"/playQueues{utils.joinArgs(args)}"
|
||||
path = "/playQueues{args}".format(args=utils.joinArgs(args))
|
||||
data = server.query(path, method=server._session.post)
|
||||
c = cls(server, data, initpath=path)
|
||||
c.playQueueType = args["type"]
|
||||
|
@ -174,7 +174,7 @@ class PlayQueue(PlexObject):
|
|||
else:
|
||||
uuid = item.section().uuid
|
||||
itemType = item.listType
|
||||
args["uri"] = f"library://{uuid}/item{item.key}"
|
||||
args["uri"] = "library://{uuid}/item{key}".format(uuid=uuid, key=item.key)
|
||||
|
||||
if itemType != self.playQueueType:
|
||||
raise Unsupported("Item type does not match PlayQueue type")
|
||||
|
@ -182,7 +182,7 @@ class PlayQueue(PlexObject):
|
|||
if playNext:
|
||||
args["next"] = 1
|
||||
|
||||
path = f"/playQueues/{self.playQueueID}{utils.joinArgs(args)}"
|
||||
path = "/playQueues/{playQueueID}{args}".format(playQueueID=self.playQueueID, args=utils.joinArgs(args))
|
||||
data = self._server.query(path, method=self._server._session.put)
|
||||
self._loadData(data)
|
||||
|
||||
|
@ -210,7 +210,9 @@ class PlayQueue(PlexObject):
|
|||
after = self.getQueueItem(after)
|
||||
args["after"] = after.playQueueItemID
|
||||
|
||||
path = f"/playQueues/{self.playQueueID}/items/{item.playQueueItemID}/move{utils.joinArgs(args)}"
|
||||
path = "/playQueues/{playQueueID}/items/{playQueueItemID}/move{args}".format(
|
||||
playQueueID=self.playQueueID, playQueueItemID=item.playQueueItemID, args=utils.joinArgs(args)
|
||||
)
|
||||
data = self._server.query(path, method=self._server._session.put)
|
||||
self._loadData(data)
|
||||
|
||||
|
@ -227,18 +229,20 @@ class PlayQueue(PlexObject):
|
|||
if item not in self:
|
||||
item = self.getQueueItem(item)
|
||||
|
||||
path = f"/playQueues/{self.playQueueID}/items/{item.playQueueItemID}"
|
||||
path = "/playQueues/{playQueueID}/items/{playQueueItemID}".format(
|
||||
playQueueID=self.playQueueID, playQueueItemID=item.playQueueItemID
|
||||
)
|
||||
data = self._server.query(path, method=self._server._session.delete)
|
||||
self._loadData(data)
|
||||
|
||||
def clear(self):
|
||||
"""Remove all items from the PlayQueue."""
|
||||
path = f"/playQueues/{self.playQueueID}/items"
|
||||
path = "/playQueues/{playQueueID}/items".format(playQueueID=self.playQueueID)
|
||||
data = self._server.query(path, method=self._server._session.delete)
|
||||
self._loadData(data)
|
||||
|
||||
def refresh(self):
|
||||
"""Refresh the PlayQueue from the Plex server."""
|
||||
path = f"/playQueues/{self.playQueueID}"
|
||||
path = "/playQueues/{playQueueID}".format(playQueueID=self.playQueueID)
|
||||
data = self._server.query(path, method=self._server._session.get)
|
||||
self._loadData(data)
|
||||
|
|
|
@ -10,10 +10,10 @@ def wait_for_idle_server(server):
|
|||
"""Wait for PMS activities to complete with a timeout."""
|
||||
attempts = 0
|
||||
while server.activities and attempts < MAX_ATTEMPTS:
|
||||
print(f"Waiting for activities to finish: {server.activities}")
|
||||
print("Waiting for activities to finish: {activities}".format(activities=server.activities))
|
||||
time.sleep(1)
|
||||
attempts += 1
|
||||
assert attempts < MAX_ATTEMPTS, f"Server still busy after {MAX_ATTEMPTS}s"
|
||||
assert attempts < MAX_ATTEMPTS, "Server still busy after {MAX_ATTEMPTS}s".format(MAX_ATTEMPTS=MAX_ATTEMPTS)
|
||||
|
||||
|
||||
def wait_for_metadata_processing(server):
|
||||
|
@ -26,12 +26,12 @@ def wait_for_metadata_processing(server):
|
|||
tl = section.timeline()
|
||||
if tl.updateQueueSize > 0:
|
||||
busy = True
|
||||
print(f"{section.title}: {tl.updateQueueSize} items left")
|
||||
print("{title}: {updateQueueSize} items left".format(title=section.title, updateQueueSize=tl.updateQueueSize))
|
||||
if not busy or attempts > MAX_ATTEMPTS:
|
||||
break
|
||||
time.sleep(1)
|
||||
attempts += 1
|
||||
assert attempts < MAX_ATTEMPTS, f"Metadata still processing after {MAX_ATTEMPTS}s"
|
||||
assert attempts < MAX_ATTEMPTS, "Metadata still processing after {MAX_ATTEMPTS}s".format(MAX_ATTEMPTS=MAX_ATTEMPTS)
|
||||
|
||||
|
||||
def test_ensure_activities_completed(plex):
|
||||
|
|
|
@ -26,7 +26,7 @@ def _has_markwatched_tag(item):
|
|||
|
||||
def _get_title(item):
|
||||
if item.type == 'episode':
|
||||
return f'{item.grandparentTitle} {item.seasonEpisode}'
|
||||
return '{title} {episode}'.format(title=item.grandparentTitle, episode=item.seasonEpisode)
|
||||
return item.title
|
||||
|
||||
|
||||
|
@ -41,17 +41,17 @@ def _iter_items(search):
|
|||
|
||||
if __name__ == '__main__':
|
||||
datestr = lambda: datetime.now().strftime('%Y-%m-%d %H:%M:%S') # noqa
|
||||
print(f'{datestr()} Starting plex-markwatched script..')
|
||||
print('{datestr} Starting plex-markwatched script..'.format(datestr=datestr()))
|
||||
plex = PlexServer()
|
||||
for section in plex.library.sections():
|
||||
print(f'{datestr()} Checking {section.title} for unwatched items..')
|
||||
print('{datestr} Checking {section.title} for unwatched items..'.format(datestr=datestr()))
|
||||
for item in _iter_items(section.search(collection='markwatched')):
|
||||
if not item.isWatched:
|
||||
print(f'{datestr()} Marking {_get_title(item)} watched.')
|
||||
print('{datestr} Marking {_get_title(item)} watched.'.format(datestr=datestr()))
|
||||
item.markWatched()
|
||||
# Check all OnDeck items
|
||||
print(f'{datestr()} Checking OnDeck for unwatched items..')
|
||||
print('{datestr} Checking OnDeck for unwatched items..'.format(datestr=datestr()))
|
||||
for item in plex.library.onDeck():
|
||||
if not item.isWatched and _has_markwatched_tag(item):
|
||||
print(f'{datestr()} Marking {_get_title(item)} watched.')
|
||||
print('{datestr} Marking {_get_title(item)} watched.'.format(datestr=datestr()))
|
||||
item.markWatched()
|
||||
|
|
Loading…
Reference in a new issue