From 4c540496dd9b3452af2751727c6f99de2d5b3525 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 19 Dec 2022 16:55:22 +0100 Subject: [PATCH] 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). --- scripts/.local/bin/vidl | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/scripts/.local/bin/vidl b/scripts/.local/bin/vidl index bc1272d..9c51b86 100755 --- a/scripts/.local/bin/vidl +++ b/scripts/.local/bin/vidl @@ -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[@]}" )}