Commits

Ning Sun committed 253dddc Merge

merge branches

  • Participants
  • Parent commits d13005d, dbbc05d

Comments (0)

Files changed (2)

-Version='0.0.2'
+Version='0.0.3'
 Authors=['Sun Ning <classicning@gmail.com>']
 Name=_('Douban Covers')
 Description='Load album cover from http://www.douban.com/music/'
 import time
 import os
 from xl.cover import *
-from xl import event, common, settings
+from xl import event, common, settings, providers, metadata
 import logging
 
 import doubanquery
 
 logger = logging.getLogger(__name__)
 
+DOUBAN_COVER  = None
+
 def enable(exaile):
 	if(exaile.loading):
 		event.add_callback(_enable, 'exaile_loaded')
 		_enable(None, exaile, None)
 
 def disable(exaile):
-	exaile.covers.remove_search_method_by_name('douban')
+	providers.unregister('covers', DOUBAN_COVER)
 
 def _enable(eventname, exaile, nothing):
-	exaile.covers.add_search_method(
-		DoubanCoverSearch()
-	)
+	global DOUBAN_COVER
+	DOUBAN_COVER =  DoubanCoverSearch()
+	providers.register('covers', DOUBAN_COVER)
 	
 def get_prefs_pane():
     return doubanprefs
 		self.starttime = 0
 
 	def find_covers(self, track, limit=-1):
-		artist, album = track.get_album_tuple()
+		try:
+			artist = track.get_tag_raw('artist')[0]
+			album = track.get_tag_raw('album')[0]
+		except (AttributeError, TypeError):
+			return []
+			
+		
 		return self.search_covers("%s, %s" %(artist, album), limit)
 
+	def get_cover_data(self, url):
+		h = urllib.urlopen(url)
+		data = h.read()
+		h.close()
+		return data
+
 	def search_covers(self, search, limit=-1):
 		waittime = 1 - (time.time() - self.starttime)
 		if waittime > 0: time.sleep(waittime)
 			cover_urls = list(doubanquery.search(search, apikey))
 			logger.info(cover_urls or "no url from douban")
 			if len(cover_urls) == 0:
-				raise NoCoverFoundException()
+				return []
+			return cover_urls
 		except:
-			traceback.print_exc()
-			raise NoCoverFoundException()
+			#traceback.print_exc()
+			return []
 
-		cache_dir = self.manager.cache_dir
-		logger.info(cache_dir)
 
-		candidants = []
-		for cover_url in cover_urls:
-			try:
-				l = urllib.urlopen(cover_url)
-				data = l.read()
-				l.close()
 
-				covername = os.path.join(cache_dir, hashlib.md5(cover_url).hexdigest())
-				covername += '.jpg'
 
-				l = open(covername, 'w')
-				l.write(data)
-				l.close()
-
-				candidants.append(covername)
-			except:
-				traceback.print_exc()
-				common.log_excepton()
-
-		return candidants
-
-
-
-
-