Specify broadcast type when listing videos

issue #13
This commit is contained in:
Ivan Habunek 2020-04-25 20:03:04 +02:00
parent c628757ac0
commit e3dde90870
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
3 changed files with 10 additions and 4 deletions

View File

@ -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")

View File

@ -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(

View File

@ -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,