Use yt-dlp if available, allow to set preferred binary.

This commit is contained in:
tastytea 2021-10-25 04:42:16 +02:00
parent f9e62efe73
commit 88190ad14a
2 changed files with 12 additions and 3 deletions

View File

@ -6,7 +6,8 @@
Download YouTube-feeds as if they are podcasts. Files will be put in
`<download_dir>/uploader/title.extension`.
This should work for all sites `youtube-dl` supports, but I only tested YouTube.
This should work for all sites `youtube-dl` supports, but I only tested
YouTube. `yt-dlp` will be preferred if available.
== Features
@ -50,6 +51,7 @@ ytdl_extra_args="--quiet"
| *ytdl_format* | Same syntax as link:{url-ytdl-format}[youtube-dl --format]. Default is "best".
| *max_videos* | Maximum number of videos to consider per feed. Default is to consider all.
| *ytdl_extra_args* | Extra arguments for `youtube-dl`. Optional.
| *ytdl_binary* | Binary to use instead of `yt-dlp` or `youtube-dl`.
|===============================================================================
[WARNING]

View File

@ -55,6 +55,13 @@ function main()
[[ -z "${keep_for_days}" ]] && die 2 "keep_for_days not specified."
[[ -z "${ytdl_format}" ]] && local ytdl_format="best"
[[ -z "${max_videos}" ]] && local max_videos="last"
if [[ -z "${ytdl_binary}" ]]; then
if command -v yt-dlp > /dev/null; then
local ytdl_binary="yt-dlp"
else
local ytdl_binary="youtube-dl"
fi
fi
find "${download_dir}" -type f -mtime +"${keep_for_days}" -delete
find "${download_dir}" -maxdepth 1 -type d -exec \
@ -64,7 +71,7 @@ function main()
local files_before="$(find "${download_dir}" -type f)"
local -a feedlist=("${(@Q)${(z)$(read_feedlist)}}")
for feed in ${feedlist}; do
youtube-dl \
${ytdl_binary} \
--download-archive "$(get_config_path)/downloaded" \
--dateafter "now-${keep_for_days}days" \
--output "${download_dir}/%(uploader)s/%(title)s.%(ext)s" \
@ -72,7 +79,7 @@ function main()
--playlist-end "${max_videos}" \
${=ytdl_extra_args} \
"${feed}"
# [[ ${?} -eq 0 ]] || die 3 "youtube-dl returned an error."
# [[ ${?} -eq 0 ]] || die 3 "${ytdl_binary} returned an error."
done
local files_after="$(find "${download_dir}" -type f)"
local time="$(date +'%F_%R')"