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
|
|
|
|
2022-04-28 11:14:26 +02:00
|
|
|
if [ "$1" == "--help" ]
|
2017-06-06 21:34:54 +02:00
|
|
|
then
|
2022-03-30 18:50:35 +02:00
|
|
|
echo "bash ./youtube-dl.sh URL FORMAT"
|
|
|
|
echo "Formate: [opus/m4a/video/hd/fullhd/4k]"
|
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"
|
2017-09-23 17:30:59 +02:00
|
|
|
|
2022-04-28 11:14:26 +02:00
|
|
|
[[ -z "${url}" ]] && read -p "URL: " url
|
2023-05-08 10:10:34 +02:00
|
|
|
[[ -z "${format}" ]] && read -p "Format [opus/flac/m4a/mp4/video/hd/fullhd/4k]: " format
|
2022-04-28 11:14:26 +02:00
|
|
|
|
2017-06-06 21:17:36 +02:00
|
|
|
if [ "$format" == "opus" ]
|
|
|
|
then
|
2023-05-08 10:10:34 +02:00
|
|
|
# https://github.com/yt-dlp/yt-dlp/issues/979
|
|
|
|
format="--audio-format opus -f "ba" --format-sort "abr,codec""
|
2022-03-30 18:50:35 +02:00
|
|
|
audio="-x"
|
|
|
|
quality="--audio-quality 0"
|
2022-07-06 19:11:59 +02:00
|
|
|
elif [ "$format" == "flac" ]
|
2022-07-06 18:59:56 +02:00
|
|
|
then
|
2023-05-08 10:10:34 +02:00
|
|
|
format="--audio-format flac -f "ba" --format-sort "abr,codec""
|
2022-07-06 18:59:56 +02:00
|
|
|
audio="-x"
|
|
|
|
quality="--audio-quality 0"
|
|
|
|
elif [ "$format" == "m4a" ]
|
2017-06-06 21:17:36 +02:00
|
|
|
then
|
2022-03-30 18:50:35 +02:00
|
|
|
format="--audio-format m4a"
|
|
|
|
audio="-x"
|
|
|
|
elif [ "$format" == "mp4" ]
|
|
|
|
then
|
|
|
|
format="--audio-format mp4"
|
|
|
|
audio="-x"
|
2017-06-06 21:17:36 +02:00
|
|
|
elif [ "$format" == "video" ]
|
|
|
|
then
|
2023-05-08 10:10:34 +02:00
|
|
|
# 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""
|
2017-09-23 17:10:53 +02:00
|
|
|
elif [ "$format" == "hd" ]
|
|
|
|
then
|
2023-05-08 10:10:34 +02:00
|
|
|
format="-S "res:720" -f "bv+ba/b""
|
2017-09-23 17:10:53 +02:00
|
|
|
elif [ "$format" == "fullhd" ]
|
2017-07-15 08:19:35 +02:00
|
|
|
then
|
2023-05-08 10:10:34 +02:00
|
|
|
format="-S "res:1080" -f "bv+ba/b""
|
2017-09-23 17:10:53 +02:00
|
|
|
elif [ "$format" == "4k" ]
|
|
|
|
then
|
2023-05-08 10:10:34 +02:00
|
|
|
format="-S "res:2160" -f "bv+ba/b""
|
2017-06-06 21:17:36 +02:00
|
|
|
fi
|
|
|
|
|
2022-11-23 06:51:30 +01:00
|
|
|
yt-dlp -i -c --socket-timeout 10000 --force-ipv4 --restrict-filenames --embed-thumbnail --embed-metadata --match-filter "!was_live" $format $audio $quality -v $url
|