]> diplodocus.org Git - flac-archive/commitdiff
Copy flac PICTURE to mp3 APIC using new extension modules.
authorepg <>
Wed, 1 Nov 2006 11:07:20 +0000 (11:07 +0000)
committerepg <>
Wed, 1 Nov 2006 11:07:20 +0000 (11:07 +0000)
flac2mp3

index 5fc05ed..20ab476 100755 (executable)
--- a/flac2mp3
+++ b/flac2mp3
@@ -55,12 +55,13 @@ from optparse import OptionParser
 from subprocess import Popen, PIPE
 
 import org.diplodocus.jobs
+from org.diplodocus import flac, taglib
 from org.diplodocus.util import run_or_die
 
 ################################################################################
 # The child processes
 
-def flac2mp3(fn, title, artist, album, date, track, skip_until):
+def flac2mp3(fn, title, artist, album, date, track, skip_until, pic=None):
     (title, artist, album, date) = [(x == None and 'unknown') or x
                                     for x in (title, artist, album, date)]
     try:
@@ -95,6 +96,9 @@ def flac2mp3(fn, title, artist, album, date, track, skip_until):
                % (flac_options, skip_arg or '', until_arg or '', fn,
                   lame_options, title, artist, album, date, track, outfile))
 
+    if pic != None:
+        taglib.add_apic_frame_to_mp3(outfile, pic[0], pic[1], pic[2])
+
     return 0
 
 ################################################################################
@@ -176,7 +180,7 @@ def get_tags(fn):
 
     tags = Tags()
 
-    p = Popen(['metaflac', '--export-vc-to=-', fn], stdout=PIPE)
+    p = Popen(['metaflac', '--export-tags-to=-', fn], stdout=PIPE)
     for line in (x.rstrip() for x in p.stdout):
         (tag, value) = line.split('=', 1)
 
@@ -193,6 +197,18 @@ def get_tags(fn):
 
     return tags
 
+def find_pic(fn, tags):
+    pic = tags.get('__flac2mp3_PICTURE')
+
+    if not isinstance(pic, tuple):
+        for i in flac.get_pictures(fn):
+            if i[1] == flac.PICTURE_TYPE_FRONT_COVER:
+                pic = i[:3]
+                break
+        tags.set('__flac2mp3_PICTURE', pic)
+
+    return pic
+
 def main(argv):
     # Control the exit code for any uncaught exceptions.
     try:
@@ -255,7 +271,7 @@ def main(argv):
                                  tags.gets('ARTIST', track),
                                  album,
                                  tags.gets('DATE', track),
-                                 track, args[i]])
+                                 track, args[i], find_pic(fn, tags)])
                     track = i + 2
             except Exception, error:
                 sys.stderr.write(getattr(error, 'msg', ''))