Skip to content

Commit

Permalink
Improve paging
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed May 17, 2020
1 parent d22fd74 commit cabc8ff
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions twitchdl/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,40 @@ def get_channel_videos(channel_id, limit, sort, type="archive", game_ids=[], aft

query = """
{{
user(login: "{channel_id}") {{
videos(options: {{
gameIDs: {game_ids}
}}, first: {limit}, type: {type}, sort: {sort}, after: "{after}") {{
totalCount
edges {{
cursor
node {{
id
title
publishedAt
broadcastType
lengthSeconds
game {{
name
}}
creator {{
channel {{
displayName
user(login: "{channel_id}") {{
videos(
first: {limit},
type: {type},
sort: {sort},
after: "{after}",
options: {{
gameIDs: {game_ids}
}}
) {{
totalCount
pageInfo {{
hasNextPage
}}
edges {{
cursor
node {{
id
title
publishedAt
broadcastType
lengthSeconds
game {{
name
}}
creator {{
channel {{
displayName
}}
}}
}}
}}
}}
}}
}}
}}
}}
}}
"""

Expand All @@ -152,9 +161,10 @@ def channel_videos_generator(channel_id, limit, sort, type, game_ids=None):
if not videos["edges"]:
break

cursor = videos["edges"][-1]["cursor"]
has_next = videos["pageInfo"]["hasNextPage"]
cursor = videos["edges"][-1]["cursor"] if has_next else None

yield videos, cursor is not None
yield videos, has_next

if not cursor:
break
Expand Down

0 comments on commit cabc8ff

Please sign in to comment.