Compare commits
3 Commits
a81db2b8d1
...
main
Author | SHA1 | Date | |
---|---|---|---|
b8197d7678
|
|||
92b65aacc6
|
|||
e0756a714d
|
17
Makefile
17
Makefile
@ -1,2 +1,15 @@
|
||||
yt_download:
|
||||
gcc -ansi -I . -L. -ggdb -o yt_download yt_download.c -Wl,-Bstatic -lstrops -Wl,-Bdynamic
|
||||
.POSIX:
|
||||
yt_download: yt_download.c
|
||||
gcc -ansi -O2 -o yt_download yt_download.c -lstrops
|
||||
|
||||
.PHONY: install uninstall
|
||||
|
||||
install: yt_download move_audio.sh move_video.sh
|
||||
sudo mv yt_download /usr/local/bin
|
||||
sudo mv move_audio.sh /usr/local/bin
|
||||
sudo mv move_video.sh /usr/local/bin
|
||||
|
||||
uninstall:
|
||||
sudo rm /usr/local/bin/yt_download
|
||||
sudo rm /usr/local/bin/move_audio.sh
|
||||
sudo rm /usr/local/bin/move_video.sh
|
||||
|
@ -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