From 29c384db9bf9ecba5e71f25c54634c00fb0ca021 Mon Sep 17 00:00:00 2001 From: Leonardo Taccari Date: Sat, 6 Jun 2020 01:50:22 +0200 Subject: [PATCH 3/4] Expand extended_entities URLs in retweets --- tscrape.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tscrape.c b/tscrape.c index 8b211cb..a7686d6 100644 --- a/tscrape.c +++ b/tscrape.c @@ -415,6 +415,29 @@ processnodes(struct json_node *nodes, size_t depth, const char *str) url[0] = '\0'; } } + + /* [].retweeted_status.extended_entities.media[].url */ + if (depth == 7 && + nodes[0].type == JSON_TYPE_ARRAY && + nodes[1].type == JSON_TYPE_OBJECT && + nodes[2].type == JSON_TYPE_OBJECT && + nodes[3].type == JSON_TYPE_OBJECT && + nodes[4].type == JSON_TYPE_ARRAY && + nodes[5].type == JSON_TYPE_OBJECT && + nodes[6].type == JSON_TYPE_STRING && + !strcmp(nodes[2].name, "retweeted_status") && + !strcmp(nodes[3].name, "extended_entities") && + !strcmp(nodes[4].name, "media")) { + if (!strcmp(nodes[6].name, "url")) { +// printf("DEBUG: url: %s\n", str); + strlcpy(url, str, sizeof(url)); + } else if (!strcmp(nodes[6].name, "expanded_url")) { +// printf("DEBUG: expanded_url: %s\n", str); + /* assumes "expanded_url" is specified after "url" */ + addurl(url, str); + url[0] = '\0'; + } + } } int -- 2.24.1