def _populate_from_all_logs(self): lw.log(['reset the window to prep it for data']) self.LISTCONTROL.reset() displayed_log = False #if there is an external script defined, call it if self.EXTERNALSCRIPT: lw.log(['trying to execute external script to generate log file']) result, loglines = popenWithTimeout(self.EXTERNALSCRIPT, self.EXTERNALTIMEOUT) lw.log(loglines) for title, logfile in self._get_log_files(): self.LOGFILE = logfile if title: item = xbmcgui.ListItem(label=title) item.setProperty('istitle', 'true') self.LISTCONTROL.addItem(item) if xbmcvfs.exists(logfile): displayed_log = True self._populate_from_log() if displayed_log: self.setFocus(self.LISTCONTROL) else: command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8( language(30103)), smartUTF8( language(30104)), 6000, smartUTF8(addonicon)) xbmc.executebuiltin(command)
def _generate_hashlist( self ): hashmap = self._get_artists_hashmap() hashmap_str = '' for key, value in hashmap.iteritems(): hashmap_str = hashmap_str + value + '\t' + key + '\n' success, log_line = writeFile( hashmap_str, self.HASHLISTFILE ) if success: lw.log( log_line ) message = smartUTF8( language(30311) ) else: lw.log( ['unable to write has list file out to disk'] ) message = smartUTF8( language(30312) )
def _get_artists_hashmap( self ): #gets a list of all the artists from XBMC pDialog = DialogProgressBG() pDialog.create( smartUTF8(language(32001)), smartUTF8(language(30301)) ) hashmap = _ordereddict() response = xbmc.executeJSONRPC ( '{"jsonrpc":"2.0", "method":"AudioLibrary.GetArtists", "params":{"albumartistsonly":false, "sort":{"order":"ascending", "ignorearticle":true, "method":"artist"}},"id": 1}}' ) try: artists_info = _json.loads(response)['result']['artists'] except (IndexError, KeyError, ValueError): artists_info = [] except Exception, e: lw.log( ['unexpected error getting JSON back from XBMC', e] ) artists_info = []
def _parse_musicbrainz_info( self, type, mbid, playing_thing, query_times ): if self._playback_stopped_or_changed(): return False lw.log( ["checking this artist's " + type + "s against currently playing " + type] ) mboptions = {"artist":mbid, "limit":"100", "fmt":"json"} for thing in self._get_musicbrainz_info( mboptions, '', type + 's', type + 's', query_times ): title = smartUTF8( thing['title'] ) if playing_thing.rfind('(') > 0: playing_title = smartUTF8( playing_thing[:playing_thing.rfind('(')-2] ) else: playing_title = smartUTF8( playing_thing ) lw.log( ['comparing musicbrainz %s: %s with local %s: %s' % (type, title, type, playing_title)] ) if title.lower().startswith( playing_title.lower() ) or playing_title.lower().startswith( title.lower() ): lw.log( ['found matching %s, this should be the right artist' % type] ) return True return False
def __init__( self ): self._init_vars() self._get_settings() self._make_dirs() if self.HASHLIST == 'false' and self.MIGRATE == 'false': command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8(language(30350)), smartUTF8(language(30351)), 5000, smartUTF8(addonicon)) xbmc.executebuiltin(command) return if self.HASHLIST == 'true' and self.HASHLISTFOLDER: self._generate_hashlist() elif self.HASHLIST == 'true' and not self.HASHLISTFOLDER: command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8(language(30340)), smartUTF8(language(30341)), 5000, smartUTF8(addonicon)) xbmc.executebuiltin(command) if self.MIGRATE == 'true' and self.MIGRATEFOLDER: self._migrate() elif self.MIGRATE == 'true' and not self.MIGRATEFOLDER: command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8(language(30320)), smartUTF8(language(30321)), 5000, smartUTF8(addonicon)) xbmc.executebuiltin(command)
def _get_local_images( self ): self.LocalImagesFound = False if not self.NAME: lw.log( ['no artist name provided'] ) return self.CacheDir = os.path.join( self.LOCALARTISTPATH, smartUTF8(self.NAME).decode('utf-8'), self.FANARTFOLDER ) lw.log( ['cachedir = %s' % self.CacheDir] ) try: dirs, files = xbmcvfs.listdir( self.CacheDir ) except OSError: files = [] except Exception, e: lw.log( ['unexpected error getting directory list', e] ) files = []
def _merge_images( self ): lw.log( ['merging files from primary directory %s into merge directory %s' % (self.CacheDir, self.MergeDir)] ) self.MergedImagesFound = True dirs, files = xbmcvfs.listdir(self.CacheDir) for file in files: if(file.lower().endswith('tbn') or file.lower().endswith('jpg') or file.lower().endswith('jpeg') or file.lower().endswith('gif') or file.lower().endswith('png')): xbmcvfs.copy(os.path.join(self.CacheDir, smartUTF8(file).decode('utf-8')), os.path.join(self.MergeDir, smartUTF8(file).decode('utf-8'))) if self.ARTISTNUM == self.TOTALARTISTS: wait_elapsed = time.time() - self.LASTARTISTREFRESH if( wait_elapsed > self.MINREFRESH ): self._wait( self.MINREFRESH - (wait_elapsed % self.MINREFRESH) ) else: self._wait( self.MINREFRESH - (wait_elapsed + 2) ) #not sure why there needs to be a manual adjustment here if not self._playback_stopped_or_changed(): lw.log( ['switching slideshow to merge directory'] ) self._set_artwork_skininfo( self.MergeDir )
def _populate_from_all_logs( self ): lw.log( ['reset the window to prep it for data'] ) self.LISTCONTROL.reset() displayed_log = False for title, logfile in self._get_log_files(): self.LOGFILE = logfile if title: item = xbmcgui.ListItem( label=title ) item.setProperty( 'istitle','true' ) self.LISTCONTROL.addItem( item ) if xbmcvfs.exists( logfile ): displayed_log = True self._populate_from_log() if displayed_log: self.setFocus( self.LISTCONTROL ) else: command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8(__language__(30103)), smartUTF8(__language__(30104)), 6000, smartUTF8(__addonicon__)) xbmc.executebuiltin( command )
def _populate_from_all_logs( self ): lw.log( ['reset the window to prep it for data'] ) self.LISTCONTROL.reset() displayed_log = False #if there is an external script defined, call it if self.EXTERNALSCRIPT: lw.log( ['trying to execute external script to generate log file'] ) result, loglines = popenWithTimeout( self.EXTERNALSCRIPT, self.EXTERNALTIMEOUT ) lw.log( loglines ) for title, logfile in self._get_log_files(): self.LOGFILE = logfile if title: item = xbmcgui.ListItem( label=title ) item.setProperty( 'istitle','true' ) self.LISTCONTROL.addItem( item ) if xbmcvfs.exists( logfile ): displayed_log = True self._populate_from_log() if displayed_log: self.setFocus( self.LISTCONTROL ) else: command = 'XBMC.Notification(%s, %s, %s, %s)' % ( smartUTF8( language( 30103 ) ), smartUTF8( language( 30104 ) ), 6000, smartUTF8( addonicon ) ) xbmc.executebuiltin( command )
def _migrate( self ): lw.log( ['attempting to %s images from Artist Slideshow cache directory' % self.MIGRATETYPE] ) test_str = '' hashmap = self._get_artists_hashmap() try: folders, throwaway = xbmcvfs.listdir( self.ASCACHEFOLDER ) except OSError: lw.log( ['no directory found: ' + self.ASCACHEFOLDER] ) return except Exception, e: lw.log( ['unexpected error while getting directory list', e] ) return pDialog = DialogProgressBG() pDialog.create( smartUTF8(language(32003)), smartUTF8(language(30301)) ) total = len( folders ) count = 1 for folder in folders: try: artist_start = hashmap[folder] except KeyError: lw.log( ['no matching artist folder for: ' + folder] ) artist_start = '' except Exception, e: lw.log( ['unexpected error while finding matching artist for ' + folder, e] ) artist_start = '' if artist_start: pDialog.update(int(100*(count/total)), smartUTF8( language(32003) ), smartUTF8( artist_start ) ) if self.ENABLEFUZZYSEARCH == 'true': artist_name = ''
def _start_download( self ): self.CachedImagesFound = False self.DownloadedFirstImage = False self.DownloadedAllImages = False self.ImageDownloaded = False self.FirstImage = True cached_image_info = False if not self.NAME: lw.log( ['no artist name provided'] ) return if self.PRIORITY == '2' and self.LocalImagesFound: pass #self.CacheDir was successfully set in _get_local_images else: self._set_cachedir( self.NAME ) lw.log( ['cachedir = %s' % self.CacheDir] ) if self.ARTISTNUM == 1: self._get_artistinfo() dirs, files = xbmcvfs.listdir(self.CacheDir) for file in files: if (file.lower().endswith('tbn') or file.lower().endswith('jpg') or file.lower().endswith('jpeg') or file.lower().endswith('gif') or file.lower().endswith('png')) or (self.PRIORITY == '2' and self.LocalImagesFound): self.CachedImagesFound = True if self.CachedImagesFound: lw.log( ['cached images found'] ) cached_image_info = True self.LASTARTISTREFRESH = time.time() if self.ARTISTNUM == 1: self._set_artwork_skininfo( self.CacheDir ) else: self.LASTARTISTREFRESH = 0 if self.ARTISTNUM == 1: if self.NOTIFICATIONTYPE == "1": self._set_property("ArtistSlideshow", self.InitDir) command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8(language(30300)), smartUTF8(language(30301)), 5000, smartUTF8(addonicon)) xbmc.executebuiltin(command) elif self.NOTIFICATIONTYPE == "2": self._set_property("ArtistSlideshow", self.PROGRESSPATH) else: self._set_property("ArtistSlideshow", self.InitDir) lw.log( ['downloading images'] ) folders, cachelist = xbmcvfs.listdir( self.CacheDir ) cachelist_str = ''.join(str(e) for e in cachelist) for url in self._get_image_list(): lw.log( ['the url to check is ' + url] ) if( self._playback_stopped_or_changed() ): return path = itemHashwithPath( url, self.CacheDir ) path2 = itemHashwithPath( url, self.TransitionDir ) checkpath, checkfilename = os.path.split( path ) if not (checkfilename in cachelist_str): if self._download(url, path, path2): lw.log( ['downloaded %s to %s' % (url, path)] ) self.ImageDownloaded = True if self.ImageDownloaded: if( self._playback_stopped_or_changed() and self.ARTISTNUM == 1 ): self._set_artwork_skininfo( self.CacheDir ) self.LASTARTISTREFRESH = time.time() self._clean_dir( self.TransitionDir ) return if not self.CachedImagesFound: self.CachedImagesFound = True wait_elapsed = time.time() - self.LASTARTISTREFRESH if( wait_elapsed > self.MINREFRESH ): if( not (self.FirstImage and not self.CachedImagesFound) ): self._wait( self.MINREFRESH - (wait_elapsed % self.MINREFRESH) ) if( not self._playback_stopped_or_changed() and self.ARTISTNUM == 1 ): self._refresh_image_directory() self.FirstImage = False if self.ImageDownloaded: lw.log( ['finished downloading images'] ) self.DownloadedAllImages = True if( self._playback_stopped_or_changed() ): self._set_artwork_skininfo( self.CacheDir ) self.LASTARTISTREFRESH = time.time() self._clean_dir( self.TransitionDir ) return lw.log( ['cleaning up from refreshing slideshow'] ) wait_elapsed = time.time() - self.LASTARTISTREFRESH if( wait_elapsed < self.MINREFRESH ): self._wait( self.MINREFRESH - wait_elapsed ) if( not self._playback_stopped_or_changed() ): if self.ARTISTNUM == 1: self._refresh_image_directory() if self.NOTIFICATIONTYPE == "1" and not cached_image_info: command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8(language(30304)), smartUTF8(language(30305)), 5000, smartUTF8(addonicon)) xbmc.executebuiltin(command) if self.TOTALARTISTS > 1: self._merge_images() if( self._get_infolabel( self.ARTISTSLIDESHOW ).decode('utf-8') == self.TransitionDir and self.ARTISTNUM == 1): self._wait( self.MINREFRESH ) if( not self._playback_stopped_or_changed() ): self._refresh_image_directory() self._clean_dir( self.TransitionDir ) if not self.ImageDownloaded: lw.log( ['no images downloaded'] ) self.DownloadedAllImages = True if not self.CachedImagesFound: if self.ARTISTNUM == 1: lw.log( ['setting slideshow directory to blank directory'] ) self._set_property("ArtistSlideshow", self.InitDir) if self.NOTIFICATIONTYPE == "1" and not cached_image_info: command = 'XBMC.Notification(%s, %s, %s, %s)' % (smartUTF8(language(30302)), smartUTF8(language(30303)), 10000, smartUTF8(addonicon)) xbmc.executebuiltin(command) elif self.TOTALARTISTS > 1: self._merge_images()
def _get_artistinfo( self ): bio = '' bio_params = {} bio_params['mbid'] = self.MBID bio_params['infodir'] = self.InfoDir bio_params['localartistdir'] = os.path.join( self.LOCALARTISTPATH, smartUTF8(self.NAME).decode('utf-8') ) bio_params['lang'] = self.LANGUAGE bio_params['artist'] = self.NAME bio = '' try: bio_plugins['names'].sort( key=lambda x: x[0] ) except TypeError: pass for plugin_name in bio_plugins['names']: lw.log( ['checking %s for bio' % plugin_name[1]] ) bio, loglines = bio_plugins['objs'][plugin_name[1]].getBio( bio_params ) lw.log( loglines ) if bio: lw.log( ['got a bio from %s, so stop looking' % plugin_name] ) break if bio: self.biography = self._clean_text(bio) else: self.biography = '' album_params = {} album_params['infodir'] = self.InfoDir album_params['localartistdir'] = os.path.join( self.LOCALARTISTPATH, smartUTF8(self.NAME).decode('utf-8') ) album_params['lang'] = self.LANGUAGE album_params['artist'] = self.NAME albums = [] try: album_plugins['names'].sort( key=lambda x: x[0] ) except TypeError: pass for plugin_name in album_plugins['names']: lw.log( ['checking %s for album info' % plugin_name[1]] ) albums, loglines = album_plugins['objs'][plugin_name[1]].getAlbumList( album_params ) lw.log( loglines ) if not albums == []: lw.log( ['got album list from %s, so stop looking' % plugin_name] ) break if albums == []: self.albums = [] else: self.albums = albums similar_params = {} similar_params['infodir'] = self.InfoDir similar_params['localartistdir'] = os.path.join( self.LOCALARTISTPATH, smartUTF8(self.NAME).decode('utf-8') ) similar_params['lang'] = self.LANGUAGE similar_params['artist'] = self.NAME similar_artists = [] try: similar_plugins['names'].sort( key=lambda x: x[0] ) except TypeError: pass for plugin_name in similar_plugins['names']: lw.log( ['checking %s for similar artist info' % plugin_name[1]] ) similar_artists, loglines = similar_plugins['objs'][plugin_name[1]].getSimilarArtists( similar_params ) lw.log( loglines ) if not similar_artists == []: lw.log( ['got similar artist list from %s, so stop looking' % plugin_name] ) break if similar_artists == []: self.similar = [] else: self.similar = similar_artists self._set_properties()
def _move_info_files( self, old_loc, new_loc, type ): lw.log( ['attempting to move from %s to %s' % (old_loc, new_loc)] ) try: folders, fls = xbmcvfs.listdir( old_loc ) except OSError: lw.log( ['no directory found: ' + old_loc] ) return except Exception, e: lw.log( ['unexpected error while getting directory list', e] ) return for folder in folders: if type == 'cache': old_folder = os.path.join( old_loc, folder ) new_folder = os.path.join( new_loc, folder ) elif type == 'local': old_folder = os.path.join( old_loc, smartUTF8(folder).decode('utf-8'), self.FANARTFOLDER ) new_folder = os.path.join( new_loc, itemHash(folder) ) try: dirs, old_files = xbmcvfs.listdir( old_folder ) except Exception, e: lw.log( ['unexpected error while getting directory list', e] ) old_files = [] exclude_path = os.path.join( old_folder, '_exclusions.nfo' ) if old_files and type == 'cache' and not xbmcvfs.exists(exclude_path): success, loglines = writeFile( '', exclude_path ) lw.log( loglines ) for old_file in old_files: if old_file.endswith( '.nfo' ) and not old_file == '_exclusions.nfo': exists, loglines = checkPath( new_folder ) lw.log( loglines ) new_file = old_file.strip('_')