Add sorting options for clips (ascending/descending for view-count and date) #120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Twitch's gql API sucks and doesn't seem to support anything but
VIEWS_DESC
for the query. AFAIK the official stance for the public Helix API is to just sort the data yourself after getting it.So, here we are.
Tested with
--json
and--pager
as well as without. Haven't tested downloading but I don't see why that would break.This does have poor performance when working with large numbers of clips (e.g.
--all
on channels with thousands of clips) since it has to first exhaust the generator before sorting. But until we can query the GQL API properly I don't see any way around it.There's no performance impact to the default setting of sorting by view-count descending since the query response comes sorted that way already (so we don't need to exhaust the generator).
Should be noted that since the API returns clips sorted by View Count, the sorting method provided by
--sort
will only apply to the most-viewed clips unless you specify--all
. So that may be a little confusing for end users.