X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/d8b1024f3b57a8619fa0e07029e9205e760a84d7..cbfd1b29112cd8ab5540c1019f2a400f4bf20410:/flac2mp3 diff --git a/flac2mp3 b/flac2mp3 index 5ebc873..3f0ef90 100755 --- a/flac2mp3 +++ b/flac2mp3 @@ -1,6 +1,6 @@ #! /usr/bin/env python2.4 -''' +""" =head1 NAME B - transcode FLAC file to MP3 files @@ -48,7 +48,7 @@ Written by Eric Gillespie . =cut -''' #' # python-mode is sucks +""" import re, sys, traceback from optparse import OptionParser @@ -58,6 +58,8 @@ import org.diplodocus.jobs from org.diplodocus import flac, taglib from org.diplodocus.util import run_or_die +from flac_archive.tags import Tags + ################################################################################ # The child processes @@ -146,59 +148,15 @@ def get_decode_args(fn): return args -# XXX other things should usue this; flac files, for example, should -# get PART as part of the filelname, same as mp3s. -class Tags(object): - def __init__(self): - self._global = {} - self._tags = {} - def __len__(self): - return len(self._tags) - def get(self, key, track=None): - key = key.upper() - try: - try: - return self._tags[track][key] - except KeyError: - return self._global[key] - except KeyError: - return None - def gets(self, key, track=None): - value = self.get(key, track) - if value == None: - return None - return '\n'.join(value) - def set(self, key, value, track=None): - key = key.upper() - if track == None: - tags = self._global - else: - try: - tags = self._tags[track] - except KeyError: - tags = self._tags[track] = {} - if key not in tags: - tags[key] = [] - tags[key].append(value) - def get_tags(fn): - '''Return the ARTIST, ALBUM, and DATE tags followed by the TITLE tags - in the file FN.''' + """Return the ARTIST, ALBUM, and DATE tags followed by the TITLE tags + in the file FN.""" tags = Tags() p = Popen(['metaflac', '--export-tags-to=-', fn], stdout=PIPE) - for line in (x.rstrip() for x in p.stdout): - (tag, value) = line.split('=', 1) - - m = re.search(r'\[([0-9]+)]$', tag) - if m != None: - tag = tag[:m.start()] - track = int(m.group(1)) - else: - track = None + tags.load(p.stdout) - tags.set(tag, value, track) # XXX dataloss! check status status = p.wait()