summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorrafa_99 <raroma09@gmail.com>2021-09-01 00:27:27 +0100
committerrafa_99 <raroma09@gmail.com>2021-09-01 00:27:27 +0100
commite2ffc88b409b54f7a23d963095ea3a2439a361c1 (patch)
tree09700de3cb28cc5ef8dade9519c02d789073e320 /libs
parentdae23472f41380b232134d20412d59844040daea (diff)
JSON Navigation
Diffstat (limited to 'libs')
-rw-r--r--libs/json.c36
-rw-r--r--libs/json.h1
2 files changed, 33 insertions, 4 deletions
diff --git a/libs/json.c b/libs/json.c
index 4b0dac0..3631c19 100644
--- a/libs/json.c
+++ b/libs/json.c
@@ -3,11 +3,39 @@
#include <string.h>
#include <json-c/json.h>
#include "json.h"
+#define MAXLENGTH 256
json_object* jsonParseString(char* stringedJSON)
{
- struct json_object *json;
- json = ( stringedJSON != NULL && strlen(stringedJSON) > 0 ) ? json_tokener_parse(stringedJSON) : NULL;
- free(stringedJSON);
- return json;
+ return ( stringedJSON != NULL && strlen(stringedJSON) > 0 ) ? json_tokener_parse(stringedJSON) : NULL;
+}
+
+json_object* navigateToVideos(json_object* jsonRoot)
+{
+ char path[][MAXLENGTH] = {
+ "contents",
+ "twoColumnSearchResultsRenderer",
+ "primaryContents",
+ "sectionListRenderer",
+ "contents",
+ "0",
+ "itemSectionRenderer",
+ "contents"
+ };
+
+ json_object *videos = json_object_object_get(jsonRoot, path[0]);
+
+ for( int i = 1; i < sizeof(path)/sizeof(path[0]); i++ )
+ {
+ if ( json_object_get_type(videos) == json_type_array )
+ {
+ videos = json_object_array_get_idx(videos, atoi(path[i]));
+ }
+ else
+ {
+ videos = json_object_object_get(videos, path[i]);
+ }
+ }
+
+ return videos;
}
diff --git a/libs/json.h b/libs/json.h
index 3896805..f769d9c 100644
--- a/libs/json.h
+++ b/libs/json.h
@@ -2,3 +2,4 @@
#include <json-c/json.h>
json_object* jsonParseString(char* stringedJSON);
+json_object* navigateToVideos(json_object* jsonRoot);