]> Sergey Matveev's repositories - dotfiles.git/blob - bin/bin/music-indexer
Have not used zshfe for years
[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 Collection Lossless
7 %type: Year int
8 %type: Lossless bool
9
10 EOF
11
12 setopt EXTENDED_GLOB
13 COLS=()
14 for col (cols/*) COLS=($COLS $col:t)
15 for name (*~cols) {
16     ts=(${(s/-/)name})
17     year=""
18     for (( i=2 ; i <= $#ts ; i++ )) {
19         [[ ${ts[$i]} =~ "^[0-9][0-9][0-9][0-9]$" ]] && {
20             year=${ts[$i]}
21             break
22         }
23     }
24     [[ -n $year ]] && {
25         artist=(${ts[1,$i-1]})
26         album=(${ts[$i+1,-1]})
27     } || {
28         artist=${ts[1]}
29         album=(${ts[2,-1]})
30     }
31     lossless=""
32     if [[ -d $name ]] ; then
33         wvs=($name/**/*.wv(N))
34         [[ ${#wvs} -gt 0 ]] && lossless=1
35     else
36         [[ $name:e = wv ]] && lossless=1
37     fi
38     cols=()
39     for col ($COLS) [[ -e cols/$col/$name ]] && cols=($cols $col)
40
41     print "Artist: ${(j/-/)artist:gs/_/ /}"
42     [[ -n $year ]] && print "Year: $year"
43     print "Album: ${(j/-/)album:gs/_/ /}"
44     [[ -n $lossless ]] && print "Lossless: yes"
45     for col ($cols) print "Collection: $col"
46     print
47 }