youtube: fix information for NSFW videos and add fields - frontends - front-ends for some sites (experiment)
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit ad970d5ed90fca291bb8e2a1738977efd788bcfa
 (DIR) parent 4d8ef4606fcdb808af8b505fc84318f22fe1c552
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sun, 26 Feb 2023 14:00:41 +0100
       
       youtube: fix information for NSFW videos and add fields
       
       Also add category, isunlisted and isfamilysafe field.
       
       Diffstat:
         M youtube/youtube.c                   |      14 +++++++++++---
         M youtube/youtube.h                   |       3 +++
       
       2 files changed, 14 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/youtube/youtube.c b/youtube/youtube.c
       @@ -317,8 +317,6 @@ processnode_video(struct json_node *nodes, size_t depth, const char *value,
                if (depth > 1) {
                        if (nodes[0].type == JSON_TYPE_OBJECT &&
                            !strcmp(nodes[1].name, "streamingData")) {
       -                        r->isfound = 1; /* a video is found */
       -
                                if (depth == 2 &&
                                    nodes[2].type == JSON_TYPE_STRING &&
                                    !strcmp(nodes[2].name, "expiresInSeconds")) {
       @@ -388,10 +386,18 @@ processnode_video(struct json_node *nodes, size_t depth, const char *value,
                    nodes[3].type == JSON_TYPE_STRING &&
                    !strcmp(nodes[1].name, "microformat") &&
                    !strcmp(nodes[2].name, "playerMicroformatRenderer")) {
       +                r->isfound = 1;
       +
                        if (!strcmp(nodes[3].name, "publishDate")) {
                                strlcpy(r->publishdate, value, sizeof(r->publishdate));
       -                } if (!strcmp(nodes[3].name, "uploadDate")) {
       +                } else if (!strcmp(nodes[3].name, "uploadDate")) {
                                strlcpy(r->uploaddate, value, sizeof(r->uploaddate));
       +                } else if (!strcmp(nodes[3].name, "category")) {
       +                        strlcpy(r->category, value, sizeof(r->category));
       +                } else if (!strcmp(nodes[3].name, "isFamilySafe")) {
       +                        r->isfamilysafe = !strcmp(value, "true");
       +                } else if (!strcmp(nodes[3].name, "isUnlisted")) {
       +                        r->isunlisted = !strcmp(value, "true");
                        }
                }
        
       @@ -399,6 +405,8 @@ processnode_video(struct json_node *nodes, size_t depth, const char *value,
                        if (nodes[0].type == JSON_TYPE_OBJECT &&
                            nodes[2].type == JSON_TYPE_STRING &&
                            !strcmp(nodes[1].name, "videoDetails")) {
       +                        r->isfound = 1;
       +
                                if (!strcmp(nodes[2].name, "title")) {
                                        strlcpy(r->title, value, sizeof(r->title));
                                } else if (!strcmp(nodes[2].name, "videoId")) {
 (DIR) diff --git a/youtube/youtube.h b/youtube/youtube.h
       @@ -46,6 +46,9 @@ struct video_response {
                long viewcount;
                long lengthseconds;
                char shortdescription[4096 * 4];
       +        char category[256];
       +        int isfamilysafe;
       +        int isunlisted;
        
                int isfound;