youtube/gopher: list channel videos, allow to search by ?search - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit f3adbb9aabfccab9ab538881887867e1ffca5863 (DIR) parent fa40d5e0863446d6083d7290249b65f738474a76 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Sat, 18 Feb 2023 13:10:19 +0100 youtube/gopher: list channel videos, allow to search by ?search Also allows linking to channel videos with ?c=channelid. Diffstat: M youtube/gopher.c | 44 ++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) --- (DIR) diff --git a/youtube/gopher.c b/youtube/gopher.c @@ -20,6 +20,10 @@ static const char *host = "127.0.0.1", *port = "70"; +static const char *querystring = ""; +static const char *channelid = ""; +static const char *requestpath = "/"; + void line(int _type, const char *username, const char *selector) { @@ -94,6 +98,16 @@ render(struct search_response *r) } printf("\t%s\t%s\r\n", host, port); + if (videos[i].channelid[0]) { + OUT("1"); + OUT(videos[i].channeltitle); + printf("\t%s?c=%s\t%s\t%s\r\n", requestpath, videos[i].channelid, host, port); + } else if (videos[i].channeltitle[0]) { + OUT("i"); + OUT(videos[i].channeltitle); + printf("\t%s\t%s\t%s\r\n", "", host, port); + } + if (videos[i].channelid[0] || videos[i].userid[0]) { OUT("hAtom feed of "); OUTTEXT(videos[i].channeltitle); @@ -134,8 +148,9 @@ render(struct search_response *r) int main(void) { - struct search_response *r; - char *p, search[1024]; + struct search_response *r = NULL; + const char *p; + char search[1024]; if (pledge("stdio dns inet rpath unveil", NULL) == -1) exit(1); @@ -147,17 +162,34 @@ main(void) host = p; if ((p = getenv("SERVER_PORT"))) port = p; - - if (!(p = getenv("X_GOPHER_SEARCH"))) /* geomyidae */ + if ((p = getenv("PATH_TRANSLATED"))) + requestpath = p; + if ((p = getenv("QUERY_STRING"))) + querystring = p; + + p = NULL; + if (querystring[0] == '?') + querystring++; + if (querystring[0] == 'c' && querystring[1] == '=') { + channelid = querystring + 2; + p = querystring = ""; + } + if (querystring[0]) + p = querystring; + if (!p) + p = getenv("X_GOPHER_SEARCH"); /* geomyidae */ + if (!p) p = getenv("SEARCHREQUEST"); /* gophernicus */ - if (p && !uriencode(p, search, sizeof(search))) { error("Invalid search"); printf(".\r\n"); exit(1); } - r = youtube_search(search, "", "relevance"); + if (search[0]) + r = youtube_search(search, "", "relevance"); + else if (channelid[0]) + r = youtube_channel_videos(channelid); if (!r || r->nitems == 0) { error("No videos found"); printf(".\r\n");