Compare commits
No commits in common. "3e00e84319b03180c145e2372de779d5797e2f56" and "27cbf30da0c8169de84e13678a2d450e57a4ace5" have entirely different histories.
3e00e84319
...
27cbf30da0
3 changed files with 43 additions and 129 deletions
|
@ -2,6 +2,13 @@
|
||||||
# download a file if it does not exist in the archive alread
|
# download a file if it does not exist in the archive alread
|
||||||
# otherwise just re-link it from the archive
|
# otherwise just re-link it from the archive
|
||||||
|
|
||||||
|
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[@]}" )}
|
||||||
|
YT_DL_TITLE="""${YT_DL_TITLE:-%(channel)s_%(title)s_%(id)s}"""
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
printf """
|
printf """
|
||||||
archive.sh: Hard linking your stuff.
|
archive.sh: Hard linking your stuff.
|
||||||
|
@ -15,24 +22,19 @@ Point it to a link you want downloaded.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
-h Display this help.
|
-h Display this help.
|
||||||
|
|
||||||
-d Directory to check for existence of file and archive to if needed.
|
-d Directory to check for existence of file and archive to if needed.
|
||||||
If this is passed will not download existing archived files again.
|
|
||||||
|
|
||||||
-f Directory to download to.
|
-f Directory to download to.
|
||||||
|
|
||||||
-c Clear existing download queue.
|
|
||||||
|
|
||||||
-t Point to youtube-dl command to use. Can be command or absolute link.
|
-t Point to youtube-dl command to use. Can be command or absolute link.
|
||||||
By default will use \`yt-dlp\` which is a more up to date fork of the
|
By default will use \`yt-dlp\` which is a more up to date fork of the
|
||||||
youtube-dl program.
|
program.
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
urls=("$@")
|
while getopts "t:f:d:h" opt; do
|
||||||
|
|
||||||
while getopts "t:f:d:hc" opt; do
|
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
# v) verbose=1
|
# v) verbose=1
|
||||||
# ;;
|
# ;;
|
||||||
|
@ -45,9 +47,6 @@ while getopts "t:f:d:hc" opt; do
|
||||||
d)
|
d)
|
||||||
ARCHIVE_FOLDER="$OPTARG"
|
ARCHIVE_FOLDER="$OPTARG"
|
||||||
;;
|
;;
|
||||||
c)
|
|
||||||
ONLY_DO=clear
|
|
||||||
;;
|
|
||||||
h | \? | *)
|
h | \? | *)
|
||||||
show_help
|
show_help
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -56,15 +55,7 @@ while getopts "t:f:d:hc" opt; do
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
get_ytdl_fname() {
|
_call_archive() {
|
||||||
yt_dl_fname=$("$YT_DL_CMD" --get-filename -o "$YT_DL_TITLE" "$*")
|
|
||||||
if [ -z "$yt_dl_fname" ]; then
|
|
||||||
echo Could not get video filename, error with youtube-dl.
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
_call_archive() { # 1=new_file, 2=archive_location
|
|
||||||
command -v archive >/dev/null 2>&1 || {
|
command -v archive >/dev/null 2>&1 || {
|
||||||
echo "archive command not found."
|
echo "archive command not found."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -73,119 +64,43 @@ _call_archive() { # 1=new_file, 2=archive_location
|
||||||
}
|
}
|
||||||
|
|
||||||
vid_ext="\(mp4\|avi\|webm\|mkv\|mpe?g\|3gp\|m4a\)"
|
vid_ext="\(mp4\|avi\|webm\|mkv\|mpe?g\|3gp\|m4a\)"
|
||||||
_findfile() { # 1=directory, 2=file
|
_findfile() {
|
||||||
find "$1" -type f -name "$2.*" | sed -ne "/$2\.$vid_ext$/Ip"
|
dir="$1"
|
||||||
|
fname="$2"
|
||||||
|
find "$dir" -type f -name "$fname.*" | sed -ne "/$fname\.$vid_ext$/Ip"
|
||||||
}
|
}
|
||||||
|
|
||||||
_alreadyexists() { # 1=video_regex
|
YT_DL_TITLE="%(channel)s_%(title)s_%(id)s"
|
||||||
if [ ! -d "$ARCHIVE_FOLDER" ]; then return 0; fi
|
_download() {
|
||||||
local found
|
|
||||||
found=$(_findfile "$ARCHIVE_FOLDER" "$1")
|
|
||||||
if [ -n "$found" ]; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
_download_cmd() {
|
|
||||||
"$YT_DL_CMD" \
|
"$YT_DL_CMD" \
|
||||||
-o "$DL_FOLDER/$YT_DL_TITLE.%(ext)s" \
|
-o "$DL_FOLDER/$YT_DL_TITLE.%(ext)s" \
|
||||||
"${YT_DL_OPTS[@]}" \
|
"${YT_DL_OPTS[@]}" \
|
||||||
"$*"
|
"$url"
|
||||||
}
|
}
|
||||||
|
|
||||||
download() { # 1=url
|
url="$*"
|
||||||
# # download the video to download folder
|
dl_fn=$("$YT_DL_CMD" --get-filename -o "$YT_DL_TITLE" "$url")
|
||||||
if ! _alreadyexists "$yt_dl_fname"; then
|
video_file_regex="${dl_fn}"
|
||||||
_download_cmd "$*"
|
|
||||||
|
|
||||||
# yt-dl never knows the exact filename in advance
|
if [ -z "$dl_fn" ]; then
|
||||||
file=$(_findfile "$DL_FOLDER" "$yt_dl_fname")
|
echo Could not get video filename, error with youtube-dl.
|
||||||
if [ -z "$file" ]; then exit 1; fi
|
exit 1
|
||||||
_call_archive "$file" "$ARCHIVE_FOLDER"
|
fi
|
||||||
# only link old file if one exists
|
|
||||||
else
|
|
||||||
archive_file=$(_findfile "$ARCHIVE_FOLDER" "$yt_dl_fname")
|
|
||||||
echo "$archive_file" | while read -r file; do
|
|
||||||
echo "file $file exists, not downloading duplicate"
|
|
||||||
_call_archive "$file" "$DL_FOLDER"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
setup() {
|
alreadyexists=$(_findfile "$ARCHIVE_FOLDER" "$video_file_regex")
|
||||||
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[@]}" )}
|
|
||||||
YT_DL_TITLE="${YT_DL_TITLE:-%(channel)s_%(title)s_%(id)s}" # this title needs to be without extension
|
|
||||||
|
|
||||||
queue_file="${XDG_CACHE_HOME:-$HOME/.cache}/vidl_queue"
|
# # download the video to download folder
|
||||||
if [ ! -f "$queue_file" ]; then
|
if [ "$alreadyexists" = "" ] || [ -z "$alreadyexists" ]; then
|
||||||
mkdir -p $(dirname "$queue_file")
|
_download
|
||||||
touch "$queue_file"
|
|
||||||
fi
|
|
||||||
lock_dir="${XDG_CACHE_HOME:-$HOME/.cache}/vidl_lock"
|
|
||||||
}
|
|
||||||
|
|
||||||
is_in_queue() { # 1=url
|
# yt-dl never knows the exact filename in advance
|
||||||
[ -f "$queue_file" ] || return 1
|
file=$(_findfile "$DL_FOLDER" "$video_file_regex")
|
||||||
grep -q "$1" "$queue_file"
|
if [ -z "$file" ]; then exit 1; fi
|
||||||
}
|
_call_archive "$file" "$ARCHIVE_FOLDER"
|
||||||
|
# only link old file if one exists
|
||||||
add_to_queue() { # 1=url
|
else
|
||||||
if is_in_queue "$1"; then return; fi
|
echo "$alreadyexists" | while read -r file; do
|
||||||
echo "$1" >>"$queue_file"
|
echo "file $file exists, not downloading duplicate"
|
||||||
echo "added $url to queue."
|
_call_archive "$file" "$DL_FOLDER"
|
||||||
}
|
|
||||||
|
|
||||||
remove_from_queue() { # 1=url
|
|
||||||
sed -i.bak -e "\|$1|d" "$queue_file"
|
|
||||||
}
|
|
||||||
|
|
||||||
clear_queue() {
|
|
||||||
rm "$queue_file"
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_lock() {
|
|
||||||
if ! rmdir $lock_dir; then
|
|
||||||
echo "Failed to remove lock '$lock_dir'. Please remove manually before next run."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
is_only_instance() {
|
|
||||||
if mkdir $lock_dir 2>/dev/null; then
|
|
||||||
trap "remove_lock" EXIT
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
setup
|
|
||||||
if [ "$ONLY_DO" = "clear" ]; then
|
|
||||||
clear_queue
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
for url in $*; do
|
|
||||||
add_to_queue "$url"
|
|
||||||
done
|
done
|
||||||
if is_only_instance; then
|
fi
|
||||||
echo "Download starting..."
|
|
||||||
while read -r line; do
|
|
||||||
get_ytdl_fname "$line"
|
|
||||||
download "$line"
|
|
||||||
remove_from_queue "$line"
|
|
||||||
done <"$queue_file"
|
|
||||||
else
|
|
||||||
echo "Download already running, only adding to queue."
|
|
||||||
fi
|
|
||||||
echo "Download done..."
|
|
||||||
}
|
|
||||||
|
|
||||||
main "${urls[@]}"
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
rename-window dot-git
|
rename-window dot-git
|
||||||
send-keys "cd ~/.dotfiles; while true; do [[ -z $(git status -s) ]] && { fd -t f --hidden | entr -cd tea issue ;} || { fd -t f --hidden | entr -cd git -c color.ui=always diff ;} ; done"
|
send-keys "cd ~/.dotfiles; while true; do fd -t f --hidden | entr -cd git -c color.ui=always diff; done" C-m
|
||||||
split-window -h "cd ~/.dotfiles; while true; do fd -t f --hidden --exclude .git/objects | entr -cd git -c color.ui=always status; done"
|
split-window -h "cd ~/.dotfiles; while true; do fd -t f --hidden --exclude .git/objects | entr -cd git -c color.ui=always status; done"
|
||||||
split-window -v
|
split-window -v
|
||||||
send-keys "cd ~/.dotfiles; clear" C-m L C-m
|
send-keys "cd ~/.dotfiles; clear" C-m L C-m
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
include colorscheme
|
|
||||||
|
|
||||||
set recolor "true"
|
set recolor "true"
|
||||||
set selection-clipboard "clipboard"
|
set selection-clipboard "clipboard"
|
||||||
|
|
||||||
|
@ -7,3 +5,4 @@ map r reload
|
||||||
map R rotate
|
map R rotate
|
||||||
map p print
|
map p print
|
||||||
|
|
||||||
|
include colorscheme
|
||||||
|
|
Loading…
Reference in a new issue