youtube: add shortdescription from search or channel/user listings - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit e0461c105d8e02725c05d0cafd896fc54fb8be30 (DIR) parent d278df39b1e6a28ada817813ecb6a2ed96817b90 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Sat, 25 Feb 2023 19:40:40 +0100 youtube: add shortdescription from search or channel/user listings Diffstat: M youtube/cli.c | 7 +++++-- M youtube/youtube.c | 28 ++++++++++++++++++++++------ M youtube/youtube.h | 3 --- 3 files changed, 27 insertions(+), 11 deletions(-) --- (DIR) diff --git a/youtube/cli.c b/youtube/cli.c @@ -79,7 +79,8 @@ render_search_tsv(struct search_response *r) OUTESCAPE(videos[i].channeltitle); OUT("\t"); OUTESCAPE(videos[i].userid); - OUT("\t"); +/* OUT("\t"); + OUTESCAPE(videos[i].shortdescription); */ /* TODO: escape newlines etc */ OUT("\n"); } @@ -89,10 +90,12 @@ render_search_tsv(struct search_response *r) int render_search(struct search_response *r) { - struct item *videos = r->items; + struct item *videos = r->items, *v; size_t i; for (i = 0; i < r->nitems; i++) { + v = &(r->items[i]); + switch (videos[i].linktype) { case Channel: OUT("Channel: "); (DIR) diff --git a/youtube/youtube.c b/youtube/youtube.c @@ -191,8 +191,24 @@ processnode_search(struct json_node *nodes, size_t depth, const char *value, strlcpy(item->title, value, sizeof(item->title)); } - /* in channel/user videos listing there is a short description */ -#ifdef neinneinnein + /* in search listing there is a short description, string items are appended */ + if (depth >= 8 && + nodes[depth - 7].type == JSON_TYPE_OBJECT && + nodes[depth - 6].type == JSON_TYPE_ARRAY && + nodes[depth - 5].type == JSON_TYPE_OBJECT && + nodes[depth - 4].type == JSON_TYPE_OBJECT && + nodes[depth - 3].type == JSON_TYPE_ARRAY && + nodes[depth - 2].type == JSON_TYPE_OBJECT && + nodes[depth - 1].type == JSON_TYPE_STRING && + !strcmp(nodes[depth - 7].name, "videoRenderer") && + !strcmp(nodes[depth - 6].name, "detailedMetadataSnippets") && + !strcmp(nodes[depth - 4].name, "snippetText") && + !strcmp(nodes[depth - 3].name, "runs") && + !strcmp(nodes[depth - 1].name, "text")) { + strlcat(item->shortdescription, value, sizeof(item->shortdescription)); + } + + /* in channel/user videos listing there is a short description, string items are appended */ if (depth >= 7 && nodes[depth - 5].type == JSON_TYPE_OBJECT && nodes[depth - 4].type == JSON_TYPE_OBJECT && @@ -202,11 +218,9 @@ processnode_search(struct json_node *nodes, size_t depth, const char *value, !strcmp(nodes[depth - 5].name, "videoRenderer") && !strcmp(nodes[depth - 4].name, "descriptionSnippet") && !strcmp(nodes[depth - 3].name, "runs") && - !strcmp(nodes[depth - 1].name, "text") && - !item->shortdescription[0]) { - strlcpy(item->shortdescription, value, sizeof(item->shortdescription)); + !strcmp(nodes[depth - 1].name, "text")) { + strlcat(item->shortdescription, value, sizeof(item->shortdescription)); } -#endif if (depth >= 5 && nodes[depth - 4].type == JSON_TYPE_OBJECT && @@ -275,6 +289,8 @@ parse_search_response(const char *data) /* skip header */ s += strlen("\r\n\r\n"); +// s = data; // DEBUG + if (!(r = calloc(1, sizeof(*r)))) return NULL; (DIR) diff --git a/youtube/youtube.h b/youtube/youtube.h @@ -8,10 +8,7 @@ struct item { char publishedat[32]; /* "human-friendly" string */ char viewcount[32]; /* view count string, formatted */ char duration[32]; /* duration string */ - -#ifdef neinneinnein char shortdescription[4096]; -#endif }; #define MAX_VIDEOS 50