Last active
October 17, 2022 20:33
-
-
Save goncalomb/eda8a47d199c35eee9fc7426ef5782be to your computer and use it in GitHub Desktop.
Another YouTube downloader script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2021 Gonçalo Baltazar <[email protected]> | |
# MIT License | |
# pip3 install --upgrade youtube-dl | |
# ffmpeg -y -loglevel repeat+info -i file:video.xyz -i file:audio.xyz -c copy -map 0:v:0 -map 1:a:0 file:out.mkv | |
set -eo pipefail | |
cd -- "$(dirname -- "$0")" | |
VERSION=2.0 | |
now() { | |
date +%s.%N | |
} | |
ytdl() { | |
yt-dlp \ | |
--no-continue \ | |
--write-description \ | |
--write-info-json \ | |
--write-annotations \ | |
--write-thumbnail \ | |
--write-all-thumbnails \ | |
--all-subs \ | |
--write-sub \ | |
--write-pages \ | |
--playlist-reverse \ | |
-o '%(id)s.%(ext)s' \ | |
-f bestvideo+bestaudio/best \ | |
--keep-video \ | |
-i \ | |
-v \ | |
"$@" | |
} | |
dl_single() { | |
SVC=$1 | |
ARC_NAME=$2 | |
ID=$3 | |
URL=$4 | |
CMD=$5 | |
if [ -f "data/archive.txt" ] && grep -F "$ARC_NAME" "data/archive.txt" > /dev/null; then | |
echo "$ID already in the archive" | |
return | |
fi | |
START=$(now) | |
RUN_DIR="data/$SVC/single/$ID.$START" | |
mkdir -p "$RUN_DIR" | |
( | |
cd "$RUN_DIR" | |
end() { | |
now > end | |
echo end | |
} | |
trap end EXIT | |
echo "$VERSION" > version | |
"$CMD" --download-archive "../../../archive.txt" "$URL" 2>&1 | tee -i log.txt | |
) | |
} | |
youtube_single() { | |
dl_single youtube "youtube $1" "$1" "https://www.youtube.com/watch?v=$1" ytdl | |
} | |
twitch_single() { | |
dl_single twitch "twitchvod v$1" "$1" "https://www.twitch.tv/videos/$1" ytdl | |
} | |
if [ "$1" == "youtube-single" ]; then | |
youtube_single "$2" | |
elif [ "$1" == "twitch-single" ]; then | |
twitch_single "$2" | |
else | |
echo "youtube-single,twitch-single?" | |
exit 1 | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment