From 5e620cd9868239347a51e669f0e4f96e3dda8be0 Mon Sep 17 00:00:00 2001 From: ghuter Date: Wed, 2 Nov 2022 21:29:29 +0100 Subject: [PATCH] create an uri scheme, "yt://", to prefix youtube IDs --- caoydl.c | 10 +++++----- youtube.c | 8 +++++++- youtube.h | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/caoydl.c b/caoydl.c index 54184d3..35229d2 100644 --- a/caoydl.c +++ b/caoydl.c @@ -86,7 +86,7 @@ render(struct Items *r, char ext_search) if (!ext_search) { for (i = 0; i < r->nitem; i++) { if (item[i].id[0] && item[i].title[0]) { - OUTESCAPE(item[i].id); + OUT("%s%s", urischeme, item[i].id); OUT("\t"); OUTESCAPE(item[i].title); OUT("\n"); @@ -118,7 +118,7 @@ render(struct Items *r, char ext_search) if (item[i].id[0]) { OUT("URL: https://www.youtube.com/embed/"); - OUTESCAPE(item[i].id); + OUT("%s", item[i].id); OUT("\n"); } @@ -203,7 +203,7 @@ render_chan_urls(struct Items *r) for (i = 0; i < r->nitem; i++) { if (vid[i].title[0] && vid[i].id[0]) { - OUTESCAPE(vid[i].id); + OUT("%s%s", urischeme, vid[i].id); OUT("\t"); OUTESCAPE(vid[i].title); OUT("\n"); @@ -226,7 +226,7 @@ render_chan_pl(struct Items *r) if (vid[i].title[0] && vid[i].vid_count[0] && vid[i].id[0]) { - OUTESCAPE(vid[i].id); + OUT("%s%s", urischeme, vid[i].id); OUT("\t"); OUTESCAPE(vid[i].vid_count); OUT("\t"); @@ -250,7 +250,7 @@ render_playlist_urls(struct Items *r) for (i = 0; i < r->nitem; i++) { if (vid[i].title[0] && vid[i].id[0]) { - OUTESCAPE(vid[i].id); + OUT("%s%s", urischeme, vid[i].id); OUT("\t"); OUTESCAPE(vid[i].title); OUT("\n"); diff --git a/youtube.c b/youtube.c index 82188fa..19ff41b 100644 --- a/youtube.c +++ b/youtube.c @@ -54,7 +54,6 @@ idchr(const unsigned char c) struct Id url2id(char *url) { - size_t len = strlen(url); struct Id id = {}; struct Url2id { @@ -70,6 +69,13 @@ url2id(char *url) { STRANDLEN("list="), Playlist, 34, }, }; + /* if our particular uri scheme is in use, skip it */ + char *s = strstr(url, urischeme); + if (s) + url = s + strlen(urischeme); + + size_t len = strlen(url); + switch (len) { case 11: id.type = Video; diff --git a/youtube.h b/youtube.h index ca4f7de..79669fc 100644 --- a/youtube.h +++ b/youtube.h @@ -1,6 +1,8 @@ #define MAX_VIDEOS 500 #define MAX_URLS 30 +static char urischeme[] = "yt://"; + enum { PL, CHAN_VIDS, -- 2.45.2