youtube: when clicking a channel, show the latest videos - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit f47b9452628b9a68e527b7872771b08ef47e38c4 (DIR) parent 2be30b4f834c64d4478e8cff231ee9b29601edc0 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Sat, 18 Feb 2023 11:32:41 +0100 youtube: when clicking a channel, show the latest videos Diffstat: M youtube/cgi.c | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) --- (DIR) diff --git a/youtube/cgi.c b/youtube/cgi.c @@ -21,7 +21,7 @@ extern char **environ; static int curpage = 1; /* CGI parameters */ -static char rawsearch[4096], search[4096], order[16], page[64]; +static char rawsearch[4096], search[4096], order[16], page[64], channelid[256]; void parsecgi(void) @@ -69,6 +69,12 @@ parsecgi(void) exit(1); } } + + /* channel ID */ + if ((p = getparam(query, "chan"))) { + if (decodeparam(channelid, sizeof(channelid), p) == -1) + channelid[0] = '\0'; + } } int @@ -177,13 +183,16 @@ render(struct search_response *r) "</span><br/>\n" "\t\t<span class=\"channel\">"); - OUT("<a href=\"?q="); - xmlencode(videos[i].channeltitle); - OUT("&o="); - xmlencode(order); - OUT("\">"); - xmlencode(videos[i].channeltitle); - OUT("</a>"); + if (videos[i].channelid[0]) { + OUT("<a href=\"?chan="); + xmlencode(videos[i].channelid); + OUT("\">"); + xmlencode(videos[i].channeltitle); + OUT("</a>"); + } else { + xmlencode(videos[i].channeltitle); + } + if (videos[i].channelid[0] || videos[i].userid[0]) { OUT(" | <a title=\""); xmlencode(videos[i].channeltitle); @@ -197,6 +206,7 @@ render(struct search_response *r) } OUT("\">Atom feed</a>"); } + OUT("</span><br/>\n"); if (videos[i].publishedat[0]) { OUT(" <span class=\"publishedat\">Published: "); @@ -272,10 +282,12 @@ main(void) parsecgi(); - if (!rawsearch[0]) + if (rawsearch[0]) + r = youtube_search(rawsearch, page, order); + else if (channelid[0]) + r = youtube_channel_videos(channelid); + else goto show; - - r = youtube_search(rawsearch, page, order); if (!r || r->nitems == 0) { OUT("Status: 500 Internal Server Error\r\n\r\n"); exit(1);