简体   繁体   中英

Download 50 twitch.tv clips for a specific game for the past week

I'm using the code beneath to list 50 twitch.tv clips from the past 7 days. For some reason, the script isn't getting the top viewed clip and is starting further down. ( see images )

import requests

url = "https://gql.twitch.tv/gql"
json_req = """[{"query":"query ClipsCards__Game($gameName: String!, $limit: Int, $cursor: Cursor, $criteria: GameClipsInput) { game(name: $gameName) { id clips(first: $limit, after: $cursor, criteria: $criteria) { pageInfo { hasNextPage __typename } edges { cursor node { id slug url embedURL title viewCount language curator { id login displayName __typename } game { id name boxArtURL(width: 52, height: 72) __typename } broadcaster { id login displayName __typename } thumbnailURL createdAt durationSeconds __typename } __typename } __typename } __typename } } ","variables":{"gameName":"Counter-Strike: Global Offensive","limit":50,"criteria":{"languages":[],"filter":"LAST_WEEK"},"cursor":"MjA="},"operationName":"ClipsCards__Game"}]"""
r = requests.post(url, data=json_req, headers={"client-id":"kimne78kx3ncx6brgo4mv6wki5h1ko"})
r_json = r.json()

edges = r_json[0]['data']['game']['clips']['edges']
urls = [edge['node']['url'] for edge in edges]

for url in urls:
    print (url)

I'm trying to get the top 50 clips, starting from the most viewed and on. When scrolling down to invoke more clips to be shown, the first clip to load is the first clip to be stored instead of the actual first top clip.

For any more information, please do ask.

Thanks

According to the docs I don't see that the data returned is in any particular order.

Testing your code I did find the top clip in the list, you probably have to sort by view count to get the same result than on the pages you showed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM