renew script

This commit is contained in:
Simon Rieger 2025-04-26 19:38:09 +02:00
parent 3e06ca7217
commit e20e489488

View file

@ -2,11 +2,10 @@
set -ex set -ex
if [ "$1" == "--help" ] if [ "$1" == "--help" ]; then
then echo "Usage: $0 [URL] [FORMAT] [EXTRA]"
echo "bash ./youtube-dl.sh URL FORMAT" echo "Formate: opus/flac/m4a/mp4/video/hd/fullhd/4k/bestaudio"
echo "Formate: [opus/m4a/video/hd/fullhd/4k/bestaudio]" echo "Beispiel für Unterordner: -o '%(channel)s/%(playlist_title)s/%(title)s.%(ext)s'"
echo "Extra: (Zusätzliche Parameter)"
exit 0 exit 0
fi fi
@ -14,55 +13,71 @@ url="$1"
format="$2" format="$2"
extra="$3" extra="$3"
# Abfragen für interaktive Eingaben
[[ -z "${url}" ]] && read -p "URL: " url [[ -z "${url}" ]] && read -p "URL: " url
[[ -z "${format}" ]] && read -p "Format [opus/flac/m4a/mp4/video/hd/fullhd/4k/bestaudio]: " format [[ -z "${format}" ]] && read -p "Format [opus/flac/m4a/mp4/video/hd/fullhd/4k/bestaudio]: " format
echo "Wenn man für alle Playlisten Unterordner anlegen will: [-o %(channel)s/%(playlist_title)s/%(title)s.%(ext)s/--cookies cookies.txt/--cookies-from-browser firefox] (Praktisch für Downloads ganzer Kanäle"
[[ -z "${extra}" ]] && read -p "Sind noch zusätzliche Parameter gewünscht?: " extra
if [ "$format" == "opus" ] # Abfrage für Various Artists
then read -p "Album als Playlist Title setzen? [Y/n] " title
# https://github.com/yt-dlp/yt-dlp/issues/979 if [[ "$title" != "n" ]]; then
format="--audio-format opus -f "ba" --format-sort "abr,codec"" album_metadata="--parse-metadata playlist_title:%(album)s"
audio="-x"
quality="--audio-quality 0"
elif [ "$format" == "flac" ]
then
format="--audio-format flac -f "ba" --format-sort "abr,codec""
audio="-x"
quality="--audio-quality 0"
elif [ "$format" == "m4a" ]
then
format="--audio-format m4a"
audio="-x"
elif [ "$format" == "mp4" ]
then
format="--audio-format mp4"
audio="-x"
elif [ "$format" == "video" ]
then
# Download and merge the best video-only format and the best audio-only format,
# or download the best combined format if video-only format is not available
# Download the best video available with the largest resolution but no better than 480p,
# or the best video with the smallest resolution if there is no video under 480p
# Resolution is determined by using the smallest dimension.
# So this works correctly for vertical videos as well
format="-S "res:480" -f "bv+ba/b""
elif [ "$format" == "hd" ]
then
format="-S "res:720" -f "bv+ba/b""
elif [ "$format" == "fullhd" ]
then
format="-S "res:1080" -f "bv+ba/b""
elif [ "$format" == "4k" ]
then
format="-S "res:2160" -f "bv+ba/b""
elif [ "$format" == "bestaudio" ]
then
# Lädt das beste Audioformat OHNE Umwandlung (z.B. Opus/WebM oder AAC/M4A)
format="-f bestaudio"
fi fi
# Abfrage für Cookies
read -p "Cookies aus cookies.txt verwenden? [Y/n] " cookies
if [[ "$cookies" != "n" ]]; then
cookies_cmd="--cookies cookies.txt"
fi
# Abfrage für Unterordner-Struktur
read -p "Unterordner nach Kanal erstellen? [Y/n] " folders
if [[ "$folders" != "n" ]]; then
output_template="-o %(channel)s/%(title)s.%(ext)s"
fi
# Format-Spezifikationen
case "$format" in
opus)
format_cmd="-f ba --audio-format opus --format-sort abr,codec"
audio="-x"
quality="--audio-quality 0"
;;
flac)
format_cmd="-f ba --audio-format flac --format-sort abr,codec"
audio="-x"
quality="--audio-quality 0"
;;
m4a)
format_cmd="--audio-format m4a"
audio="-x"
;;
mp4)
format_cmd="--audio-format mp4"
audio="-x"
;;
video)
format_cmd="-S res:480 -f bv+ba/b"
;;
hd)
format_cmd="-S res:720 -f bv+ba/b"
;;
fullhd)
format_cmd="-S res:1080 -f bv+ba/b"
;;
4k)
format_cmd="-S res:2160 -f bv+ba/b"
;;
bestaudio)
format_cmd="-f bestaudio"
;;
*)
format_cmd=""
audio=""
quality=""
;;
esac
# Hauptbefehl mit allen Optionen
yt-dlp \ yt-dlp \
-i \ -i \
-c \ -c \
@ -71,11 +86,13 @@ yt-dlp \
--restrict-filenames \ --restrict-filenames \
--embed-thumbnail \ --embed-thumbnail \
--embed-metadata \ --embed-metadata \
--parse-metadata "playlist_title:%(album)s" \ $album_metadata \
$cookies_cmd \
${output_template} \
--match-filter "!was_live" \ --match-filter "!was_live" \
${format} \ $format_cmd \
${audio} \ $audio \
${quality} \ $quality \
-v \ -v \
${url} \ "$url" \
${extra} ${extra}