idiotbox

youtube scraping and interfaces: CGI, Gopher, CLI
Log | Files | Refs | README | LICENSE

commit e27a668ed3d8fb19addd6aaed493cf3de2e77aa3
parent ee23b274b4833848218247d0a766620a4a64ff4c
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 17 Feb 2019 12:08:47 +0100

cli: ignore all control-characters from youtube input

Diffstat:
Mcli.c | 37+++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/cli.c b/cli.c @@ -21,12 +21,21 @@ #define TLS_CA_CERT_FILE "/etc/ssl/cert.pem" #endif -/* TODO: escape control-characters etc */ #define OUT(s) (fputs((s), stdout)) +#define OUTESCAPE(s) (printescape(s)) struct video *videos; static int nvideos; +/* print: ignore control-characters */ +void +printescape(const char *s) +{ + for (; *s; ++s) + if (!iscntrl((unsigned char)*s)) + fputc(*s, stdout); +} + void die(const char *fmt, ...) { @@ -115,25 +124,25 @@ render(void) switch (videos[i].linktype) { case Channel: OUT("[Channel] "); - OUT(videos[i].channeltitle); + OUTESCAPE(videos[i].channeltitle); break; case Movie: OUT("[Movie] "); - OUT(videos[i].title); + OUTESCAPE(videos[i].title); break; case Playlist: OUT("[Playlist] "); - OUT(videos[i].title); + OUTESCAPE(videos[i].title); break; default: - OUT(videos[i].title); + OUTESCAPE(videos[i].title); break; } OUT("\n"); if (videos[i].id[0]) { OUT("URL: https://www.youtube.com/embed/"); - OUT(videos[i].id); + OUTESCAPE(videos[i].id); OUT("\n"); } @@ -141,41 +150,41 @@ render(void) OUT("Atom feed: https://www.youtube.com/feeds/videos.xml?"); if (videos[i].channelid[0]) { OUT("channel_id="); - OUT(videos[i].channelid); + OUTESCAPE(videos[i].channelid); } else if (videos[i].userid[0]) { OUT("user="); - OUT(videos[i].userid); + OUTESCAPE(videos[i].userid); } OUT("\n"); } if (videos[i].channelid[0] || videos[i].userid[0]) { OUT("Channel title: "); - OUT(videos[i].channeltitle); + OUTESCAPE(videos[i].channeltitle); OUT("\n"); if (videos[i].channelid[0]) { OUT("Channelid: "); - OUT(videos[i].channelid); + OUTESCAPE(videos[i].channelid); OUT("\n"); } else if (videos[i].userid[0]) { OUT("Userid: "); - OUT(videos[i].userid); + OUTESCAPE(videos[i].userid); OUT("\n"); } } if (videos[i].publishedat[0]) { OUT("Published: "); - OUT(videos[i].publishedat); + OUTESCAPE(videos[i].publishedat); OUT("\n"); } if (videos[i].viewcount[0]) { OUT("Viewcount: "); - OUT(videos[i].viewcount); + OUTESCAPE(videos[i].viewcount); OUT("\n"); } if (videos[i].duration[0]) { OUT("Duration: " ); - OUT(videos[i].duration); + OUTESCAPE(videos[i].duration); OUT("\n"); } OUT("===\n");