X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/3e8794c0d39a363cd6da9f6a29e0b07fb8ede9ea..cbfd1b29112cd8ab5540c1019f2a400f4bf20410:/flac2mp3 diff --git a/flac2mp3 b/flac2mp3 index 1e29ad0..3f0ef90 100755 --- a/flac2mp3 +++ b/flac2mp3 @@ -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,42 +148,6 @@ 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): - # All files have at least one track. - return max(1, 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.""" @@ -189,17 +155,8 @@ def get_tags(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()