youtube/cli: enable to sort via the command-line - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit d76cca97c957bab0b2a8dca7554837831522a8b6 (DIR) parent 3079e32c8a2abdcb8b896e9fd32c0c0f6a407e59 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Fri, 5 May 2023 11:37:43 +0200 youtube/cli: enable to sort via the command-line Only works with keywords search. Diffstat: M youtube/cli.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) --- (DIR) diff --git a/youtube/cli.c b/youtube/cli.c @@ -320,7 +320,7 @@ render_video(struct video_response *r) static void usage(const char *argv0) { - fprintf(stderr, "usage: %s [-t] <keyword> | <-c channelid> | <-u user> | <-i videoid>\n", argv0); + fprintf(stderr, "usage: %s [-t] <keyword> | <-c channelid> | <-u user> | <-i videoid> | [-o relevance|views|rating]\n", argv0); exit(1); } @@ -331,6 +331,7 @@ main(int argc, char *argv[]) struct video_response *vr = NULL; char search[1024]; const char *keywords = NULL, *channelid = NULL, *user = NULL, *videoid = NULL; + const char *order = "relevance"; int i, usetsv = 0; if (pledge("stdio dns inet rpath unveil", NULL) == -1) { @@ -353,6 +354,12 @@ main(int argc, char *argv[]) videoid = argv[i + 1]; i++; break; + case 'o': + if (i + 1 >= argc) + usage(argv[0]); + order = argv[i + 1]; + i++; + break; case 'u': if (i + 1 >= argc) usage(argv[0]); @@ -381,6 +388,13 @@ main(int argc, char *argv[]) if (argc < 2 || !argv[1][0]) usage(argv[0]); + + /* check order options */ + if (strcmp(order, "relevance") && + strcmp(order, "views") && + strcmp(order, "rating")) + usage(argv[0]); + if (channelid) { r = youtube_channel_videos(channelid); } else if (user) { @@ -396,7 +410,7 @@ main(int argc, char *argv[]) } else if (keywords) { if (!uriencode(keywords, search, sizeof(search))) usage(argv[0]); - r = youtube_search(search, "", "relevance"); + r = youtube_search(search, "", order); } if (!r || r->nitems == 0) { OUT("No videos found\n");