summaryrefslogtreecommitdiff
path: root/ar/.local/bin/statusbar/sb-queues
diff options
context:
space:
mode:
Diffstat (limited to 'ar/.local/bin/statusbar/sb-queues')
-rwxr-xr-xar/.local/bin/statusbar/sb-queues40
1 files changed, 40 insertions, 0 deletions
diff --git a/ar/.local/bin/statusbar/sb-queues b/ar/.local/bin/statusbar/sb-queues
new file mode 100755
index 0000000..7cd48a7
--- /dev/null
+++ b/ar/.local/bin/statusbar/sb-queues
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+notify_filenames() {
+ while IFS= read -r line; do
+ id=$(echo "$line" | awk '{print $1}')
+ url=$(tsp -l | awk -v id="$id" 'flag && /notify-send/ {print $0; flag=0} $1 == id {flag=1}' | grep -o 'https://[^\"]*')
+ if [ -n "$url" ]; then
+ decoded_url=$(echo "$url" | sed 's/&/\&/g')
+ yt-dlp --no-playlist --simulate --get-filename "$decoded_url" 2>/dev/null | while IFS= read -r filename; do
+ notify-send "๐Ÿ”ฝ Downloading:" "$filename"
+ done
+ else
+ notify-send "๐Ÿชน No URL extracted for task $id"
+ fi
+ done <<EOF
+$(tsp -l | awk '/running/ && /yt-dlp/')
+EOF
+ if [ -z "$url" ]; then
+ notify-send "๐Ÿ’ค No active yt-dlp downloads"
+ fi
+ pkill -RTMIN+21 "${STATUSBAR:-dwmblocks}"
+}
+
+# This block displays the number of running and queued background tasks. Requires tsp.
+num=$(tsp -l | awk -v numr=0 -v numq=0 '{if (!/notify-send/ && /running/) numr++; if (!/notify-send/ && /queued/) numq++} END{print numr"|"numq}')
+
+# Handle mouse clicks
+case $BLOCK_BUTTON in
+1) setsid -f "$TERMINAL" -e sh -c 'tsp -l; echo "\nPress enter to close..." ; read REPLY' ;;
+2) setsid -f "$TERMINAL" -e sh -c 'tsp -t' ;;
+3)
+ notify_filenames
+ notify-send "๐Ÿ“ Tasks module" "๐Ÿค–: number of running/queued background tasks
+- Left click to show all tasks
+- Middle click to show the current task progress"
+ ;;
+6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+cat /tmp/qplaylist 2>/dev/null || ([ "$num" != "0|0" ] && echo "๐Ÿค–$num")