* flac -> ogg
* flac -> wav -> mp3
+* ogg -> wav -> flac
* ogg -> wav -> mp3
-* mp3 -> ogg
+* mp3 -> wav -> flac
+* mp3 -> wav -> ogg
External packages required for full functionality:
"""
metadata = {}
vorbis_keys = {
+ 'comm': 'comment',
'talb': 'album',
- 'tpe1': 'artist',
+ 'tcom': 'composer',
+ 'tcon': 'genre',
+ 'tcop': 'copyright',
'tit2': 'title',
+ 'tpe1': 'artist',
+ 'tpe2': 'band',
+ 'tpe3': 'conductor',
+ 'tpos': 'part of set',
'trck': 'tracknumber',
'tyer': 'date',
- 'tcon': 'genre',
- 'comm': 'comment',
}
+ drop_keys = [
+ 'apic' # attached picture
+ ]
in_v2 = False
for line in stdout.splitlines():
if not in_v2:
continue
key,value = [x.strip() for x in line.split(':', 1)]
short_key = key.split()[0]
+ if short_key.lower() in drop_keys:
+ continue
v_key = vorbis_keys[short_key.lower()]
if v_key == 'genre':
value = value.rsplit('(', 1)[0].strip()
invoke(['oggenc', '--quiet', '-q', '3', source, '-o', target])
convert_flac_to_ogg.handles_metadata = True
+ def convert_mp3_to_flac(self, source, target):
+ self.convert_mp3_to_wav(source, self._tempfile)
+ self.convert_wav_to_flac(self._tempfile, target)
+
def convert_mp3_to_ogg(self, source, target):
self.convert_mp3_to_wav(source, self._tempfile)
self.convert_wav_to_ogg(self._tempfile, target)
def convert_ogg_to_wav(self, source, target):
self.convert_flac_to_wav(source_target)
+ def convert_wav_to_flac(self, source, target):
+ invoke(['flac', '-o', target, source])
+
def convert_wav_to_mp3(self, source, target):
invoke(['lame', '--quiet', '-V', '4', source, target])
['vorbiscomment', '--list', source])
return self._parse_vorbis_comments(stdout)
+ def set_flac_metadata(self, target, metadata):
+ stdin = '\n'.join(['%s=%s' % (k.upper(), v)
+ for k,v in sorted(metadata.iteritems())])
+ invoke(['metaflac', '--import-tags-from=-', target], stdin=stdin)
+
def set_mp3_metadata(self, target, metadata):
args = ['id3v2']
for key,arg in [('album', '--album'), ('artist', '--artist'),
def set_ogg_metadata(self, target, metadata):
stdin = '\n'.join(['%s=%s' % (k.upper(), v)
- for k,v in metadata.iteritems()])
+ for k,v in sorted(metadata.iteritems())])
invoke(['vorbiscomment', '--write', target], stdin=stdin)
- return self._parse_vorbis_comments(stdin)
def test():