On May 28, 2008 15:49:52 David Spreen wrote:
> Hi,
>
> I wrote a quick patch against the stable branch to sync cover art to
> Rockbox iPods (with the UMS config). However, right now gpodder doesn't
> determine if the player is a rockbox player and the size of the BMP file
> generated is non-configurable.
>
> If this was to make it upstream, what would be the prefered way of
> dealing with this? Should I make a new player-class for rockbox players
> and have cover-size be configurable (I believe that different player
> ports of rockbox use different resolutions for album art)? Or should
> that just be an option for the general UMS class?
>
> Let me know what you think. I am happy to provide a patch against trunk
> too. Right now I'd just like some feedback.
>
> Best,
>
> David

Hello David,

That looks pretty good. I added two config settings, one 
called 'rockbox_copy_coverart' and 'rockbox_coverart_size'. The former 
enables copying to the device and the latter specifies the size of the image 
file (we only need one side since it's always a square, right?).

Great work,

nick
Index: src/gpodder/config.py
===================================================================
--- src/gpodder/config.py	(revision 724)
+++ src/gpodder/config.py	(working copy)
@@ -108,6 +108,8 @@
     'mp3_player_use_scrobbler_log': (bool, False),
     'show_podcast_url_entry': (bool, True),
     'maemo_allow_custom_player': (bool, False),
+    'rockbox_copy_coverart' : (bool, False),
+    'rockbox_coverart_size' : (int, 100),
 
     # Hide the cover/pill from the podcast sidebar when it gets too small
     'podcast_sidebar_save_space': (bool, True),
Index: src/gpodder/sync.py
===================================================================
--- src/gpodder/sync.py	(revision 724)
+++ src/gpodder/sync.py	(working copy)
@@ -46,6 +46,10 @@
 except:
     log( '(gpodder.sync) Could not find eyeD3')
 
+try:
+    import Image
+except:
+    log( '(gpodder.sync) Could not find Python Image Library')
 
 import os
 import os.path
@@ -513,6 +517,10 @@
             log('Marking "%s" from "%s" as played', episode.title, episode.channel.title, sender=self)
             gl.history_mark_played(episode.url)
 
+        if gl.config.rockbox_copy_coverart and not os.path.exists(os.path.join(folder, 'cover.bmp')):
+            log('Creating Rockbox album art for "%s"', episode.channel.title, sender=self)
+            self.set_cover_art(folder, from_file)
+
         if not os.path.exists(to_file):
             log('Copying %s => %s', os.path.basename(from_file), to_file.decode(self.enc), sender=self)
             return self.copy_file_progress(from_file, to_file)
@@ -614,6 +622,27 @@
         # No scrobbler log on that device
         return None
 
+    def set_cover_art(self, destination, local_filename):
+        try:
+            cover_loc = os.path.join(os.path.dirname(local_filename), 'cover')
+            cover_dst = os.path.join(destination, 'cover.bmp')
+            if os.path.isfile(cover_loc):
+                size = (gl.config.rockbox_coverart_size, gl.config.rockbox_coverart_size)
+                try:
+                    cover = Image.open(cover_loc)
+                    cover.thumbnail(size)
+                    cover.save(cover_dst, 'BMP')
+                except IOError:
+                    log('Cannot create %s (PIL?)', cover_dst, sender=self)
+                return True
+            else:
+                log('No rockbox cover available', sender=self)
+                return True
+        except:
+            log('Error getting cover using channel cover', sender=self)
+        return False
+
+
     def load_audioscrobbler_log(self, log_file):
         """ Retrive track title and artist info for all the entries
             in an audioscrobbler portable player format logfile
_______________________________________________
gpodder-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/gpodder-devel

Reply via email to