Esempio n. 1
0
 def _cache_artists_art(self):
     """
         Cache artwork for all artists
     """
     # We create cache if needed
     InfoCache.init()
     # Then cache artwork for lastfm/wikipedia/spotify
     # We cache content as the same time
     # TODO Make this code more generic
     for (artist_id, artist) in Lp().artists.get([]):
         debug("ArtDownloader::_cache_artists_art(): %s" % artist)
         artwork_set = False
         if not Gio.NetworkMonitor.get_default().get_network_available() or\
                 InfoCache.exists_in_cache(artist):
             continue
         if Lp().lastfm is not None:
             try:
                 (url, content) = Lp().lastfm.get_artist_infos(artist)
                 if url is not None:
                     s = Gio.File.new_for_uri(url)
                     (status, data, tag) = s.load_contents()
                     if status:
                         artwork_set = True
                         InfoCache.cache(artist, content, data, "lastfm")
                     else:
                         InfoCache.cache(artist, None, None, "lastfm")
             except:
                 InfoCache.cache(artist, None, None, "lastfm")
         if ArtDownloader.Wikipedia is not None:
             try:
                 wp = ArtDownloader.Wikipedia()
                 (url, content) = wp.get_page_infos(artist)
                 if url is not None:
                     s = Gio.File.new_for_uri(url)
                     (status, data, tag) = s.load_contents()
                     if status:
                         artwork_set = True
                         InfoCache.cache(artist, content, data, "wikipedia")
                     else:
                         InfoCache.cache(artist, None, None, "wikipedia")
             except:
                 InfoCache.cache(artist, None, None, "wikipedia")
         url = self._get_spotify_artist_artwork(artist)
         if url is not None:
             s = Gio.File.new_for_uri(url)
             (status, data, tag) = s.load_contents()
             if status:
                 artwork_set = True
                 InfoCache.cache(artist, None, data, "spotify")
             else:
                 InfoCache.cache(artist, None, None, "spotify")
         if artwork_set:
             Lp().art.emit('artist-artwork-changed', artist)
     self._cache_artists_running = False