scripts: Fix vidl temporary directory

Lets vidl download to a temporary directory first (by default
~/downloads can be changed through "$TEMP_FOLDER") before moving
downloaded files to target directory as last step.

Massively increases download speed if final directory is on a slow HDD
or a network drive (since otherwise ffmpeg is computing on these slow
devices themselves).
This commit is contained in:
Marty Oehme 2022-12-19 16:55:22 +01:00
parent 3b7c24c676
commit 4c540496dd
Signed by: Marty
GPG key ID: 73BA40D5AFAF49C9

View file

@ -92,24 +92,36 @@ _alreadyexists() { # 1=video_regex
fi
}
_should_archive() {
if [ -n "$ARCHIVE_FOLDER" ]; then
return 0
else
return 1
fi
}
_download_cmd() {
"$YT_DL_CMD" \
-o "$DL_FOLDER/$YT_DL_TITLE.%(ext)s" \
-o "$TEMP_FOLDER/$YT_DL_TITLE.%(ext)s" \
"${YT_DL_OPTS[@]}" \
"$*"
}
download() { # 1=url
# # download the video to download folder
if ! _alreadyexists "$yt_dl_fname"; then
if ! _alreadyexists "$yt_dl_fname" || ! _should_archive; then
_download_cmd "$*"
file=$(_findfile "$TEMP_FOLDER" "$yt_dl_fname")
mv "$file" "$DL_FOLDER"
# yt-dl never knows the exact filename in advance
file=$(_findfile "$DL_FOLDER" "$yt_dl_fname")
if [ -z "$file" ]; then exit 1; fi
_call_archive "$file" "$ARCHIVE_FOLDER"
if _should_archive; then
# yt-dl never knows the exact filename in advance
file=$(_findfile "$DL_FOLDER" "$yt_dl_fname")
if [ -z "$file" ]; then exit 1; fi
_call_archive "$file" "$ARCHIVE_FOLDER"
fi
# only link old file if one exists
else
elif _should_archive; then
archive_file=$(_findfile "$ARCHIVE_FOLDER" "$yt_dl_fname")
echo "$archive_file" | while read -r file; do
echo "file $file exists, not downloading duplicate"
@ -119,8 +131,9 @@ download() { # 1=url
}
setup() {
DL_FOLDER="${DL_FOLDER:-${XDG_VIDEOS_DIR:-$HOME/videos}}/inbox"
ARCHIVE_FOLDER="${ARCHIVE_FOLDER:-${XDG_VIDEOS_DIR:-$HOME/videos}}/archive"
TEMP_FOLDER="${TEMP_FOLDER:-${HOME}/downloads}"
DL_FOLDER="${DL_FOLDER:-${XDG_VIDEOS_DIR:-$HOME/videos}/inbox}"
ARCHIVE_FOLDER="${ARCHIVE_FOLDER:-${XDG_VIDEOS_DIR:-$HOME/videos}/archive}"
YT_DL_CMD="${YT_DL_CMD:-yt-dlp}"
yt_default_opts=(-f "best[height\<=1080]" --retries 15 --embed-subs --sub-lang "en,de,es,fr")
declare -a YT_DL_OPTS=${YT_DL_OPTS:-( "${yt_default_opts[@]}" )}