switch to libstrops and execlp
This commit is contained in:
@ -1,32 +1,12 @@
|
||||
#include <strops.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int download(char *path, char *url, char is_audio) {
|
||||
int ret;
|
||||
char *args[10];
|
||||
args[0] = "yt-dlp";
|
||||
args[1] = "--config-locations";
|
||||
if (is_audio) {
|
||||
args[2] = "/mnt/youtube/yt-dlp_audio.conf";
|
||||
} else {
|
||||
args[2] = "/mnt/youtube/yt-dlp_video.conf";
|
||||
}
|
||||
args[3] = "--download-archive";
|
||||
if (is_audio) {
|
||||
char *buf = malloc(strlen(path) + 1);
|
||||
sprintf(buf, "%s/downloaded_audio.txt", path);
|
||||
args[4] = buf;
|
||||
} else {
|
||||
char *buf = malloc(strlen(path) + 1);
|
||||
sprintf(buf, "%s/downloaded_video.txt", path);
|
||||
args[4] = buf;
|
||||
}
|
||||
args[5] = "--paths";
|
||||
args[6] = path;
|
||||
args[7] = "--yes-playlist";
|
||||
args[8] = url;
|
||||
args[9] = 0;
|
||||
char *downloaded = malloc(strops_length(path) + 1);
|
||||
is_audio ? sprintf(downloaded, "%s/downloaded_audio.txt", path)
|
||||
: sprintf(downloaded, "%s/downloaded_video.txt", path);
|
||||
|
||||
int pid = fork();
|
||||
|
||||
@ -36,32 +16,36 @@ int download(char *path, char *url, char is_audio) {
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &ret, 0);
|
||||
} else {
|
||||
execvp(args[0], args);
|
||||
execlp("yt-dlp", "yt-dlp",
|
||||
"--config-locations", is_audio ? "/mnt/youtube/yt-dlp_audio.conf" : "/mnt/youtube/yt-dlp_video.conf",
|
||||
"--download-archive", downloaded,
|
||||
"--paths", path,
|
||||
"--yes-playlist",
|
||||
url,
|
||||
NULL);
|
||||
}
|
||||
free(buf);
|
||||
|
||||
free(downloaded);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Incorred amount of arguments\n");
|
||||
return 1;
|
||||
}
|
||||
char *path;
|
||||
char *url;
|
||||
char is_audio;
|
||||
char *path, *url, is_audio;
|
||||
size_t i;
|
||||
for (i = 1; i < 4; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
if (strcmp(argv[i], "-audio") == 0) {
|
||||
if (strops_equals(argv[i], "-audio")) {
|
||||
is_audio = 1;
|
||||
} else if (strcmp(argv[i], "-video") == 0) {
|
||||
} else if (strops_equals(argv[i], "-video")) {
|
||||
is_audio = 0;
|
||||
} else {
|
||||
fprintf(stderr, "Invalid option: %s\n", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
} else if (strstr(argv[i], "https://")) {
|
||||
} else if (strops_starts_with(argv[i], "https://")) {
|
||||
url = argv[i];
|
||||
} else {
|
||||
path = argv[i];
|
||||
|
Reference in New Issue
Block a user