shell-scripte-code/youtube.sh

99 lines
2.2 KiB
Bash
Raw Normal View History

2019-01-07 20:23:02 +01:00
#!/usr/bin/env bash
2017-06-06 21:17:36 +02:00
2021-08-30 22:36:00 +02:00
set -ex
2017-06-06 21:17:36 +02:00
2025-04-26 19:38:09 +02:00
if [ "$1" == "--help" ]; then
echo "Usage: $0 [URL] [FORMAT] [EXTRA]"
echo "Formate: opus/flac/m4a/mp4/video/hd/fullhd/4k/bestaudio"
echo "Beispiel für Unterordner: -o '%(channel)s/%(playlist_title)s/%(title)s.%(ext)s'"
2017-11-17 21:24:15 +01:00
exit 0
2017-06-06 21:34:54 +02:00
fi
2017-07-15 08:19:35 +02:00
2022-03-30 18:50:35 +02:00
url="$1"
format="$2"
2023-12-11 00:33:34 +01:00
extra="$3"
2017-09-23 17:30:59 +02:00
2025-04-26 19:38:09 +02:00
# Abfragen für interaktive Eingaben
[[ -z "${url}" ]] && read -p "URL: " url
2025-04-23 08:28:51 +02:00
[[ -z "${format}" ]] && read -p "Format [opus/flac/m4a/mp4/video/hd/fullhd/4k/bestaudio]: " format
2025-04-26 19:38:09 +02:00
# Abfrage für Various Artists
read -p "Album als Playlist Title setzen? [Y/n] " title
if [[ "$title" != "n" ]]; then
album_metadata="--parse-metadata playlist_title:%(album)s"
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
2023-05-08 10:10:34 +02:00
2025-04-26 19:38:09 +02:00
# 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"
2017-06-06 21:17:36 +02:00
fi
2025-04-26 19:38:09 +02:00
# 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
2025-04-26 18:58:26 +02:00
yt-dlp \
-i \
-c \
--socket-timeout 10000 \
--force-ipv4 \
--restrict-filenames \
--embed-thumbnail \
--embed-metadata \
2025-04-26 19:38:09 +02:00
$album_metadata \
$cookies_cmd \
${output_template} \
2025-04-26 18:58:26 +02:00
--match-filter "!was_live" \
2025-04-26 19:38:09 +02:00
$format_cmd \
$audio \
$quality \
2025-04-26 18:58:26 +02:00
-v \
2025-04-26 19:38:09 +02:00
"$url" \
2025-04-26 18:58:26 +02:00
${extra}