[kupfer] rhythmbox: Local file system search more closely mimics rhythmbox



commit 53af5a101f95d0e1c96c2e6c798971ddfd890d00
Author: William Friesen <wfriesen gmail com>
Date:   Wed Nov 17 18:42:27 2010 +1100

    rhythmbox: Local file system search more closely mimics rhythmbox
    
    Local file system search is case insensitive
    Finds .jpg files with any of the following names
    "cover", "album", "albumart", ".folder", "folder" or "$artist - $album"
    
    Co-authored-by: Ulrik (ignore unicode)
    
    Launchpad-bug: https://bugs.launchpad.net/kupfer/+bug/676433

 kupfer/plugin/rhythmbox.py |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/plugin/rhythmbox.py b/kupfer/plugin/rhythmbox.py
index 73a09af..67ecc7a 100644
--- a/kupfer/plugin/rhythmbox.py
+++ b/kupfer/plugin/rhythmbox.py
@@ -8,6 +8,7 @@ import itertools
 from hashlib import md5
 
 import gio
+import os
 
 from kupfer.objects import (Leaf, Source, AppLeaf, Action, RunnableLeaf,
 		SourceLeaf )
@@ -252,10 +253,18 @@ class AlbumLeaf (TrackCollection):
 	def _get_thumb_local(self):
 		# try local filesystem
 		uri = self.object[0]["location"]
+		artist = self.object[0]["artist"].lower()
+		album = self.object[0]["album"].lower()
 		gfile = gio.File(uri)
-		for cover_name in ("album.jpg", "cover.jpg"):
-			cfile = gfile.resolve_relative_path("../" + cover_name)
-			if cfile.query_exists():
+		cdir = gfile.resolve_relative_path("../").get_path()
+		# We don't support unicode ATM
+		bs_artist_album = \
+			" - ".join([us.encode("ascii", "ignore") for us in (artist, album)])
+		cover_names = ("cover.jpg", "album.jpg", "albumart.jpg",
+				".folder.jpg", "folder.jpg", bs_artist_album + ".jpg")
+		for cover_name in os.listdir(cdir):
+			if cover_name.lower() in cover_names:
+				cfile = gfile.resolve_relative_path("../" + cover_name)
 				return cfile.get_path()
 
 	def _get_thumb_mediaart(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]