From dfcdfa24ce412771a27fc610bd087ad50ebed6fc Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Tue, 27 May 2025 00:15:12 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 ++ Makefile | 2 ++ move_audio.sh | 23 +++++++++++++ move_video.sh | 24 +++++++++++++ yt-dlp_audio.conf | 25 ++++++++++++++ yt-dlp_video.conf | 41 ++++++++++++++++++++++ yt_download.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 204 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100755 move_audio.sh create mode 100755 move_video.sh create mode 100644 yt-dlp_audio.conf create mode 100644 yt-dlp_video.conf create mode 100644 yt_download.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b10021 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +yt_download +ytdlp-honey.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7f471e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +yt_download: + gcc -ansi -I . -L. -ggdb -o yt_download yt_download.c -Wl,-Bstatic -lstrops -Wl,-Bdynamic diff --git a/move_audio.sh b/move_audio.sh new file mode 100755 index 0000000..f311a35 --- /dev/null +++ b/move_audio.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +[[ -z $1 ]] && echo 'No arguments specified' && exit 1 + +if [[ -d $1 ]]; then + cd "$1" +else + echo 'Specified path does not exist' && exit 1 +fi + +folders=("audio" "thumbnails" "metadata" "descriptions") + +for folder in "${folders[@]}"; do + [[ ! -d $folder ]] && mkdir "$folder" +done + +mv *.opus audio > /dev/null 2>&1 +mv *.jpg thumbnails > /dev/null 2>&1 +mv *.jpeg thumbnails > /dev/null 2>&1 +mv *.png thumbnails > /dev/null 2>&1 +mv *.webp thumbnails > /dev/null 2>&1 +mv *.info.json metadata > /dev/null 2>&1 +mv *.description descriptions > /dev/null 2>&1 \ No newline at end of file diff --git a/move_video.sh b/move_video.sh new file mode 100755 index 0000000..45bdbe5 --- /dev/null +++ b/move_video.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +[[ -z $1 ]] && echo 'No arguments specified' && exit 1 + +if [[ -d $1 ]]; then + cd "$1" +else + echo 'Specified path does not exist' && exit 1 +fi + +folders=("video" "thumbnails" "metadata" "descriptions" "subs") + +for folder in "${folders[@]}"; do + [[ ! -d $folder ]] && mkdir "$folder" +done + +mv *.mkv video +mv *.jpg thumbnails +mv *.jpeg thumbnails +mv *.png thumbnails +mv *.webp thumbnails +mv *.info.json metadata +mv *.description descriptions +mv *.vtt subs diff --git a/yt-dlp_audio.conf b/yt-dlp_audio.conf new file mode 100644 index 0000000..34ee83a --- /dev/null +++ b/yt-dlp_audio.conf @@ -0,0 +1,25 @@ +# Uses best audio +-f bestaudio + +# Extracts the audio +--extract-audio + +# Uses best quality +--audio-quality 0 + +# opus is the best you can get from youtube +--audio-format opus + +# Concurrent download of fragments +--concurrent-fragments 8 + +# Cache +--cache-dir /tmp/yt-dlp/cache + +# Cookies +--cookies /mnt/youtube/cookies.txt + +# Chill out +--sleep-requests 1.25 +--min-sleep-interval 60 +--max-sleep-interval 90 diff --git a/yt-dlp_video.conf b/yt-dlp_video.conf new file mode 100644 index 0000000..4113aef --- /dev/null +++ b/yt-dlp_video.conf @@ -0,0 +1,41 @@ +# best video and audio +-f bestvideo+bestaudio + +# Thumbnail +--write-thumbnail +--embed-thumbnail + +# Add chapters +--embed-chapters + +# Embed info json +--write-info-json +--embed-info-json + +# Metadata +--embed-metadata + +# Description +--write-description + +# Subtitles +--sub-langs en.* +--write-subs +--embed-subs + +# Concurrent download of fragments +--concurrent-fragments 8 + +# Cache +--cache-dir /tmp/yt-dlp/cache + +# Cookies +--cookies /mnt/youtube/cookies.txt + +# Merge downloaded video and audio into a mkv file +--merge-output-format mkv + +# Chill out +--sleep-requests 1.25 +--min-sleep-interval 60 +--max-sleep-interval 90 diff --git a/yt_download.c b/yt_download.c new file mode 100644 index 0000000..b42684b --- /dev/null +++ b/yt_download.c @@ -0,0 +1,87 @@ +#include +#include +#include + +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; + + int 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); + } + free(buf); + + return ret; +} + +int main(int argc, char **argv) { + if (argc != 4) { + fprintf(stderr, "Incorred amount of arguments\n"); + } + char *path; + char *url; + char is_audio; + size_t i; + for (i = 1; i < 4; i++) { + if (argv[i][0] == '-') { + if (strcmp(argv[i], "-audio") == 0) { + is_audio = 1; + } else if (strcmp(argv[i], "-video") == 0) { + is_audio = 0; + } else { + fprintf(stderr, "Invalid option: %s\n", argv[i]); + return 1; + } + } else if (strstr(argv[i], "https://")) { + url = argv[i]; + } else { + path = argv[i]; + } + } + if (!path) { + fprintf(stderr, "No path specified\n"); + return 1; + } + if (!url) { + fprintf(stderr, "No valid url specified\n"); + return 1; + } + + int ret; + ret = download(path, url, is_audio); + if (ret != 0) { + fprintf(stderr, "Download Failed\n"); + return 1; + } + return 0; +} +