youtube: cleanup, shorten variable name for videos - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 59471286810c9ef14f294bba649dd75a78e74c6a (DIR) parent e0461c105d8e02725c05d0cafd896fc54fb8be30 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Sat, 25 Feb 2023 19:48:59 +0100 youtube: cleanup, shorten variable name for videos Diffstat: M youtube/cgi.c | 60 ++++++++++++++++--------------- M youtube/cli.c | 68 ++++++++++++++++--------------- M youtube/gopher.c | 60 ++++++++++++++++--------------- 3 files changed, 97 insertions(+), 91 deletions(-) --- (DIR) diff --git a/youtube/cgi.c b/youtube/cgi.c @@ -86,7 +86,7 @@ parsecgi(void) int render(struct search_response *r) { - struct item *videos = r ? r->items : NULL; + struct item *v; char tmp[64]; size_t i; @@ -141,14 +141,16 @@ render(struct search_response *r) "<tbody>\n"); for (i = 0; i < r->nitems; i++) { + v = &(r->items[0]); + OUT("<tr class=\"v\">\n" " <td class=\"thumb\" width=\"120\" align=\"center\">\n"); - if (videos[i].id[0]) { + if (v->id[0]) { OUT(" <a href=\"https://www.youtube.com/embed/"); - xmlencode(videos[i].id); + xmlencode(v->id); OUT("\"><img src=\"https://i.ytimg.com/vi/"); - xmlencode(videos[i].id); + xmlencode(v->id); OUT("/default.jpg\" alt=\"\" height=\"90\" border=\"0\" /></a>\n"); } else { /* placeholder image */ @@ -158,81 +160,81 @@ render(struct search_response *r) " <td>\n" " <span class=\"title\">"); - if (videos[i].id[0]) { + if (v->id[0]) { OUT("<a href=\"https://www.youtube.com/embed/"); - xmlencode(videos[i].id); + xmlencode(v->id); printf("\" accesskey=\"%zu\">", i); } - switch (videos[i].linktype) { + switch (v->linktype) { case Channel: OUT("[Channel] "); - xmlencode(videos[i].channeltitle); + xmlencode(v->channeltitle); break; case Movie: OUT("[Movie] "); - xmlencode(videos[i].title); + xmlencode(v->title); break; case Playlist: OUT("[Playlist] "); - xmlencode(videos[i].title); + xmlencode(v->title); break; default: - xmlencode(videos[i].title); + xmlencode(v->title); break; } - if (videos[i].id[0]) + if (v->id[0]) OUT("</a>"); OUT( "</span><br/>\n" "\t\t<span class=\"channel\">"); - if (videos[i].channelid[0]) { + if (v->channelid[0]) { OUT("<a href=\"?chan="); - xmlencode(videos[i].channelid); + xmlencode(v->channelid); OUT("\">"); - xmlencode(videos[i].channeltitle); + xmlencode(v->channeltitle); OUT("</a>"); - } else if (videos[i].userid[0]) { + } else if (v->userid[0]) { OUT("<a href=\"?user="); - xmlencode(videos[i].channelid); + xmlencode(v->channelid); OUT("\">"); - xmlencode(videos[i].channeltitle); + xmlencode(v->channeltitle); OUT("</a>"); } else { - xmlencode(videos[i].channeltitle); + xmlencode(v->channeltitle); } - if (videos[i].channelid[0] || videos[i].userid[0]) { + if (v->channelid[0] || v->userid[0]) { OUT(" | <a title=\""); - xmlencode(videos[i].channeltitle); + xmlencode(v->channeltitle); OUT(" Atom feed\" href=\"https://www.youtube.com/feeds/videos.xml?"); - if (videos[i].channelid[0]) { + if (v->channelid[0]) { OUT("channel_id="); - xmlencode(videos[i].channelid); - } else if (videos[i].userid[0]) { + xmlencode(v->channelid); + } else if (v->userid[0]) { OUT("user="); - xmlencode(videos[i].userid); + xmlencode(v->userid); } OUT("\">Atom feed</a>"); } OUT("</span><br/>\n"); - if (videos[i].publishedat[0]) { + if (v->publishedat[0]) { OUT(" <span class=\"publishedat\">Published: "); - OUT(videos[i].publishedat); + OUT(v->publishedat); OUT("</span><br/>\n"); } OUT(" <span class=\"stats\">"); - OUT(videos[i].viewcount); + OUT(v->viewcount); OUT( "</span><br/>\n" " </td>\n" " <td align=\"right\" class=\"a-r\">\n" " <span class=\"duration\">"); - OUT(videos[i].duration); + OUT(v->duration); OUT( "</span>\n" " </td>\n" (DIR) diff --git a/youtube/cli.c b/youtube/cli.c @@ -48,39 +48,41 @@ printescape_multiline(const char *s, const char *indent) int render_search_tsv(struct search_response *r) { - struct item *videos = r->items; + struct item *v; size_t i; for (i = 0; i < r->nitems; i++) { - OUTESCAPE(videos[i].id); + v = &(r->items[i]); + + OUTESCAPE(v->id); OUT("\t"); - if (videos[i].id[0]) { + if (v->id[0]) { OUT("https://www.youtube.com/embed/"); - OUTESCAPE(videos[i].id); + OUTESCAPE(v->id); } OUT("\t"); - OUTESCAPE(videos[i].title); + OUTESCAPE(v->title); OUT("\t"); - OUTESCAPE(videos[i].publishedat); + OUTESCAPE(v->publishedat); OUT("\t"); - OUTESCAPE(videos[i].viewcount); + OUTESCAPE(v->viewcount); OUT("\t"); - OUTESCAPE(videos[i].duration); + OUTESCAPE(v->duration); OUT("\t"); - switch (videos[i].linktype) { + switch (v->linktype) { case Channel: OUT("channel"); break; case Movie: OUT("movie"); break; case Playlist: OUT("playlist"); break; default: break; } OUT("\t"); - OUTESCAPE(videos[i].channelid); + OUTESCAPE(v->channelid); OUT("\t"); - OUTESCAPE(videos[i].channeltitle); + OUTESCAPE(v->channeltitle); OUT("\t"); - OUTESCAPE(videos[i].userid); + OUTESCAPE(v->userid); /* OUT("\t"); - OUTESCAPE(videos[i].shortdescription); */ /* TODO: escape newlines etc */ + OUTESCAPE(v->shortdescription); */ /* TODO: escape newlines etc */ OUT("\n"); } @@ -90,64 +92,64 @@ render_search_tsv(struct search_response *r) int render_search(struct search_response *r) { - struct item *videos = r->items, *v; + struct item *v; size_t i; for (i = 0; i < r->nitems; i++) { v = &(r->items[i]); - switch (videos[i].linktype) { + switch (v->linktype) { case Channel: OUT("Channel: "); - OUTESCAPE(videos[i].channeltitle); + OUTESCAPE(v->channeltitle); break; case Movie: OUT("Movie: "); - OUTESCAPE(videos[i].title); + OUTESCAPE(v->title); break; case Playlist: OUT("Playlist: "); - OUTESCAPE(videos[i].title); + OUTESCAPE(v->title); break; default: OUT(" "); - OUTESCAPE(videos[i].title); + OUTESCAPE(v->title); break; } - if (videos[i].duration[0]) { + if (v->duration[0]) { OUT(" ["); - OUTESCAPE(videos[i].duration); + OUTESCAPE(v->duration); OUT("]"); } OUT("\n"); - if (videos[i].id[0]) { + if (v->id[0]) { OUT("URL: https://www.youtube.com/embed/"); - OUTESCAPE(videos[i].id); + OUTESCAPE(v->id); OUT("\n"); } - if (videos[i].channelid[0] || videos[i].userid[0]) { + if (v->channelid[0] || v->userid[0]) { OUT("Channel: "); - OUTESCAPE(videos[i].channeltitle); + OUTESCAPE(v->channeltitle); OUT(": https://www.youtube.com/feeds/videos.xml?"); - if (videos[i].channelid[0]) { + if (v->channelid[0]) { OUT("channel_id="); - OUTESCAPE(videos[i].channelid); - } else if (videos[i].userid[0]) { + OUTESCAPE(v->channelid); + } else if (v->userid[0]) { OUT("user="); - OUTESCAPE(videos[i].userid); + OUTESCAPE(v->userid); } OUT("\n"); } - if (videos[i].publishedat[0]) { + if (v->publishedat[0]) { OUT("Published: "); - OUTESCAPE(videos[i].publishedat); + OUTESCAPE(v->publishedat); OUT("\n"); } - if (videos[i].viewcount[0]) { + if (v->viewcount[0]) { OUT("Views: "); - OUTESCAPE(videos[i].viewcount); + OUTESCAPE(v->viewcount); OUT("\n"); } OUT("\n"); (DIR) diff --git a/youtube/gopher.c b/youtube/gopher.c @@ -56,7 +56,7 @@ footer(void) int render(struct search_response *r) { - struct item *videos = r->items; + struct item *v; size_t i; if (pledge("stdio", NULL) == -1) @@ -65,81 +65,83 @@ render(struct search_response *r) header(); for (i = 0; i < r->nitems; i++) { + v = &(r->items[0]); + if (i > 0) { info(""); info(""); } - if (videos[i].id[0]) + if (v->id[0]) putchar('h'); else putchar('i'); - switch (videos[i].linktype) { + switch (v->linktype) { case Channel: OUT("[Channel] "); - OUTTEXT(videos[i].channeltitle); + OUTTEXT(v->channeltitle); break; case Movie: OUT("[Movie] "); - OUTTEXT(videos[i].title); + OUTTEXT(v->title); break; case Playlist: OUT("[Playlist] "); - OUTTEXT(videos[i].title); + OUTTEXT(v->title); break; default: - OUTTEXT(videos[i].title); + OUTTEXT(v->title); break; } OUT("\t"); - if (videos[i].id[0]) { + if (v->id[0]) { OUT("URL:https://www.youtube.com/embed/"); - OUTLINK(videos[i].id); + OUTLINK(v->id); } printf("\t%s\t%s\r\n", host, port); - if (videos[i].channelid[0]) { + if (v->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].userid[0]) { + OUT(v->channeltitle); + printf("\t%s?c=%s\t%s\t%s\r\n", requestpath, v->channelid, host, port); + } else if (v->userid[0]) { OUT("1"); - OUT(videos[i].channeltitle); - printf("\t%s?u=%s\t%s\t%s\r\n", requestpath, videos[i].userid, host, port); - } else if (videos[i].channeltitle[0]) { + OUT(v->channeltitle); + printf("\t%s?u=%s\t%s\t%s\r\n", requestpath, v->userid, host, port); + } else if (v->channeltitle[0]) { OUT("i"); - OUT(videos[i].channeltitle); + OUT(v->channeltitle); printf("\t%s\t%s\t%s\r\n", "", host, port); } - if (videos[i].channelid[0] || videos[i].userid[0]) { + if (v->channelid[0] || v->userid[0]) { OUT("hAtom feed of "); - OUTTEXT(videos[i].channeltitle); + OUTTEXT(v->channeltitle); OUT("\t"); OUTLINK("URL:https://www.youtube.com/feeds/videos.xml?"); - if (videos[i].channelid[0]) { + if (v->channelid[0]) { OUT("channel_id="); - OUTLINK(videos[i].channelid); - } else if (videos[i].userid[0]) { + OUTLINK(v->channelid); + } else if (v->userid[0]) { OUT("user="); - OUTLINK(videos[i].userid); + OUTLINK(v->userid); } printf("\t%s\t%s\r\n", host, port); } - if (videos[i].duration[0]) { + if (v->duration[0]) { OUT("iDuration: " ); - OUTTEXT(videos[i].duration); + OUTTEXT(v->duration); printf("\t%s\t%s\t%s\r\n", "", host, port); } - if (videos[i].publishedat[0]) { + if (v->publishedat[0]) { OUT("iPublished: "); - OUTTEXT(videos[i].publishedat); + OUTTEXT(v->publishedat); printf("\t%s\t%s\t%s\r\n", "", host, port); } - if (videos[i].viewcount[0]) { + if (v->viewcount[0]) { OUT("iViews: "); - OUTTEXT(videos[i].viewcount); + OUTTEXT(v->viewcount); printf("\t%s\t%s\t%s\r\n", "", host, port); } }