Commit | Line | Data |
---|---|---|
583b7e4a MW |
1 | #! /bin/sh -e |
2 | ||
3 | case $# in 0) set -- . ;; esac | |
4 | ||
5 | parse_vorbis_comment () { | |
6 | tag=$1 | |
7 | ||
8 | while read value; do | |
9 | case "$value" in | |
10 | artist=* | album=* | musicbrainz_albumid=*) | |
11 | label=${value%%=*} | |
12 | eval $label=\${value#*=} | |
13 | eval have_$label=t | |
14 | ;; | |
15 | esac | |
16 | done <<TAG | |
17 | $tag | |
18 | TAG | |
19 | } | |
20 | ||
21 | find "$@" \( -name '*.flac' -o -name '*.ogg' -o -name '*.mp3' \) -print | \ | |
22 | while read file; do | |
23 | have_artist=nil | |
24 | have_album=nil | |
25 | have_musicbrainz_albumid=nil | |
26 | case "$file" in | |
27 | "$skip"/*) | |
28 | continue | |
29 | ;; | |
30 | *.flac) | |
31 | parse_vorbis_comment "$( | |
32 | metaflac --list --block-type=VORBIS_COMMENT "$file" | | |
33 | sed -n '/^.*comment\[[0-9]*\]: /s///p')" | |
34 | ;; | |
35 | *.ogg) | |
36 | parse_vorbis_comment "$(vorbiscomment "$file")" | |
37 | ;; | |
38 | *.mp3) | |
39 | tag="$(id3v2 --list "$file")" | |
40 | while read fourcc rest; do | |
41 | rest=${rest#*): } | |
42 | case "$fourcc,$rest" in | |
43 | TPE1,*) artist=$rest have_artist=t ;; | |
44 | TALB,*) album=$rest have_album=t ;; | |
45 | TXXX,"(MusicBrainz Album Id): "*) | |
46 | musicbrainz_albumid=${rest#*): } | |
47 | have_musicbrainz_albumid=t | |
48 | ;; | |
49 | esac | |
50 | done <<TAG | |
51 | $tag | |
52 | TAG | |
53 | esac | |
54 | case $have_artist,$have_album,$have_musicbrainz_albumid in | |
55 | t,t,t) | |
56 | echo "$musicbrainz_albumid $artist | $album" | |
57 | skip=${file%/*} | |
58 | ;; | |
59 | esac | |
60 | done |