youtube: change searching in channel/user - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 7d908e50fd0ce5df924886d613721495bf835eb6 (DIR) parent 596b6dd0de7c2971acf63b959441ad53af008d85 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Fri, 14 Aug 2020 20:56:03 +0200 youtube: change searching in channel/user Remove searching in channel/user, the layout was changed and this was broken. Instead now when clicking on the channel title search on the channel title. Diffstat: M youtube/cgi.c | 118 ++++++++----------------------- M youtube/cli.c | 2 +- M youtube/gopher.c | 2 +- M youtube/youtube.c | 21 ++++----------------- M youtube/youtube.h | 3 +-- 5 files changed, 38 insertions(+), 108 deletions(-) --- (DIR) diff --git a/youtube/cgi.c b/youtube/cgi.c @@ -22,7 +22,6 @@ static int curpage = 1; /* CGI parameters */ static char rawsearch[4096], search[4096], order[16], page[64]; -static char chan[1024], user[1024]; void parsecgi(void) @@ -33,25 +32,6 @@ parsecgi(void) if (!(query = getenv("QUERY_STRING"))) query = ""; - /* channel: search in channel */ - if ((p = getparam(query, "chan"))) { - if (decodeparam(chan, sizeof(chan), p) == -1) - chan[0] = '\0'; - } - /* user: search in user */ - if ((p = getparam(query, "user"))) { - if (decodeparam(user, sizeof(user), p) == -1) - user[0] = '\0'; - } - if (!strcmp(chan, "Search all") || !strcmp(user, "Search all")) { - chan[0] = '\0'; - user[0] = '\0'; - } - - /* prefer channel over user when both are set */ - if (chan[0] && user[0]) - user[0] = '\0'; - /* order */ if ((p = getparam(query, "o"))) { if (decodeparam(order, sizeof(order), p) == -1 || @@ -61,7 +41,7 @@ parsecgi(void) order[0] = '\0'; } if (!order[0]) - snprintf(order, sizeof(order), chan[0] || user[0] ? "date" : "relevance"); + snprintf(order, sizeof(order), "relevance"); /* page */ if ((p = getparam(query, "page"))) { @@ -109,14 +89,7 @@ render(struct search_response *r) "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" "<title>Search: \""); xmlencode(search); - OUT("\""); - if (r && r->nitems && (chan[0] || user[0])) { - if (videos[0].channelid[0]) - printf(" in %s", videos[0].channeltitle); - else if (videos[0].userid[0]) - printf(" in %s", videos[0].userid); - } - printf(" sorted by %s</title>\n", order); + printf("\" sorted by %s</title>\n", order); OUT( "<link rel=\"stylesheet\" href=\"css/style.css\" type=\"text/css\" media=\"screen\" />\n" "<link rel=\"icon\" type=\"image/png\" href=\"/favicon.png\" />\n" @@ -125,17 +98,6 @@ render(struct search_response *r) "<body class=\"search\">\n" "<form method=\"get\" action=\"\">\n"); - if (chan[0]) { - OUT("<input type=\"hidden\" name=\"chan\" value=\""); - xmlencode(chan); - OUT("\" />\n"); - } - if (user[0]) { - OUT("<input type=\"hidden\" name=\"user\" value=\""); - xmlencode(user); - OUT("\" />\n"); - } - OUT( "<table class=\"search\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n" "<tr>\n" @@ -146,14 +108,7 @@ render(struct search_response *r) "\" placeholder=\"Search...\" size=\"72\" autofocus=\"autofocus\" class=\"search\" accesskey=\"f\" />\n" " </td>\n" " <td nowrap class=\"nowrap\">\n" - " <input type=\"submit\" value=\"Search\" class=\"button\"/>\n"); - - if (chan[0]) - OUT(" <input type=\"submit\" name=\"chan\" value=\"Search all\" title=\"Search globally and not in the selected channel\" accesskey=\"c\" />\n"); - if (user[0]) - OUT(" <input type=\"submit\" name=\"user\" value=\"Search all\" title=\"Search globally and not in the selected user\" accesskey=\"c\" />\n"); - - OUT( + " <input type=\"submit\" value=\"Search\" class=\"button\"/>\n" " <select name=\"o\" title=\"Order by\" accesskey=\"o\">\n"); printf(" <option value=\"date\"%s>Creation date</option>\n", !strcmp(order, "date") ? " selected=\"selected\"" : ""); printf(" <option value=\"relevance\"%s>Relevance</option>\n", !strcmp(order, "relevance") ? " selected=\"selected\"" : ""); @@ -220,16 +175,10 @@ render(struct search_response *r) "</span><br/>\n" "\t\t<span class=\"channel\">"); - OUT("<a title=\"Search in "); + OUT("<a href=\"?q="); xmlencode(videos[i].channeltitle); - OUT("\" href=\"?"); - if (videos[i].channelid[0]) { - OUT("chan="); - xmlencode(videos[i].channelid); - } else if (videos[i].userid[0]) { - OUT("user="); - xmlencode(videos[i].userid); - } + OUT("&o="); + xmlencode(order); OUT("\">"); xmlencode(videos[i].channeltitle); OUT("</a>"); @@ -270,41 +219,36 @@ render(struct search_response *r) } OUT("</tbody>\n"); - /* pagination does not work for user/channel search */ - if (!user[0] && !chan[0]) { - OUT( - "<tfoot>\n" - "<tr>\n" - "\t<td align=\"left\" class=\"nowrap\" nowrap>\n"); - if (curpage > 1) { - OUT("\t\t<a href=\"?q="); - xmlencode(search); - OUT("&page="); - snprintf(tmp, sizeof(tmp), "%d", curpage - 1); - xmlencode(tmp); - OUT("&o="); - xmlencode(order); - OUT("\" rel=\"prev\" accesskey=\"p\">← prev</a>\n"); - } - OUT( - "\t</td>\n\t<td></td>\n" - "\t<td align=\"right\" class=\"a-r nowrap\" nowrap>\n"); - + OUT( + "<tfoot>\n" + "<tr>\n" + "\t<td align=\"left\" class=\"nowrap\" nowrap>\n"); + if (curpage > 1) { OUT("\t\t<a href=\"?q="); xmlencode(search); OUT("&page="); - snprintf(tmp, sizeof(tmp), "%d", curpage + 1); + snprintf(tmp, sizeof(tmp), "%d", curpage - 1); xmlencode(tmp); OUT("&o="); xmlencode(order); - OUT("\" rel=\"next\" accesskey=\"n\">next →</a>\n"); - - OUT( - "\t</td>\n" - "</tr>\n" - "</tfoot>\n"); + OUT("\" rel=\"prev\" accesskey=\"p\">← prev</a>\n"); } - OUT("</table>\n"); + OUT( + "\t</td>\n\t<td></td>\n" + "\t<td align=\"right\" class=\"a-r nowrap\" nowrap>\n"); + + OUT("\t\t<a href=\"?q="); + xmlencode(search); + OUT("&page="); + snprintf(tmp, sizeof(tmp), "%d", curpage + 1); + xmlencode(tmp); + OUT("&o="); + xmlencode(order); + OUT("\" rel=\"next\" accesskey=\"n\">next →</a>\n" + "\t</td>\n" + "</tr>\n" + "</tfoot>\n" + "</table>\n"); } OUT("</body>\n</html>\n"); @@ -326,10 +270,10 @@ main(void) parsecgi(); - if (!rawsearch[0] && !chan[0] && !user[0]) + if (!rawsearch[0]) goto show; - r = youtube_search(rawsearch, chan, user, page, order); + r = youtube_search(rawsearch, page, order); if (!r || r->nitems == 0) { OUT("Status: 500 Internal Server Error\r\n\r\n"); exit(1); (DIR) diff --git a/youtube/cli.c b/youtube/cli.c @@ -142,7 +142,7 @@ main(int argc, char *argv[]) if (!uriencode(argv[1], search, sizeof(search))) usage(argv[0]); - r = youtube_search(search, "", "", "", "relevance"); + r = youtube_search(search, "", "relevance"); if (!r || r->nitems == 0) { OUT("No videos found\n"); exit(1); (DIR) diff --git a/youtube/gopher.c b/youtube/gopher.c @@ -157,7 +157,7 @@ main(void) exit(1); } - r = youtube_search(search, "", "", "", "relevance"); + r = youtube_search(search, "", "relevance"); if (!r || r->nitems == 0) { error("No videos found"); printf(".\r\n"); (DIR) diff --git a/youtube/youtube.c b/youtube/youtube.c @@ -254,23 +254,11 @@ xmltagstart(XMLParser *x, const char *t, size_t tl) } static char * -request_search(const char *s, const char *chan, const char *user, - const char *page, const char *order) +request_search(const char *s, const char *page, const char *order) { char path[4096]; - /* when searching in channel or user but the search string is empty: - fake a search with a single space. */ - if ((chan[0] || user[0]) && !s[0]) - s = "+"; - - if (user[0]) - snprintf(path, sizeof(path), "/user/%s/search?query=%s", user, s); - else if (chan[0]) - snprintf(path, sizeof(path), "/channel/%s/search?query=%s", chan, s); - else - snprintf(path, sizeof(path), "/results?search_query=%s", s); - + snprintf(path, sizeof(path), "/results?search_query=%s", s); if (page[0]) { strlcat(path, "&page=", sizeof(path)); strlcat(path, page, sizeof(path)); @@ -298,14 +286,13 @@ request_search(const char *s, const char *chan, const char *user, } struct search_response * -youtube_search(const char *rawsearch, const char *chan, const char *user, - const char *page, const char *order) +youtube_search(const char *rawsearch, const char *page, const char *order) { struct search_response *r; XMLParser x = { 0 }; char *data, *s; - if (!(data = request_search(rawsearch, chan, user, page, order))) + if (!(data = request_search(rawsearch, page, order))) return NULL; if (!(s = strstr(data, "\r\n\r\n"))) return NULL; /* invalid response */ (DIR) diff --git a/youtube/youtube.h b/youtube/youtube.h @@ -18,5 +18,4 @@ struct search_response { }; struct search_response * -youtube_search(const char *rawsearch, const char *chan, const char *user, - const char *page, const char *order); +youtube_search(const char *rawsearch, const char *page, const char *order);