Package screenlets :: Package plugins :: Module CoverSearch

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.CoverSearch

     1  # This application is released under the GNU General Public License
     2  # v3 (or, at your option, any later version). You can find the full
     3  # text of the license under http://www.gnu.org/licenses/gpl.txt.
     4  # By using, editing and/or distributing this software you agree to
     5  # the terms and conditions of this license.
     6  # Thank you for using free software!
     7
     8
     9  from AmazonCoverArtSearch import AmazonCoverArtSearch
    10  from Loader import Loader
    11  import os
    12
    13  import threading
    14  import time
    15
    16 -class CoverSearch (threading.Thread):
    17          loader = None
    18          Result = False
    19          artist = ""
    20          album = ""
    21          callback_fn = False
    22
    23          AlbumCover = "/tmp/nowplaying-album.jpg"
    24
    25 -        def __init__(self):
    26                  self.loader = Loader()
    27                  self.engine = AmazonCoverArtSearch(self.loader)
    28                  self.Result = False
    29                  threading.Thread.__init__(self)
    30
    31 -        def initData(self, artist, album, fn):
    32                  self.artist = artist
    33                  self.album = album
    34                  self.callback_fn = fn
    35
    36 -        def saveimg(self, data):
    37                  fobj = open(self.AlbumCover,"w")
    38                  fobj.write(data)
    39                  fobj.close()
    40                  self.Result = True
    41
    42 -        def cb(self, itm, artist, album, result, *args):
    43                  data = self.engine.get_best_match_urls(result)
    44                  if data and self.artist == artist and self.album == album:
    45                          #print data[0]
    46                          self.loader.get_url(data[0], self.saveimg)
    47
    48 -        def run(self):
    49                  if os.path.exists(self.AlbumCover): os.remove(self.AlbumCover)
    50                  self.Result = False
    51                  self.engine.search (self.artist, self.album, self.cb)
    52                  while True:
    53                          if self.Result:
    54                                  break
    55                          if not self.engine.search_next ():
    56                                  break
    57
    58                  cover = False
    59                  if os.path.exists(self.AlbumCover):
    60                          cover = self.AlbumCover
    61
    62                  #print threading.currentThread()
    63                  self.callback_fn(cover)
    64                  return None
    65