aboutsummaryrefslogtreecommitdiff
path: root/scripts/vidrm
blob: dbdc6d49aeddd15e98be287dcb6584782a4e42a6 (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
26
27
28
29
30
#!/bin/sh
set -eu

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" || echo "$url")"
  echo "$MATCH" >> "$LIST"
done < "$QUEUE"

file_and_stuff="$(fzf < "$LIST")"

if [ -n "$file_and_stuff" ]; then
  file="$(echo "$file_and_stuff" | awk -F' - ' '{print $NF}')"
  NEW_QUEUE="$(mktemp)"
  awk -v file="$file" '
    BEGIN {
      once=0
    }
    once == 0 && $0 == file {
      once=1
      print file
    }
    $0 != file { print }
  ' "$QUEUE" > "$NEW_QUEUE"
  mv "$NEW_QUEUE" "$QUEUE"
fi