summaryrefslogtreecommitdiff
path: root/ar/.local/bin/statusbar/sb-queues
blob: e0ddefd5487fa1b1cc2d2e00c99be683b6540fa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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"|"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")