Dedupe clip fields

This commit is contained in:
Ivan Habunek 2021-04-25 17:30:13 +02:00
parent 2f51b3821b
commit 9c3cf11635
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -96,6 +96,30 @@ VIDEO_FIELDS = """
""" """
CLIP_FIELDS = """
id
slug
title
createdAt
viewCount
durationSeconds
url
videoQualities {
frameRate
quality
sourceURL
}
game {
id
name
}
broadcaster {
displayName
login
}
"""
def get_video(video_id): def get_video(video_id):
query = """ query = """
{{ {{
@ -115,31 +139,12 @@ def get_clip(slug):
query = """ query = """
{{ {{
clip(slug: "{}") {{ clip(slug: "{}") {{
id {fields}
slug
title
createdAt
viewCount
durationSeconds
url
videoQualities {{
frameRate
quality
sourceURL
}}
game {{
id
name
}}
broadcaster {{
displayName
login
}}
}} }}
}} }}
""" """
response = gql_query(query.format(slug)) response = gql_query(query.format(slug, fields=CLIP_FIELDS))
return response["data"]["clip"] return response["data"]["clip"]
@ -184,26 +189,7 @@ def get_channel_clips(channel_id, period, limit, after=None):
edges {{ edges {{
cursor cursor
node {{ node {{
id {fields}
slug
title
createdAt
viewCount
durationSeconds
url
videoQualities {{
frameRate
quality
sourceURL
}}
game {{
id
name
}}
broadcaster {{
displayName
login
}}
}} }}
}} }}
}} }}
@ -211,12 +197,13 @@ def get_channel_clips(channel_id, period, limit, after=None):
}} }}
""" """
query = query.format(**{ query = query.format(
"channel_id": channel_id, channel_id=channel_id,
"after": after if after else "", after=after if after else "",
"limit": limit, limit=limit,
"period": period.upper(), period=period.upper(),
}) fields=CLIP_FIELDS
)
response = gql_query(query) response = gql_query(query)
user = response["data"]["user"] user = response["data"]["user"]
@ -264,18 +251,7 @@ def get_channel_videos(channel_id, limit, sort, type="archive", game_ids=[], aft
edges {{ edges {{
cursor cursor
node {{ node {{
id {fields}
title
publishedAt
broadcastType
lengthSeconds
game {{
name
}}
creator {{
login
displayName
}}
}} }}
}} }}
}} }}
@ -283,14 +259,15 @@ def get_channel_videos(channel_id, limit, sort, type="archive", game_ids=[], aft
}} }}
""" """
query = query.format(**{ query = query.format(
"channel_id": channel_id, channel_id=channel_id,
"game_ids": game_ids, game_ids=game_ids,
"after": after if after else "", after=after if after else "",
"limit": limit, limit=limit,
"sort": sort.upper(), sort=sort.upper(),
"type": type.upper(), type=type.upper(),
}) fields=VIDEO_FIELDS
)
response = gql_query(query) response = gql_query(query)