]> Sergey Matveev's repositories - dotfiles.git/blob - bin/bin/music-indexer
076a19e7ff03ab41431950f4eff63a06da032def
[dotfiles.git] / bin / bin / music-indexer
1 #!/usr/bin/env zsh
2
3 cat <<EOF
4 %rec: album
5 %mandatory: artist album
6 %allowed: year col lossless
7 %type: year int
8 %type: lossless bool
9 %sort: artist year album
10
11 EOF
12
13 setopt EXTENDED_GLOB
14 COLS=()
15 for col (cols/*) COLS=($COLS $col:t)
16 for name (*~cols) {
17     ts=(${(s/-/)name})
18     year=""
19     for (( i=2 ; i <= $#ts ; i++ )) {
20         [[ ${ts[$i]} =~ "^[0-9][0-9][0-9][0-9]$" ]] && {
21             year=${ts[$i]}
22             break
23         }
24     }
25     [[ -n $year ]] && {
26         artist=(${ts[1,$i-1]})
27         album=(${ts[$i+1,-1]})
28     } || {
29         artist=${ts[1]}
30         album=(${ts[2,-1]})
31     }
32     lossless=""
33     if [[ -d $name ]] ; then
34         wvs=($name/**/*.wv(N))
35         [[ ${#wvs} -gt 0 ]] && lossless=1
36     else
37         [[ $name:e = wv ]] && lossless=1
38     fi
39     cols=()
40     for col ($COLS) [[ -e cols/$col/$name ]] && cols=($cols $col)
41
42     print "artist: ${(j/-/)artist:gs/_/ /}"
43     [[ -n $year ]] && print "year: $year"
44     print "album: ${(j/-/)album:gs/_/ /}"
45     [[ -n $lossless ]] && print "lossless: yes"
46     for col ($cols) print "col: $col"
47     print
48 }