From e3dde90870925e15a7341c5670346b1b06e8ee86 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sat, 25 Apr 2020 20:03:04 +0200 Subject: [PATCH] Specify broadcast type when listing videos issue #13 --- twitchdl/commands.py | 4 ++-- twitchdl/console.py | 6 ++++++ twitchdl/twitch.py | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/twitchdl/commands.py b/twitchdl/commands.py index b067476..c18ec22 100644 --- a/twitchdl/commands.py +++ b/twitchdl/commands.py @@ -16,14 +16,14 @@ from twitchdl.exceptions import ConsoleError from twitchdl.output import print_out, print_video -def videos(channel_name, limit, offset, sort, **kwargs): +def videos(channel_name, limit, offset, sort, type, **kwargs): print_out("Looking up user...") user = twitch.get_user(channel_name) if not user: raise ConsoleError("User {} not found.".format(channel_name)) print_out("Loading videos...") - videos = twitch.get_channel_videos(user["id"], limit, offset, sort) + videos = twitch.get_channel_videos(user["id"], limit, offset, sort, type) count = len(videos['videos']) if not count: print_out("No videos found") diff --git a/twitchdl/console.py b/twitchdl/console.py index c28f0fa..50a5cb4 100644 --- a/twitchdl/console.py +++ b/twitchdl/console.py @@ -57,6 +57,12 @@ COMMANDS = [ "choices": ["views", "time"], "default": "time", }), + (["-t", "--type"], { + "help": "Broadcast type. (default: archive)", + "type": str, + "choices": ["archive", "highlight", "upload"], + "default": "archive", + }), ], ), Command( diff --git a/twitchdl/twitch.py b/twitchdl/twitch.py index 87ca26e..2d16a98 100644 --- a/twitchdl/twitch.py +++ b/twitchdl/twitch.py @@ -93,14 +93,14 @@ def get_clip(slug): return data["data"]["clip"] -def get_channel_videos(channel_id, limit, offset, sort): +def get_channel_videos(channel_id, limit, offset, sort, type="archive"): """ https://dev.twitch.tv/docs/v5/reference/channels#get-channel-videos """ url = "https://api.twitch.tv/kraken/channels/{}/videos".format(channel_id) return kraken_get(url, { - "broadcast_type": "archive", + "broadcast_type": type, "limit": limit, "offset": offset, "sort": sort,