summaryrefslogtreecommitdiff
path: root/queryt.c
diff options
context:
space:
mode:
authorrafa_99 <raroma09@gmail.com>2021-09-04 17:50:20 +0100
committerrafa_99 <raroma09@gmail.com>2021-09-04 17:50:20 +0100
commited9ad979be88a230eb873e8914a2425f84f09b06 (patch)
tree6700ee59d65f80fa9bd30dc8c168ff3fd3b0b57c /queryt.c
parentde404a7e66132b918410c3770c3b802b4052dc02 (diff)
Updated Main and Some Memory Errors
Diffstat (limited to 'queryt.c')
-rw-r--r--queryt.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/queryt.c b/queryt.c
index a91f234..8f198b0 100644
--- a/queryt.c
+++ b/queryt.c
@@ -5,7 +5,7 @@
#include <json-c/json.h>
#include "include/utils.h"
#include "include/video.h"
-#include "libs/curl.h"
+#include "libs/json.h"
void processOptions(int *options, char **args);
@@ -82,14 +82,36 @@ void processOptions(int *options, char **args)
if ( json != NULL && strlen(json) > 0 )
{
- json_object *queryRoot = json_tokener_parse(json), *handler;
+ json_object *queryRoot = jsonParseString(json);
free(json);
if ( queryRoot != NULL && json_object_get_type(queryRoot) != json_type_null )
{
+ json_object *handler = navigateToVideos(queryRoot);
+ int videoCount = videoCounter(handler);
+
+ if ( videoCount > 0 )
+ {
+ Video *videos = generateVideos(handler);
+ json_object_put(queryRoot);
+ int printedVideos = ( options[2] && checkNumber(args[1]) > 0) ? checkNumber(args[1]) : videoCount;
+ char *format = ( options[0] ) ? args[0] : "";
+ printVideoInfo(format, videos, printedVideos);
+
+ for ( int i = 0; i < videoCount; i++ )
+ {
+ freeVideo(&videos[i]);
+ }
+
+ free(videos);
+ }
+ else
+ {
+ json_object_put(queryRoot);
+ }
}
else
{
- json_object_put(queryRoot);
+ json_object_put(queryRoot);
}
}
else