move download() to hdbd.c and refactor it
it also wont compile because it is missing the config stuff
This commit is contained in:
62
src/hdb.c
62
src/hdb.c
@@ -78,68 +78,6 @@ int h_config_parser(Config *config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int h_download(char *line, Config config) {
|
||||
int ret;
|
||||
char *url = malloc(strlen(line));
|
||||
char *artist_name = malloc(strlen(line));
|
||||
char *website_name = malloc(strlen(line));
|
||||
sscanf(line, "%s %s %s", url, artist_name, website_name);
|
||||
char *args[7];
|
||||
char *tmp = malloc(10000);
|
||||
if (strstr(website_name, "Iwara") != NULL) {
|
||||
sprintf(tmp, "%s/%s/%s/%(id)s.%(ext)s", config.data_dir, artist_name, website_name);
|
||||
args[0] = "yt-dlp_linux";
|
||||
args[1] = "--config-locations";
|
||||
args[2] = config.yt_dlp_conf;
|
||||
args[3] = "-o";
|
||||
args[4] = tmp;
|
||||
args[5] = url;
|
||||
} else {
|
||||
sprintf(tmp, "%s/%s/%s", config.data_dir, artist_name, website_name);
|
||||
args[0] = "gallery-dl";
|
||||
args[1] = "--config";
|
||||
args[2] = config.gallery_dl_conf;
|
||||
args[3] = "--directory";
|
||||
args[4] = tmp;
|
||||
args[5] = url;
|
||||
}
|
||||
args[6] = NULL;
|
||||
|
||||
printf("Starting download using %s\n", args[0]);
|
||||
size_t i;
|
||||
for (i = 5; i > 0; i--) {
|
||||
/* Keep for later debugging or logging
|
||||
size_t j;
|
||||
for (j = 0; args[j] != NULL; j++) {
|
||||
printf("args[%d] = %s\n", j, args[j]);
|
||||
}
|
||||
*/
|
||||
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == -1) {
|
||||
printf("Couldn't fork'\n");
|
||||
return 1;
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &ret, 0);
|
||||
} else {
|
||||
execvp(args[0], args);
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Command exited with non-zero code. code = %d\n", ret);
|
||||
|
||||
}
|
||||
free(url);
|
||||
free(artist_name);
|
||||
free(website_name);
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int ret;
|
||||
Config config = { 0 };
|
||||
|
||||
Reference in New Issue
Block a user