mirror of
https://github.com/305a385/ytfind.git
synced 2024-07-26 23:54:30 +00:00
fixed bug where stack thinging occured
This commit is contained in:
parent
5bec1d71c6
commit
e883a34d26
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,2 @@
|
|||
# ignore binaries
|
||||
ytfind
|
||||
# ignore AUR packages
|
||||
PKGBUILD
|
||||
|
|
1
config.h
1
config.h
|
@ -1,2 +1,3 @@
|
|||
static const char NAME[] = "ytfind";
|
||||
static const char QUERY_RESULT_FILE[] = "/tmp/ytfind-query.json";
|
||||
static const char INSTANCE[] = "https://invidious.projectsegfau.lt/api/v1/search?q=";
|
||||
|
|
25
main.c
25
main.c
|
@ -10,6 +10,7 @@
|
|||
#include <json-c/json.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int printTitles(void){
|
||||
json_object *root = json_object_from_file(QUERY_RESULT_FILE);
|
||||
if (!root) {
|
||||
|
@ -33,13 +34,20 @@ int printTitles(void){
|
|||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if( argc < 2 ) {
|
||||
printf("usage: try './%s [query]' to make a get request.\n", NAME);
|
||||
printf("usage: try '%s [query]' to make a search.\n", NAME);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
char query[] = "https://invidious.projectsegfau.lt/api/v1/search?q=";
|
||||
char *query;
|
||||
query = (char*) malloc(sizeof(char*) * (sizeof(*argv) + sizeof(INSTANCE)));
|
||||
strcat(query, INSTANCE);
|
||||
|
||||
/* if memory cannot be allocated */
|
||||
if(query == NULL) {
|
||||
printf("Error! memory not allocated.");
|
||||
exit(0);
|
||||
}
|
||||
/* add all arguments to query */
|
||||
for (short i=1; i < argc; i++){
|
||||
/* add space before current argument if not first argument*/
|
||||
|
@ -68,7 +76,7 @@ int main(int argc, char *argv[]) {
|
|||
if(res != CURLE_OK) {
|
||||
fprintf(stderr, "error: %s\n", curl_easy_strerror(res));
|
||||
} else {
|
||||
/* create pointer to QUERY_RESULT_FILE
|
||||
/* create pointer to query_RESULT_FILE
|
||||
* (where the query will be stored,
|
||||
* you can change the value in config.h) */
|
||||
FILE *tmpFilePtr = fopen(QUERY_RESULT_FILE,"w");
|
||||
|
@ -78,10 +86,13 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
curl_easy_cleanup(curl_handle);
|
||||
free(chunk.memory);
|
||||
|
||||
/* dealocate memory for query */
|
||||
free(query);
|
||||
|
||||
/* print titles of videos to stdout */
|
||||
printTitles();
|
||||
printTitles();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
1
src/ytfind-1.0
Symbolic link
1
src/ytfind-1.0
Symbolic link
|
@ -0,0 +1 @@
|
|||
/home/saadyah/projects/c/ytfind/ytfind-1.0
|
Loading…
Reference in New Issue
Block a user