summaryrefslogtreecommitdiff
path: root/tagimg
blob: 10017a2363de580f576ae5d00e555a1fd6bd2e33 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/sbin/sh

# check for flags
for i in $@; do
  case "$i" in
    "-"*) unset DIRSFLAG LOCALFLAG
      ;;
  esac
  [ -n "$DIRSFLAG" ] && unset LOCALFLAG
  [ -n "$LOCALFLAG" ] && unset DIRSFLAG
  [ -n "$THUMBFLAG" ] && THUMBNAIL="$i" && unset THUMBFLAG
  [ -n "$FILEFLAG" ] && FILENAME="$(printf "$i\n$FILENAME" | paste -s -d'|')" && unset FILEFLAG
  case "$i" in
    "-d")
      DIRSFLAG="y"
      ;;
    "-l")
      LOCALFLAG="y"
      ;;
    "-t")
      THUMBFLAG="y"
      ;;
    "-f")
      FILEFLAG="y"
      ;;
    *)
      printf "Unrecognized flag! I only know -d and -l!\n"
      exit 1
      ;;
  esac
done

[ -z "$THUMBNAIL" ] && THUMBNAIL="thumb.jpg"

if [ -n "$DIRSFLAG" ]; then
  ls | while read i; do
    [ ! -d "$i" ] && continue
    ls "$i"| while read j; do
      [ ! -d "$j" ] && continue
      ls "$i/$j" | while read k; do
        [ ! -f "$k" ] && continue
        case "$k" in
          *.mp3 | *.flac )
            mid3v2 -p "$i/$j/$THUMBNAIL" "$i/$j/$k"
            ;;
        esac
      done
    done
  done
elif [ -n "$LOCALFLAG" ]; then
  [ -z "$FILENAME" ] && exit 1
  IFS='|'
  for i in "$FILENAME"; do
    mid3v2 -p "$THUMBNAIL" "$i"
  done
  unset IFS
fi