X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/6ca18c015e6e66589c8aa3620c7a11efb7cc836a..bc10ac6298048de2f6c67c9d4d413a54352ccda9:/rewrite-tags 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: