summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrafa_99 <raroma09@gmail.com>2021-09-16 23:39:39 +0100
committerrafa_99 <raroma09@gmail.com>2021-09-16 23:39:39 +0100
commit2fd3a9d009d19e48eefda098cbedcf1aa02b660d (patch)
tree345617c4d7e0ca854f6807fdd4770678eb77b799
parent390763b0adcf3c435405251fc2983df8e73df7b2 (diff)
Updated Code Path
-rw-r--r--include/utils.h1
-rw-r--r--include/video.h1
-rw-r--r--queryt.c2
-rw-r--r--src/utils.c48
-rw-r--r--src/video.c49
5 files changed, 51 insertions, 50 deletions
diff --git a/include/utils.h b/include/utils.h
index 89326d9..48ada10 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -7,4 +7,3 @@ void freeTokens (char **tokens, int size);
char *queryNormalizer (char *query);
char *extractQueryJSON (char *youtubeurl);
int checkNumber (char *num);
-void printVideoInfo (char *format, Video *videos, int numberOfVideos);
diff --git a/include/video.h b/include/video.h
index 5156600..71cf047 100644
--- a/include/video.h
+++ b/include/video.h
@@ -6,4 +6,5 @@ typedef struct video
} Video;
Video createVideo (char *title, char *author, char *id, char *duration);
+void printVideo (char *format, Video *videos, int numberOfVideos);
void freeVideo (Video *v);
diff --git a/queryt.c b/queryt.c
index 35c1874..17f6cfa 100644
--- a/queryt.c
+++ b/queryt.c
@@ -104,7 +104,7 @@ processOptions (int *options, char **args, int argc)
? checkNumber (args[1])
: videoCount;
char *format = (options[0]) ? args[0] : "";
- printVideoInfo (format, videos, printedVideos);
+ printVideo (format, videos, printedVideos);
for (int i = 0; i < videoCount; i++)
{
diff --git a/src/utils.c b/src/utils.c
index d625fed..5391e6d 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -207,51 +207,3 @@ checkNumber (char *num)
return number;
}
-
-void
-printVideoInfo (char *format, Video *videos, int numberOfVideos)
-{
- if (format != NULL && strlen (format) > 0)
- {
- for (int i = 0; i < numberOfVideos; i++)
- {
- for (int j = 0; j < strlen (format); j++)
- {
- switch (format[j])
- {
- case 'a':
- printf ("%s", videos[i].author);
- break;
- case 'd':
- printf ("%s", videos[i].duration);
- break;
- case 'i':
- printf ("%s", videos[i].id);
- break;
- case 't':
- printf ("%s", videos[i].title);
- break;
- case 'R':
- printf ("\n");
- break;
- case 'T':
- printf ("\t");
- break;
- default:
- if (!isalpha (format[j]))
- {
- printf ("%c", format[j]);
- }
- }
- }
- printf ("\n");
- }
- }
- else
- {
- for (int i = 0; i < numberOfVideos; i++)
- {
- printf ("%s\t%s\n", videos[i].id, videos[i].title);
- }
- }
-}
diff --git a/src/video.c b/src/video.c
index 0e09437..e48245b 100644
--- a/src/video.c
+++ b/src/video.c
@@ -1,4 +1,5 @@
#include "../include/video.h"
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -36,6 +37,54 @@ createVideo (char *title, char *author, char *id, char *duration)
}
void
+printVideo (char *format, Video *videos, int numberOfVideos)
+{
+ if (format != NULL && strlen (format) > 0)
+ {
+ for (int i = 0; i < numberOfVideos; i++)
+ {
+ for (int j = 0; j < strlen (format); j++)
+ {
+ switch (format[j])
+ {
+ case 'a':
+ printf ("%s", videos[i].author);
+ break;
+ case 'd':
+ printf ("%s", videos[i].duration);
+ break;
+ case 'i':
+ printf ("%s", videos[i].id);
+ break;
+ case 't':
+ printf ("%s", videos[i].title);
+ break;
+ case 'R':
+ printf ("\n");
+ break;
+ case 'T':
+ printf ("\t");
+ break;
+ default:
+ if (!isalpha (format[j]))
+ {
+ printf ("%c", format[j]);
+ }
+ }
+ }
+ printf ("\n");
+ }
+ }
+ else
+ {
+ for (int i = 0; i < numberOfVideos; i++)
+ {
+ printf ("%s\t%s\n", videos[i].id, videos[i].title);
+ }
+ }
+}
+
+void
freeVideo (Video *v)
{
free (v->title);