aboutsummaryrefslogtreecommitdiff
path: root/xmonad/scripts/dmenu-vid.sh
blob: 8b5ec40f287b17f7019964b0cc053359f02f1e83 (about) (plain) (blame)
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
#!/bin/sh
set -eu
set -x

QUEUE="$HOME/archive/vid/queue.txt"
DB="$HOME/archive/vid/metadata-database.txt"

LIST="$(mktemp)"
touch "$DB"
while IFS='' read -r url; do
  MATCH="$(grep -F "$url" "$DB" ||:)"
  if [ -n "$MATCH" ]; then
    echo "$MATCH" >> "$LIST"
  else
    printf '%s - %s\n' "$(youtube-dl "$url" -o '%(title)s - %(uploader)s' --get-filename)" "$url" >> "$DB" &
    echo "$url" >> "$LIST"
  fi
done < "$QUEUE"

file_and_stuff="$(dmenu -l 20 -p 'Media: ' < "$LIST")"

if [ -n "$file_and_stuff" ]; then
  file="$(echo "$file_and_stuff" | awk -F' - ' '{print $NF}')"
  "$HOME/dev/libre/dotfiles/scripts/vid" "$file"
fi