Skip to content

Commit adf3116

Browse files
committed
Add pagination for trakt boxoffice's #125
1 parent 68a73f7 commit adf3116

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

plugins/trakt.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,24 @@ def get_list(list_id, config=None):
145145
elif list_id.startswith("shows/") or list_id.startswith("movies/"):
146146
# Chart
147147
logger.debug("Trakt chart list")
148-
r = requests.get(f"https://api.trakt.tv/{list_id}", headers=headers)
148+
149+
current_page = 1
150+
items_data = []
151+
while True:
152+
r = requests.get(f"https://api.trakt.tv/{list_id}?page={current_page}", headers=headers)
153+
items_data += r.json()
154+
page_count = int(r.headers.get("X-Pagination-Page-Count", 1))
155+
logger.debug(f"Page {current_page}/{page_count}")
156+
if current_page >= page_count:
157+
break
158+
current_page += 1
159+
149160
list_name = Trakt._chart_types[list_id]["title"]
150161
description = Trakt._chart_types[list_id]["description"]
151-
152162
if list_id.startswith("shows/"):
153163
item_types = "show"
154164
else:
155165
item_types = "movie"
156-
157-
items_data = r.json()
158166
else:
159167
logger.debug("Trakt User list")
160168
r = requests.get(f"https://api.trakt.tv/lists/{list_id}", headers=headers)

0 commit comments

Comments
 (0)