Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sorting options for clips (ascending/descending for view-count and date) #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions twitchdl/commands/clips.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def clips(args):

generator = twitch.channel_clips_generator(args.channel_name, args.period, limit)

if args.sort != "views-desc":
match args.sort:
case "views-asc":
generator = sorted(list(generator), key=lambda x: x['viewCount'])
case "date-desc":
generator = sorted(list(generator), key=lambda x: x['createdAt'], reverse=True)
case "date-asc":
generator = sorted(list(generator), key=lambda x: x['createdAt'])

if args.json:
return print_json(list(generator))

Expand Down
8 changes: 7 additions & 1 deletion twitchdl/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def rate(value: str) -> int:
"type": str,
}),
(["-l", "--limit"], {
"help": "Number of videos to fetch. Defaults to 40 in copmpact mode, 10 otherwise.",
"help": "Number of videos to fetch. Defaults to 40 in compact mode, 10 otherwise.",
"type": pos_integer,
}),
(["-a", "--all"], {
Expand Down Expand Up @@ -143,6 +143,12 @@ def rate(value: str) -> int:
"action": "store_true",
"default": False,
}),
(["-s", "--sort"], {
"help": "Order in which to return clips. Defaults to `views-desc`.",
"type": str,
"choices": ["views-desc", "views-asc", "date-desc", "date-asc"],
"default": "views-desc",
}),
(["-P", "--period"], {
"help": "Period from which to return clips. Defaults to `all_time`.",
"type": str,
Expand Down