I was playing with eyeD3 the other day and realized that it's able to spit out 
a cover art file. So now we can get rid of the PyID3 dependency and the best 
part is that eyeD3 will actually extract cover art from files with older ID3 
tags. Also eyeD3 will give us the mimetype of the cover art file so we can 
give it a proper file extension instead of making everything use .jpg.

Also while tinkering with some ogg podcasts I noticed that if oggdec or lame 
is not installed then gPodder will crash after attempting to convert an ogg 
file. I added some verification to make sure those applications are 
installed.

Attached are the diffs of the files I modified.

nick
--- gpodder-r448/src/gpodder/libconverter.py	2007-11-03 11:07:24.000000000 -0400
+++ gpodder-r447-dev/src/gpodder/libconverter.py	2007-11-03 11:25:38.000000000 -0400
@@ -29,6 +29,12 @@
 import popen2
 import os
 import os.path
+from liblogger import log
+
+# Check to see if the user has lame installed
+have_lame = False
+if os.system("which lame >/dev/null 2>&1") == 0:
+    have_lame = True
 
 class FileConverter:
     percentage_match = re.compile('(\d+)%')
@@ -58,11 +64,19 @@
     def __init__( self):
         self.dict = {}
 
-    def add_converter( self, extension, command):
-        self.dict[extension.lower()] = FileConverter( command)
+    def add_converter( self, extension, command, arguments):
+        if os.system("which %s >/dev/null 2>&1" % command) == 0:
+            log('(libconverter) Found %s, will try to convert %s files.' % ( command, extension ))
+            self.dict[extension.lower()] = FileConverter( command + ' ' + arguments)
+        else:
+            log('(libconverter) Could not find %s, %s files will NOT be converted.' % ( command, extension ))
 
     def has_converter( self, extension):
-        return self.dict.has_key( extension.lower())
+        if have_lame:
+            return self.dict.has_key( extension.lower())
+        else:
+            log('(libconverter) Could not find lame, cannot convert file.')
+            return False
 
     def convert( self, input_filename, output_filename = None, callback = None):
         extension = os.path.splitext( input_filename)[1][1:]
@@ -81,5 +95,5 @@
 converters = ConverterCollection()
 
 # Add known converter applications
-converters.add_converter( 'ogg', 'oggdec --quiet --output=/dev/stdout "%s"')
+converters.add_converter( 'ogg', 'oggdec', '--quiet --output=/dev/stdout "%s"')
 
--- gpodder-r448/src/gpodder/libipodsync.py	2007-11-03 11:07:24.000000000 -0400
+++ gpodder-r447-dev/src/gpodder/libipodsync.py	2007-11-03 11:13:20.000000000 -0400
@@ -54,24 +54,15 @@
 except:
     log( '(ipodsync) Could not find pymad.')
 
-try:
-    import eyeD3
-    log( '(ipodsync) Found eyeD3')
-except:
-    log( '(ipodsync) Coulld not find eyeD3.')
-
-
-# are we going to use python-id3 for cover art extraction?
-use_pyid3 = False
+# are we going to use eyeD3 for cover art extraction?
+get_coverart = False
 
 try:
-    # try to load PyID3
-    import id3
-    use_pyid3 = True
-    log('(ipodsync) Found PyID3, will try to extract cover art from mp3 metadata')
+    import eyeD3
+    get_coverart = True
+    log( '(ipodsync) Found eyeD3, will try to extract cover art from mp3 metadata')
 except:
-    log('(ipodsync) PyID3 not found - falling back to channel cover for iPod cover art')
-
+    log( '(ipodsync) Coulld not find eyeD3 - falling back to channel cover for iPod cover art')
 
 import os
 import os.path
@@ -348,19 +339,21 @@
     def set_cover_art(self, track, local_filename):
         if not ipod_supported():
             return False
-        if use_pyid3:
-            try:
-                cover_filename = local_filename + '.cover.jpg'
-                id3v2_tags = id3.ID3v2( local_filename )
-                for frame in id3v2_tags.frames:
-                    if frame.id == 'APIC':
-                        cover_file = file(cover_filename, 'w')
-                        cover_file.write(frame.image)
-                        cover_file.close()
-                if os.path.isfile( cover_filename):
+        if get_coverart:
+            tag = eyeD3.Tag()
+            if tag.link(local_filename):
+                if tag.frames['APIC'] != []:
+                    # Try to guess the file extension (default to jpg)
+                    ext = '.jpg'
+                    if tag.frames['APIC'][0].mimeType == 'image/png':
+                        ext = '.png'
+                    cover_filename = local_filename + '.cover' + ext
+                    cover_file = file(cover_filename, 'w')
+                    cover_file.write(tag.frames['APIC'][0].imageData)
+                    cover_file.close()
                     gpod.itdb_track_set_thumbnails( track, cover_filename)
                     return True
-            except:
+            else:
                 log( '(ipodsync) Error reading ID3v2 information for %s' % ( local_filename, ))
         # If we haven't yet found cover art, fall back to channel cover
         return self.set_channel_art( track, local_filename)
--- gpodder-r448/src/gpodder/util.py	2007-11-03 11:07:24.000000000 -0400
+++ gpodder-r447-dev/src/gpodder/util.py	2007-11-03 11:46:45.000000000 -0400
@@ -187,9 +187,12 @@
     try:
         os.unlink( path)
         # if libipodsync extracted the cover file, remove it here
-        cover_path = path + '.cover.jpg'
-        if os.path.isfile( cover_path):
-            os.unlink( cover_path)
+        cover_path = path + '.cover'
+        if os.path.isfile( cover_path + '.jpg'):
+            os.unlink( cover_path + '.jpg')
+        elif os.path.isfile( cover_path + '.png'):
+            os.unlink( cover_path + '.png')
+
     except:
         pass
 
_______________________________________________
gpodder-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/gpodder-devel

Reply via email to