scripts: Add queue to vidl

Added queuing to vidl downloader - will collect newly added files to
download to a queue.
(by default in ($XDG_DATA_HOME/ or ~/.local/share)/vidl/vidl_queue)

The queue of links can be interacted with like any other file.

When vidl is already running it keeps a lock-file active in .cache
directory so only one instance of vidl can ever be running
simultaneously.
This commit is contained in:
Marty Oehme 2022-04-11 12:48:21 +02:00
parent 2c7430121e
commit 50a5b23aab
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 43 additions and 15 deletions

View file

@ -4,7 +4,6 @@
show_help() { show_help() {
printf """ printf """
archive.sh: Hard linking your stuff.
vidl: Video downloader vidl: Video downloader
Simple wrapper for youtube-dl (or yt-dlp or similar). Simple wrapper for youtube-dl (or yt-dlp or similar).
@ -24,6 +23,8 @@ Options:
-c Clear existing download queue. -c Clear existing download queue.
-p Print out number of remaining items in 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. youtube-dl program.
@ -32,7 +33,7 @@ Options:
urls=("$@") urls=("$@")
while getopts "t:f:d:hc" opt; do while getopts "t:f:d:hcp" opt; do
case "$opt" in case "$opt" in
# v) verbose=1 # v) verbose=1
# ;; # ;;
@ -48,6 +49,9 @@ while getopts "t:f:d:hc" opt; do
c) c)
ONLY_DO=clear ONLY_DO=clear
;; ;;
p)
ONLY_DO=remaining
;;
h | \? | *) h | \? | *)
show_help show_help
exit 0 exit 0
@ -122,12 +126,13 @@ setup() {
declare -a YT_DL_OPTS=${YT_DL_OPTS:-( "${yt_default_opts[@]}" )} 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 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" data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/vidl"
if [ ! -f "$queue_file" ]; then cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/vidl"
mkdir -p $(dirname "$queue_file") [ ! -d "$data_dir" ] && mkdir -p "$data_dir"
touch "$queue_file" [ ! -d "$cache_dir" ] && mkdir -p "$cache_dir"
fi
lock_dir="${XDG_CACHE_HOME:-$HOME/.cache}/vidl_lock" queue_file="${data_dir}/vidl_queue"
lock_file="${cache_dir}/vidl_lock"
} }
is_in_queue() { # 1=url is_in_queue() { # 1=url
@ -150,14 +155,14 @@ clear_queue() {
} }
remove_lock() { remove_lock() {
if ! rmdir $lock_dir; then if ! rmdir "$lock_file"; then
echo "Failed to remove lock '$lock_dir'. Please remove manually before next run." echo "Failed to remove lock '$lock_file'. Please remove manually before next run."
exit 1 exit 1
fi fi
} }
is_only_instance() { is_only_instance() {
if mkdir $lock_dir 2>/dev/null; then if mkdir "$lock_file" 2>/dev/null; then
trap "remove_lock" EXIT trap "remove_lock" EXIT
return 0 return 0
else else
@ -165,11 +170,22 @@ is_only_instance() {
fi fi
} }
print_queue_remaining() {
if [ ! -f "$queue_file" ]; then
echo 0
return
fi
wc -l "$queue_file" | cut -f1 -d' '
}
main() { main() {
setup setup
if [ "$ONLY_DO" = "clear" ]; then if [ "$ONLY_DO" = "clear" ]; then
clear_queue clear_queue
exit exit
elif [ "$ONLY_DO" = "remaining" ]; then
print_queue_remaining
exit
fi fi
for url in $*; do for url in $*; do

View file

@ -1,8 +1,8 @@
{ {
"layer": "top", "layer": "top",
"modules-left": ["river/tags"], "modules-left": ["river/tags", "custom/events", "custom/vidl"],
"modules-center": ["clock", ], "modules-center": ["clock", "custom/media"],
"modules-right": ["custom/events", "custom/media", "custom/wireguard", "custom/archupdates", "pulseaudio", "backlight", "network", "cpu", "memory", "temperature", "battery", "tray"], "modules-right": ["custom/wireguard", "custom/archupdates", "pulseaudio", "backlight", "network", "cpu", "memory", "temperature", "battery", "tray"],
"custom/archupdates": { "custom/archupdates": {
"format": "{} {icon}", "format": "{} {icon}",
"format-alt-click": "right", "format-alt-click": "right",
@ -166,5 +166,16 @@
"return-type": "json", "return-type": "json",
"signal": 6, "signal": 6,
"interval": 60, "interval": 60,
} },
"custom/vidl": {
"format": "{} {icon}",
"format-alt-click": "right",
"format-icons": {
"default": ""
},
"exec": "wc -l ~/.local/share/vidl/vidl_queue | cut -d' ' -f1",
"exec-if": "[ -f ~/.local/share/vidl/vidl_queue ]",
"interval": 5,
"on-click": "kitty --class float nvim ~/.local/share/vidl/vidl_queue"
},
} }

View file

@ -60,6 +60,7 @@ window#waybar.hidden {
#custom-archupdates, #custom-archupdates,
#custom-wireguard, #custom-wireguard,
#custom-events, #custom-events,
#custom-vidl,
#custom-media { #custom-media {
padding: 0 10px; padding: 0 10px;
margin: 0 5px; margin: 0 5px;