Created
October 3, 2023 11:05
-
-
Save laerreal/a1a67a471e711ea9c8739db5c32e471a to your computer and use it in GitHub Desktop.
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 | |
StartDir=$(pwd) | |
ScriptName=$(realpath "$0") | |
ScriptDir=$(dirname "$ScriptName") | |
if ! [ -d "$ScriptDir/youtube-dl" ] ; then | |
echo "Downloading youtube-dl to $ScriptDir" | |
cd "$ScriptDir" | |
if ! git clone https://github.com/ytdl-org/youtube-dl.git ; then | |
exit 1 | |
fi | |
cd "$StartDir" | |
fi | |
BidDir=$(cd "$ScriptDir/youtube-dl/bin" && pwd) | |
export PYTHONPATH=$(cd "$ScriptDir/youtube-dl" && pwd) | |
export PATH="$BidDir:$PATH" | |
if ! $(which AtomicParsley) ; then | |
echo "sudo apt install atomicparsley" | |
if ! sudo apt install atomicparsley ; then | |
exit 1 | |
fi | |
fi | |
Scale=1 | |
for Arg in "$@" ; do | |
# echo "'$Arg'" | |
if [ "$Arg" == --help ] || [ "$Arg" == -h ] ; then | |
youtube-dl --help | |
exit 0 | |
elif [[ "$Arg" =~ ^-[1-9][0-9]*$ ]] ; then | |
Scale=${Arg:1} | |
else | |
YTDLArgs+=("$Arg") | |
fi | |
done | |
ResNameContainer=$(mktemp /tmp/ytdl.XXXXXX) | |
youtube-dl \ | |
--ignore-errors \ | |
--all-subs \ | |
--embed-subs \ | |
--embed-thumbnail \ | |
--add-metadata \ | |
--verbose \ | |
--geo-bypass \ | |
-o "%(playlist_index)s-%(title)s.%(ext)s" \ | |
--format 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' \ | |
--exec "echo {} > $ResNameContainer" \ | |
"${YTDLArgs[@]}" \ | |
; | |
ResName=$(cat "$ResNameContainer") | |
rm "$ResNameContainer" | |
if [ $Scale != 1 ] ; then | |
ScaledResName="s${Scale}_${ResName}" | |
ffmpeg \ | |
-i "$ResName" \ | |
-vf scale="iw/$Scale:ih/$Scale" \ | |
-y \ | |
"$ScaledResName" \ | |
; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment