X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/066062f83099a15ddb9cf5154e217b2c58ddea33..d68e39caa6c9d64fa0d284faf71aa32d0fdc0fa6:/rewrite-tags diff --git a/rewrite-tags b/rewrite-tags index d4ce48c..1d4b412 100755 --- a/rewrite-tags +++ b/rewrite-tags @@ -20,7 +20,7 @@ class SubprocessError(Exception): Exception.__init__(self, msg % (abs(status), command_msg)) self.status = status self.command = command - self.stderr = stderr + self.stderr = ''.join(stderr) def get_tags(fn): tags = Tags() @@ -43,10 +43,9 @@ def rewrite_track_tags(track, tags, fn, tmp): '--remove-all-tags', '--import-tags-from', tmp.name, fn] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - stdout, stderr = p.communicate() status = p.wait() if status != 0: - raise SubprocessError(status, command=command, stderr=stdout) + raise SubprocessError(status, command=command, stderr=p.stdout) def do_read(filenames): # Use this mapping of tag names to sets of tag values to detect global tags. @@ -61,7 +60,7 @@ def do_read(filenames): # this check belongs in Tags if len(track_tags) != 1: sys.stderr.write('bogus TRACKNUMBER %s: %s\n' % (track_tags, fn)) - return 3 + return 4 track = int(track_tags[0]) for tag, values in tags._global.iteritems(): # Makes no sense to save TRACKNUMBER in coll_tags. @@ -89,7 +88,7 @@ def do_write(args): if len(args) != len(tags): sys.stderr.write('expected %d flac files, got %d\n' % (len(tags), len(args))) - return 4 + return 2 artist = tags.get_path_safe('ARTIST') album = tags.get_path_safe('ALBUM') try: @@ -121,10 +120,14 @@ def do_write(args): def main(args): if len(args) < 3: return usage() - if args[1] == 'read': - return do_read(args[2:]) - if args[1] == 'write': - return do_write(args[2:]) + try: + if args[1] == 'read': + return do_read(args[2:]) + if args[1] == 'write': + return do_write(args[2:]) + except SubprocessError, e: + sys.stderr.write('%s\n%s\n' % (e.stderr, e)) + return 3 return usage() def usage():