From: Date: Tue, 14 May 2013 06:20:35 +0000 (-0700) Subject: Fix bugs: X-Git-Url: https://diplodocus.org/git/flac-archive/commitdiff_plain/cbfe50a594d047b8e527aa99797f1ae3aa758509?hp=bac901c8347d505f5d78e8e08648f44ddf735944 Fix bugs: - read: support a tag appearing with the same value on a subset of tracks and nowhere else; previously this was ok if the value were differnet, but if say only a few tracks had VERSION=radio and the rest had no VERSION, VERSION would erroneously become a global tag - write: support each track having own ALBUM with on global ALBUm (e.g. most tracks are 'album=foo' but a few are 'album=foo extended'); previously broke as ALBUm had to be global - bonus: i noticed write was also missing ALBUMARTIST; added --- diff --git a/rewrite-tags b/rewrite-tags index 1d4b412..eec265e 100755 --- a/rewrite-tags +++ b/rewrite-tags @@ -74,11 +74,18 @@ def do_read(filenames): coll_tags.set(tag, value, track) for tag, values in all_tags.iteritems(): if len(values) == 1: - # Only one value for this tag, so add it to global tags. - coll_tags.set(tag, list(values)[0]) - # And now remove it from each track tags. + # Only one value for this tag, but does that one value appear on + # all tracks? for track, tags in coll_tags._tracks.iteritems(): - del tags[tag] + if not tag in tags: + # Nope. + break + else: + # Yep, so add it to global tags. + coll_tags.set(tag, list(values)[0]) + # And now remove it from each track tags. + for track, tags in coll_tags._tracks.iteritems(): + del tags[tag] print '\n'.join(coll_tags.all()) return 0 @@ -89,8 +96,12 @@ def do_write(args): sys.stderr.write('expected %d flac files, got %d\n' % (len(tags), len(args))) return 2 - artist = tags.get_path_safe('ARTIST') + artist = tags.get_path_safe('ALBUMARTIST') + if not artist: + artist = tags.get_path_safe('ARTIST') album = tags.get_path_safe('ALBUM') + if not album: + album = tags.get_path_safe('ALBUM', track=1) try: os.mkdir(artist) except OSError, e: