From 0b9ddae0a6bbf3144f13c86f9c96dd67a9174e32 Mon Sep 17 00:00:00 2001 From: rafa_99 Date: Wed, 1 Sep 2021 21:25:28 +0100 Subject: Cleaning Up some 🍝 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.c | 68 +++++++++++++++++++++---------------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/src/utils.c b/src/utils.c index b58836c..8b3e691 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "utils.h" #include "../libs/curl.h" #include "../libs/string.h" @@ -136,61 +137,38 @@ char *queryNormalizer(char *query) return norm; } -int* jsonDataLimits(int tokenCount, char **tokens, char *topDelimiter, char *bottomDelimiter) -{ - int *limits = (int *) calloc(2, sizeof(int)); - - for (int i = 0; i < tokenCount + 1 && (limits[0] == 0 || limits[1] == 0); i++) - { - if (tokens[i] != NULL && strcmp(tokens[i], topDelimiter) == 0 && strcmp(tokens[i + 1], "=") == 0) - { - limits[0] = i + 2; - } - else if (tokens[i] != NULL && limits[1] == 0 && limits[0] > 0 && strstr(tokens[i], bottomDelimiter) != NULL) - { - limits[1] = i; - } - } - - return limits; -} - char* extractQueryJSON(char *youtubeurl) { char *json = NULL; if (youtubeurl != NULL && strlen(youtubeurl) > 0) { - // Setting Up Vars - char jsonVar[] = "ytInitialData", unneededHtml[] = "; 0 ) { - if (i < limits[1]) - { - json = realloc(json, (strlen(json) + strlen(tokens[i]) + 2)); - strcat(json, tokens[i]); - strcat(json, " "); - } - else + // Setting Up Vars + char jsonVar[] = "ytInitialData", needlessHTML[] = ";