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

View File

@ -1,8 +1,8 @@
{
"layer": "top",
"modules-left": ["river/tags"],
"modules-center": ["clock", ],
"modules-right": ["custom/events", "custom/media", "custom/wireguard", "custom/archupdates", "pulseaudio", "backlight", "network", "cpu", "memory", "temperature", "battery", "tray"],
"modules-left": ["river/tags", "custom/events", "custom/vidl"],
"modules-center": ["clock", "custom/media"],
"modules-right": ["custom/wireguard", "custom/archupdates", "pulseaudio", "backlight", "network", "cpu", "memory", "temperature", "battery", "tray"],
"custom/archupdates": {
"format": "{} {icon}",
"format-alt-click": "right",
@ -166,5 +166,16 @@
"return-type": "json",
"signal": 6,
"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-wireguard,
#custom-events,
#custom-vidl,
#custom-media {
padding: 0 10px;
margin: 0 5px;