Add offset and sort options to videos command

fixes #7
This commit is contained in:
Ivan Habunek 2019-08-13 12:25:25 +02:00
parent 932b7750b9
commit 68a8b70948
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
3 changed files with 30 additions and 4 deletions

View File

@ -72,10 +72,18 @@ def _print_video(video):
print_out(video["url"])
def videos(channel_name, **kwargs):
videos = twitch.get_channel_videos(channel_name)
def videos(channel_name, limit, offset, sort, **kwargs):
videos = twitch.get_channel_videos(channel_name, limit, offset, sort)
print("Found {} videos".format(videos["_total"]))
count = len(videos['videos'])
if not count:
print_out("No videos found")
return
first = offset + 1
last = offset + len(videos['videos'])
total = videos["_total"]
print_out("<yellow>Showing videos {}-{} of {}</yellow>".format(first, last, total))
for video in videos['videos']:
_print_video(video)

View File

@ -41,6 +41,22 @@ COMMANDS = [
"help": "channel name",
"type": str,
}),
(["-l", "--limit"], {
"help": "Number of videos to fetch (default 10, max 100)",
"type": int,
"default": 10,
}),
(["-o", "--offset"], {
"help": "Offset for pagination of results. (default 0)",
"type": int,
"default": 0,
}),
(["-s", "--sort"], {
"help": "Sorting order of videos. (default: time)",
"type": str,
"choices": ["views", "time"],
"default": "time",
}),
],
),
Command(

View File

@ -27,7 +27,7 @@ def get_video(video_id):
return authenticated_get(url).json()
def get_channel_videos(channel_name, limit=20):
def get_channel_videos(channel_name, limit, offset, sort):
"""
https://dev.twitch.tv/docs/v5/reference/channels#get-channel-videos
"""
@ -36,6 +36,8 @@ def get_channel_videos(channel_name, limit=20):
return authenticated_get(url, {
"broadcast_type": "archive",
"limit": limit,
"offset": offset,
"sort": sort,
}).json()