summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrafa_99 <raroma09@gmail.com>2021-09-03 22:27:03 +0100
committerrafa_99 <raroma09@gmail.com>2021-09-03 22:27:03 +0100
commitde404a7e66132b918410c3770c3b802b4052dc02 (patch)
tree6cfc6e1e3201d2b0535f152a8dfe03965e79c2e3
parent10e79ffa42b622228d87b00dcf5addbb26d66ecd (diff)
Some more Main changes
-rw-r--r--queryt.c85
1 files changed, 72 insertions, 13 deletions
diff --git a/queryt.c b/queryt.c
index 546cf64..a91f234 100644
--- a/queryt.c
+++ b/queryt.c
@@ -2,15 +2,21 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
+#include <json-c/json.h>
#include "include/utils.h"
#include "include/video.h"
+#include "libs/curl.h"
-void errorMessage(int errorCode, char* message);
-void processOptions(int *options);
+void processOptions(int *options, char **args);
int main(int argc, char **argv)
{
int o = 0, opts[] = { 0, 0, 0, 0, 0 };
+ char **args = (char **) calloc(3, sizeof(char *));
+ for ( int i = 0; i < 3; i++ )
+ {
+ args[i] = (char *) calloc(1, sizeof(char *));
+ }
static struct option long_options[] = {
{"format", required_argument, 0, 'f'},
@@ -27,35 +33,88 @@ int main(int argc, char **argv)
{
case 'f':
opts[0]++;
+ args[0] = (char *) realloc(args[0], strlen(optarg) + 1);
+ strcpy(args[0], optarg);
break;
case 'h':
opts[1]++;
break;
case 'm':
opts[2]++;
+ args[1] = (char *) realloc(args[1], strlen(optarg) + 1);
+ strcpy(args[1], optarg);
break;
case 's':
opts[3]++;
+ args[2] = (char *) realloc(args[2], strlen(optarg) + 1);
+ strcpy(args[2], optarg);
break;
case 'v':
opts[4]++;
- break;
- default:
- errorMessage(1, "");
}
}
- processOptions(opts);
+ processOptions(opts, args);
+
+ for ( int i = 0; i < 3; i++ )
+ {
+ free(args[i]);
+ }
+ free(args);
+
return 0;
}
-void errorMessage(int errorCode, char* message)
+void processOptions(int *options, char **args)
{
- printf("%s", message);
- exit(errorCode);
-}
+ if ( !options[1] && options[3] && !options[4] )
+ {
+ char *query = queryNormalizer(args[2]);
+ if ( query != NULL )
+ {
+ char *link = (char *) calloc(strlen("https://www.youtube.com/results?search_query=") + strlen(query) + 1, sizeof(char));
+ strcpy(link, "https://www.youtube.com/results?search_query=");
+ strcat(link, query);
-void processOptions(int *options)
-{
- //ToDo
+ char *json = extractQueryJSON(link);
+ free(link);
+ free(query);
+
+ if ( json != NULL && strlen(json) > 0 )
+ {
+ json_object *queryRoot = json_tokener_parse(json), *handler;
+ free(json);
+ if ( queryRoot != NULL && json_object_get_type(queryRoot) != json_type_null )
+ {
+ }
+ else
+ {
+ json_object_put(queryRoot);
+ }
+ }
+ else
+ {
+ free(json);
+ }
+
+ }
+ }
+ else
+ {
+ if ( options[1] || (options[3] && options[4]))
+ {
+ puts("Help Message");
+ }
+ else
+ {
+ if ( options[4] )
+ {
+ puts("Version Message");
+ }
+ else
+ {
+ puts("-s is required!");
+ }
+ }
+ }
}