X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/9ee8e1d0fdc9fff034fc60986d1052cb5cb92a18..f6aab846670f5a35837cd4ce15000859631f77e6:/rewrite-tags diff --git a/rewrite-tags b/rewrite-tags index 6d47eaa..b20a8ea 100755 --- a/rewrite-tags +++ b/rewrite-tags @@ -1,10 +1,9 @@ #! /usr/bin/python -import sys +import os, sys +from errno import EEXIST from subprocess import Popen, PIPE -from org.diplodocus.util import run_or_die - from flac_archive.tags import Tags class SubprocessError(Exception): @@ -45,11 +44,15 @@ def do_read(filenames): for fn in filenames: tags = get_tags(fn) track_tags = tags.get('TRACKNUMBER') + # this check belongs in Tags if len(track_tags) != 1: sys.stderr.write('bogus TRACKNUMBER %s: %s\n' % (track_tags, fn)) return 3 track = int(track_tags[0]) for tag, values in tags._global.iteritems(): + # Makes no sense to save TRACKNUMBER in coll_tags. + if tag == 'TRACKNUMBER': + continue for value in values: if tag in all_tags: all_tags[tag].add(value) @@ -66,6 +69,33 @@ def do_read(filenames): print '\n'.join(coll_tags.all()) return 0 +def do_write(args): + tags = Tags() + tags.load(open(args.pop(0))) + if len(args) != len(tags): + sys.stderr.write('expected %d flac files, got %d\n' + % (len(tags), len(args))) + return 4 + artist = tags.get_path_safe('ARTIST') + album = tags.get_path_safe('ALBUM') + try: + os.mkdir(artist) + except OSError, e: + if e.errno != EEXIST: + raise + album_path = artist + '/' + album + try: + os.mkdir(album_path) + except OSError, e: + if e.errno != EEXIST: + raise + for i, old_fn in enumerate(args): + track = i + 1 + fn = '%s/%s/%s.flac' % (artist, album, tags.make_filename(track)) + if fn != old_fn: + print tags.track(track) + #os.rename(old_fn, fn) + def main(args): if len(args) < 3: return usage()