Compare commits

..

3 Commits

Author SHA1 Message Date
b8197d7678 forgot the shell scripts 2025-05-28 20:20:26 +02:00
92b65aacc6 switch to libstrops and execlp 2025-05-28 20:16:24 +02:00
e0756a714d Portable Makefile 2025-05-28 20:15:56 +02:00
2 changed files with 32 additions and 35 deletions

View File

@ -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

View File

@ -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];