def update_xbmc_thumbnails( background=False ): log( "Updating Thumbnails/fanart Images", xbmc.LOGNOTICE ) fanart = "fanart.jpg" artistthumb_temp = "artist.jpg" artistthumb = "folder.jpg" albumthumb = "folder.jpg" #xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ( __language__(32042), __language__(32112), 2000, image) ) xbmc.sleep( 1000 ) dialog_msg( "create", heading = __language__( 32042 ), background = background ) # Artists artists = get_local_artists_db( mode="local_artists" ) if not artists: artists = get_local_artists_db( mode="album_artists" ) # Albums albums = get_local_albums_db( "all artists", False ) percent = 1 count = 0 for artist in artists: percent = percent = int( ( count/float( len( artists ) ) ) * 100 ) count += 1 if percent == 0: percent = 1 if percent > 100: percent = 100 if dialog_msg( "iscanceled" ): break dialog_msg( "update", percent = percent, line1 = __language__( 32112 ), line2 = " %s %s" % ( __language__( 32038 ), getunicode( artist["name"] ) ), background = background ) xbmc_thumbnail_path = "" xbmc_fanart_path = "" fanart_path = os.path.join( music_path, change_characters( artist["name"] ), fanart ).replace( "\\\\","\\" ) artistthumb_path = os.path.join( music_path, change_characters( artist["name"] ), artistthumb ).replace( "\\\\","\\" ) artistthumb_rename = os.path.join( music_path, change_characters( artist["name"] ), artistthumb_temp ).replace( "\\\\","\\" ) if exists( artistthumb_rename ): file_rename( artistthumb_rename, artistthumb_path ) if exists( fanart_path ): xbmc_fanart_path = get_fanart_path( artist["local_id"], "artist" ) elif exists( artistthumb_path ): xbmc_thumbnail_path = get_thumbnail_path( artist["local_id"], "artist" ) else: continue if xbmc_fanart_path: # copy to XBMC supplied fanart path thumbnail_copy( fanart_path, xbmc_fanart_path, "fanart" ) if xbmc_thumbnail_path: # copy to XBMC supplied artist image path thumbnail_copy( artistthumb_path, xbmc_thumbnail_path, "artist thumb" ) percent = 1 count = 1 for album in albums: percent = percent = int( ( count/float( len( albums ) ) ) * 100 ) if percent < 1: percent = 1 if percent > 100: percent = 100 if dialog_msg( "iscanceled" ): break dialog_msg( "update", percent = percent, line1 = __language__( 32042 ), line2 = __language__( 32112 ), line3 = " %s %s" % ( __language__( 32039 ), getunicode( album["title"] ) ), background = background ) xbmc_thumbnail_path = "" coverart_path = os.path.join( album["path"], albumthumb ).replace( "\\\\","\\" ) if exists( coverart_path ): xbmc_thumbnail_path = get_thumbnail_path( album["local_id"], "album" ) if xbmc_thumbnail_path: thumbnail_copy( coverart_path, xbmc_thumbnail_path, "album cover" ) count += 1 log( "Finished Updating Thumbnails/fanart Images", xbmc.LOGNOTICE )
def download_art( url_cdart, album, database_id, type, mode, size, background = False ): log( "Downloading artwork... ", xbmc.LOGDEBUG ) download_success = False thumb_path = "" percent = 1 is_canceled = False if mode == "auto": dialog_msg( "update", percent = percent, background = background ) else: dialog_msg( "create", heading = __language__(32047), background = background ) #Onscreen Dialog - "Downloading...." file_name = get_filename( type, url_cdart, mode ) #Helix: paths MUST end with trailing slash path = os.path.join(album["path"].replace( "\\\\" , "\\" ), '') if file_name == "unknown": log( "Unknown Type ", xbmc.LOGDEBUG ) message = [ __language__(32026), __language__(32025), "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart ) ] return message, download_success if type in ( "artistthumb", "cover" ): thumbnail_path = get_thumbnail_path( database_id, type ) else: thumbnail_path = "" if type == "fanart" and mode in ( "manual", "single" ): thumbnail_path = get_fanart_path( database_id, type ) if not exists( path ): try: pathsuccess = _makedirs( album["path"].replace( "\\\\" , "\\" ) ) except: pass log( "Path: %s" % path, xbmc.LOGDEBUG ) log( "Filename: %s" % file_name, xbmc.LOGDEBUG ) log( "url: %s" % url_cdart, xbmc.LOGDEBUG ) # cosmetic: use subfolder for downloading instead of work folder if not exists( os.path.join(tempgfx_folder, '').replace( "\\\\","\\" )): _makedirs(os.path.join(tempgfx_folder, '').replace( "\\\\","\\" )) destination = os.path.join(tempgfx_folder, file_name).replace( "\\\\","\\" ) # download to work folder first final_destination = os.path.join( path, file_name ).replace( "\\\\","\\" ) try: #this give the ability to use the progress bar by retrieving the downloading information #and calculating the percentage def _report_hook( count, blocksize, totalsize ): try: percent = int( float( count * blocksize * 100 ) / totalsize ) if percent < 1: percent = 1 if percent > 100: percent = 100 except: percent = 1 if type in ( "fanart", "clearlogo", "artistthumb", "musicbanner" ): dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038) , get_unicode( album["artist"] ) ), background = background ) else: dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038) , get_unicode( album["artist"] ) ), line2 = "%s%s" % ( __language__(32039) , get_unicode( album["title"] ) ), background = background ) if mode == "auto": if dialog_msg( "iscanceled", background = background ): is_canceled = True if exists( path ): fp, h = urllib.urlretrieve(url_cdart, destination, _report_hook) #message = ["Download Sucessful!"] message = [__language__(32023), __language__(32024), "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart )] success = file_copy( destination, final_destination ) # copy it to album folder # update database try: conn = sqlite3.connect(addon_db) c = conn.cursor() if type == "cdart": c.execute('''UPDATE alblist SET cdart="True" WHERE path="%s"''' % ( get_unicode( album["path"] ) ) ) elif type == "cover": c.execute('''UPDATE alblist SET cover="True" WHERE path="%s"''' % ( get_unicode( album["path"] ) ) ) conn.commit() c.close() except: log( "Error updating database", xbmc.LOGDEBUG ) print_exc() download_success = True else: log( "Path error", xbmc.LOGDEBUG ) log( " file path: %s" % repr( destination ), xbmc.LOGDEBUG ) message = [ __language__(32026), __language__(32025) , "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart ) ] #message = Download Problem, Check file paths - Artwork Not Downloaded] # always cleanup downloaded files #if type == "fanart": delete_file( destination ) except: log( "General download error", xbmc.LOGDEBUG ) message = [ __language__(32026), __language__(32025), "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart ) ] #message = [Download Problem, Check file paths - Artwork Not Downloaded] print_exc() if mode == "auto" or mode == "single": return message, download_success, final_destination, is_canceled # returns one of the messages built based on success or lack of else: dialog_msg( "close", background = background ) return message, download_success, is_canceled
def update_xbmc_thumbnails(background=False): log("Updating Thumbnails/fanart Images", xbmc.LOGNOTICE) fanart = "fanart.jpg" artistthumb_temp = "artist.jpg" artistthumb = "folder.jpg" albumthumb = "folder.jpg" #xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ( __language__(32042), __language__(32112), 2000, image) ) xbmc.sleep(1000) dialog_msg("create", heading=__language__(32042), background=background) # Artists artists = get_local_artists_db(mode="local_artists") if not artists: artists = get_local_artists_db(mode="album_artists") # Albums albums = get_local_albums_db("all artists", False) percent = 1 count = 0 for artist in artists: percent = percent = int((count / float(len(artists))) * 100) count += 1 if percent == 0: percent = 1 if percent > 100: percent = 100 if dialog_msg("iscanceled"): break dialog_msg("update", percent=percent, line1=__language__(32112), line2=" %s %s" % (__language__(32038), getunicode(artist["name"])), background=background) xbmc_thumbnail_path = "" xbmc_fanart_path = "" fanart_path = os.path.join(music_path, change_characters(artist["name"]), fanart).replace("\\\\", "\\") artistthumb_path = os.path.join(music_path, change_characters(artist["name"]), artistthumb).replace("\\\\", "\\") artistthumb_rename = os.path.join(music_path, change_characters(artist["name"]), artistthumb_temp).replace( "\\\\", "\\") if exists(artistthumb_rename): file_rename(artistthumb_rename, artistthumb_path) if exists(fanart_path): xbmc_fanart_path = get_fanart_path(artist["local_id"], "artist") elif exists(artistthumb_path): xbmc_thumbnail_path = get_thumbnail_path(artist["local_id"], "artist") else: continue if xbmc_fanart_path: # copy to XBMC supplied fanart path thumbnail_copy(fanart_path, xbmc_fanart_path, "fanart") if xbmc_thumbnail_path: # copy to XBMC supplied artist image path thumbnail_copy(artistthumb_path, xbmc_thumbnail_path, "artist thumb") percent = 1 count = 1 for album in albums: percent = percent = int((count / float(len(albums))) * 100) if percent < 1: percent = 1 if percent > 100: percent = 100 if dialog_msg("iscanceled"): break dialog_msg("update", percent=percent, line1=__language__(32042), line2=__language__(32112), line3=" %s %s" % (__language__(32039), getunicode(album["title"])), background=background) xbmc_thumbnail_path = "" coverart_path = os.path.join(album["path"], albumthumb).replace("\\\\", "\\") if exists(coverart_path): xbmc_thumbnail_path = get_thumbnail_path(album["local_id"], "album") if xbmc_thumbnail_path: thumbnail_copy(coverart_path, xbmc_thumbnail_path, "album cover") count += 1 log("Finished Updating Thumbnails/fanart Images", xbmc.LOGNOTICE)