Skip to content

Commit

Permalink
Fix initial discard of subsequent pages of playlistitems
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Dec 15, 2023
1 parent cb6b85a commit 23de682
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions resources/lib/youtube_plugin/youtube/helper/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_channels(self, ids):

# Re-sort result to match order of requested IDs
# Will only work in Python v3.7+
if list(result) != ids:
if list(result) != ids[:len(result)]:
result = {
id: result[id]
for id in ids
Expand Down Expand Up @@ -149,7 +149,7 @@ def get_playlists(self, ids):

# Re-sort result to match order of requested IDs
# Will only work in Python v3.7+
if list(result) != ids:
if list(result) != ids[:len(result)]:
result = {
id: result[id]
for id in ids
Expand Down Expand Up @@ -193,13 +193,20 @@ def get_playlist_items(self, ids=None, batch_id=None):
.format(ids=list(result)))

new_data = {}
insert_point = 0
for playlist_id, page_token in to_update:
new_batch_ids = []
batch_id = (playlist_id, page_token)
insert_point = batch_ids.index(batch_id, insert_point)
while 1:
batch_id = (playlist_id, page_token)
new_batch_ids.append(batch_id)
batch = self._client.get_playlist_items(*batch_id)
new_data[batch_id] = batch
page_token = batch.get('nextPageToken') if fetch_next else None
if page_token is None:
batch_ids[insert_point:insert_point] = new_batch_ids
insert_point += len(new_batch_ids)
break

if new_data:
Expand All @@ -213,7 +220,7 @@ def get_playlist_items(self, ids=None, batch_id=None):

# Re-sort result to match order of requested IDs
# Will only work in Python v3.7+
if list(result) != batch_ids:
if list(result) != batch_ids[:len(result)]:
result = {
id: result[id]
for id in batch_ids
Expand Down Expand Up @@ -274,7 +281,7 @@ def get_videos(self, ids, live_details=False, suppress_errors=False):

# Re-sort result to match order of requested IDs
# Will only work in Python v3.7+
if list(result) != ids:
if list(result) != ids[:len(result)]:
result = {
id: result[id]
for id in ids
Expand Down

0 comments on commit 23de682

Please sign in to comment.