[gnome-music/wip/libmediaart] albumArtCache: Remove unused functions and constants



commit e3eb9378d7b692b632156c6a010f71ffa88165b6
Author: Arnel A. Borja <arnelborja src gnome org>
Date:   Wed Apr 2 14:04:15 2014 +0800

    albumArtCache: Remove unused functions and constants
    
    Cleanup for port to libmediaart.

 gnomemusic/albumArtCache.py |   72 ++++++-------------------------------------
 1 files changed, 10 insertions(+), 62 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index 4877f29..bff150f 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -34,7 +34,6 @@ import cairo
 from math import pi
 import threading
 import os
-import re
 from gnomemusic import log
 import logging
 logger = logging.getLogger(__name__)
@@ -49,17 +48,16 @@ class LookupRequest:
         self.height = height or -1
         self.callback = callback
         self.data = data
-        self.path = ''
-        self.key_index = 0
-        self.icon_format = 'jpeg'
-        self.artist = item.get_string(Grl.METADATA_KEY_ARTIST) or item.get_string(Grl.METADATA_KEY_AUTHOR) 
or ''
-        self.album = item.get_string(Grl.METADATA_KEY_ALBUM) or ''
+        self.artist = item.get_string(Grl.METADATA_KEY_ARTIST) or item.get_string(Grl.METADATA_KEY_AUTHOR)
+        self.album = item.get_string(Grl.METADATA_KEY_ALBUM)
+        self.path = MediaArt.get_path(self.artist, self.album, "album", None)[0]
         self.started = False
 
     @log
     def start(self):
         self.started = True
-        self._try_load()
+        f = Gio.File.new_for_path(self.path)
+        f.read_async(GLib.PRIORITY_DEFAULT, None, self._on_read_ready, None)
 
     @log
     def finish(self, pixbuf):
@@ -69,21 +67,6 @@ class LookupRequest:
         self.callback(pixbuf, self.path, self.data)
 
     @log
-    def _try_load(self):
-        if self.key_index >= 2:
-            if self.icon_format == 'jpeg':
-                self.key_index = 0
-                self.icon_format = 'png'
-            else:
-                self._on_try_load_finished(None)
-                return
-
-        self.path = MediaArt.get_path(self.artist, self.album, "album", None)[0]
-        f = Gio.File.new_for_path(self.path)
-
-        f.read_async(GLib.PRIORITY_DEFAULT, None, self._on_read_ready, None)
-
-    @log
     def _on_read_ready(self, obj, res, data=None):
         try:
             stream = obj.read_finish(res)
@@ -95,15 +78,14 @@ class LookupRequest:
             if AlbumArtCache.get_default().logLookupErrors:
                 print('ERROR:', error)
 
-        self.key_index += 1
-        self._try_load()
+        self._on_load_fail()
 
     @log
     def _on_pixbuf_ready(self, source, res, data=None):
         try:
             pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res)
             if self.width < 0 and self.height < 0:
-                self._on_try_load_finished(pixbuf)
+                self.finish(pixbuf)
                 return
 
             width = pixbuf.get_width()
@@ -115,21 +97,15 @@ class LookupRequest:
                     self.width *= (width / height)
                 scale = max(width / self.width, height / self.height)
                 pixbuf = pixbuf.scale_simple(width / scale, height / scale, 2)
-                self._on_try_load_finished(pixbuf)
+                self.finish(pixbuf)
                 return
         except Exception as error:
             if AlbumArtCache.get_default().logLookupErrors:
                 print('ERROR:', error)
 
-        self.key_index += 1
-        self._try_load()
-
-    @log
-    def _on_try_load_finished(self, icon, data=None):
-        if icon:
-            self.finish(icon)
-            return
+        self._on_load_fail()
 
+    def _on_load_fail(self):
         options = Grl.OperationOptions()
         options.set_flags(Grl.ResolutionFlags.FULL |
                           Grl.ResolutionFlags.IDLE_RELAY)
@@ -223,10 +199,6 @@ class AlbumArtCache:
     instance = None
     degrees = pi / 180
 
-    blocks = re.compile('(\[(.*?)\]|\{(.*?)\}|\<(.*?)\>|\((.*?)\))', re.DOTALL)
-    invalid_chars = re.compile('[()<>\[\]{}_! #$^&*+=|\\\/"\'?~]', re.DOTALL)
-    multiple_spaces = re.compile('\t|\s+', re.DOTALL)
-
     @classmethod
     def get_default(self):
         if self.instance:
@@ -348,30 +320,6 @@ class AlbumArtCache:
         request.start()
 
     @log
-    def _normalize_and_hash(self, input_str):
-        normalized = ' '
-
-        if input_str and len(input_str) > 0:
-            normalized = self._strip_invalid_entities(input_str)
-            normalized = GLib.utf8_normalize(normalized, -1,
-                                             GLib.NormalizeMode.NFKD)
-            normalized = normalized.lower()
-
-        return GLib.compute_checksum_for_string(GLib.ChecksumType.MD5,
-                                                normalized, -1)
-
-    @log
-    def _strip_invalid_entities(self, original):
-        # Strip blocks
-        string = self.blocks.sub('', original)
-        # Strip invalid chars
-        string = self.invalid_chars.sub('', string)
-        # Remove double spaces
-        string = self.multiple_spaces.sub(' ', string)
-        # Remove trailing spaces and convert to lowercase
-        return string.strip().lower()
-
-    @log
     def get_from_uri(self, uri, artist, album, width, height, callback, data=None):
         if not uri:
             return


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