Example #1
0
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 )
Example #2
0
def auto_download( type, artist_list, background=False ):
    is_canceled = False
    log( "Autodownload", xbmc.LOGDEBUG )
    try:
        artist_count = 0
        download_count = 0
        cdart_existing = 0
        album_count = 0
        d_error=False
        percent = 1
        successfully_downloaded = []
        if type in ( "clearlogo_allartists", "artistthumb_allartists", "fanart_allartists", "musicbanner_allartists" ):
            if type == "clearlogo_allartists":
                type = "clearlogo"
            elif type == "artistthumb_allartists":
                type = "artistthumb"
            elif type == "musicbanner_allartists":
                type = "musicbanner"
            else:
                type = "fanart"
        count_artist_local = len( artist_list )
        dialog_msg( "create", heading = __language__(32046), background = background )
        #Onscreen Dialog - Automatic Downloading of Artwork
        key_label = type
        for artist in artist_list:
            low_res = True
            if dialog_msg( "iscanceled", background = background ) or is_canceled:
                is_canceled = True
                break
            artist_count += 1
            if not artist["has_art"] == "True":
            # If fanart.tv does not report that it has an artist match skip it.
                continue
            percent = int( (artist_count / float(count_artist_local) ) * 100)
            if percent < 1:
                percent = 1
            if percent > 100:
                percent = 100
            log( "Artist: %-40s Local ID: %-10s   Distant MBID: %s" % ( artist["name"], artist["local_id"], artist["musicbrainz_artistid"] ), xbmc.LOGNOTICE )
            if type in ( "fanart", "clearlogo", "artistthumb", "musicbanner" ) and artist[ "has_art" ]:
                dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038), get_unicode( artist["name"] ) ), background = background )
                auto_art = {}
                temp_art = {}
                temp_art["musicbrainz_artistid"] = artist["musicbrainz_artistid"]
                auto_art["musicbrainz_artistid"] = artist["musicbrainz_artistid"]
                temp_art["artist"] = artist["name"]
                auto_art["artist"] = artist["name"]
                path = os.path.join( music_path, change_characters( smart_unicode( artist["name"] ) ) )
                if type == "fanart":
                    art = remote_fanart_list( auto_art )
                elif type == "clearlogo":
                    art = remote_clearlogo_list( auto_art )
                    arthd = remote_hdlogo_list( auto_art )
                elif type == "musicbanner":
                    art = remote_banner_list( auto_art )
                else:
                    art = remote_artistthumb_list( auto_art )
                if art:
                    if type == "fanart":
                        temp_art["path"] = path
                        auto_art["path"] = os.path.join( path, "extrafanart" ).replace( "\\\\" , "\\" )
                        if not exists( auto_art["path"] ):
                            try:
                                if _makedirs( auto_art["path"] ):
                                    log( "extrafanart directory made", xbmc.LOGDEBUG )
                            except:
                                print_exc()
                                log( "unable to make extrafanart directory", xbmc.LOGDEBUG )
                                continue
                        else:
                            log( "extrafanart directory already exists", xbmc.LOGDEBUG )
                    else:
                        auto_art["path"] = path
                    if type == "fanart":
                        if enable_fanart_limit:
                            fanart_dir, fanart_files = listdir( auto_art["path"] )
                            fanart_number = len( fanart_files )
                            if fanart_number == fanart_limit:
                                continue
                        if not exists( os.path.join( path, "fanart.jpg" ).replace( "\\\\", "\\" ) ):
                            message, d_success, final_destination, is_canceled = download_art( art[0], temp_art, artist["local_id"], "fanart", "single", 0, background )
                        for artwork in art:
                            fanart = {}
                            if enable_fanart_limit and fanart_number == fanart_limit:
                                log( "Fanart Limit Reached", xbmc.LOGNOTICE )
                                continue
                            if exists( os.path.join( auto_art["path"], os.path.basename( artwork ) ) ):
                                log( "Fanart already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork, auto_art, artist["local_id"], "fanart", "auto", 0, background )
                            if d_success == 1:
                                if enable_fanart_limit:
                                    fanart_number += 1
                                download_count += 1
                                fanart["artist"] = auto_art["artist"]
                                fanart["path"] = final_destination
                                successfully_downloaded.append( fanart )
                            else:
                                log( "Download Error...  Check Path.", xbmc.LOGDEBUG )
                                log( "    Path: %s" % auto_art["path"], xbmc.LOGDEBUG )
                                d_error = True
                    else:
                        if type == "clearlogo":
                            if arthd and enable_hdlogos:
                                artwork = arthd[0]
                            else:
                                artwork = art[0]
                        else:
                            artwork = art[0]
                        if type == "artistthumb":
                            if resizeondownload:
                                low_res = check_size( auto_art["path"], key_label, 1000, 1000 )
                            # Fixed always redownloading Thumbs
                            else:
                                low_res = False
                            if exists( os.path.join( auto_art["path"], "folder.jpg" ) ) and not low_res:
                                log( "Artist Thumb already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork , auto_art, artist["local_id"], "artistthumb", "auto", 0, background )
                        elif type == "clearlogo":
                            if enable_hdlogos and resizeondownload and arthd:
                                low_res = check_size( auto_art["path"], key_label, 800, 310 )
                            else:
                                low_res = False
                            if exists( os.path.join( auto_art["path"], "logo.png" ) ) and not low_res:
                                log( "ClearLOGO already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork , auto_art, artist["local_id"], "clearlogo", "auto", 0, background )
                        elif type == "musicbanner":
                            if exists( os.path.join( auto_art["path"], "banner.jpg" ) ):
                                log( "Music Banner already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork , auto_art, artist["local_id"], "musicbanner", "auto", 0, background )
                        if d_success == 1:
                            download_count += 1
                            auto_art["path"] = final_destination
                            successfully_downloaded.append( auto_art )
                        else:
                            log( "Download Error...  Check Path.", xbmc.LOGDEBUG )
                            log( "    Path: %s" % auto_art["path"], xbmc.LOGDEBUG )
                            d_error = True
                else :
                        log( "Artist Match not found", xbmc.LOGDEBUG )
            elif type in ( "cdart", "cover" ) and artist[ "has_art" ]:
                local_album_list = get_local_albums_db( artist["name"], background )
                if type == "cdart":
                    remote_art_url = remote_cdart_list( artist )
                else:
                    remote_art_url = remote_coverart_list( artist )
                for album in local_album_list:
                    low_res = True
                    if dialog_msg( "iscanceled", background = background ):
                            break
                    if not remote_art_url:
                        log( "No artwork found", xbmc.LOGDEBUG )
                        break
                    album_count += 1
                    if not album["musicbrainz_albumid"]:
                        continue
                    dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038) , get_unicode( artist["name"] ) ), line2 = "%s%s" % (__language__(32039) , get_unicode( album["title"] ) ), background = background )
                    name = artist["name"]
                    title = album["title"]
                    log( "Album: %s" % album["title"], xbmc.LOGDEBUG )
                    if not album[key_label] or resizeondownload:
                        musicbrainz_albumid = album["musicbrainz_albumid"]
                        art = artwork_search( remote_art_url, musicbrainz_albumid, album["disc"], key_label )
                        if art:
                            if resizeondownload:
                                low_res = check_size( album["path"].replace( "\\\\", "\\" ), key_label, art["size"], art["size"] )
                            if art["picture"]: 
                                log( "ALBUM MATCH ON FANART.TV FOUND", xbmc.LOGDEBUG )
                                #log( "test_album[0]: %s" % test_album[0], xbmc.LOGDEBUG )
                                if low_res:
                                    message, d_success, final_destination, is_canceled = download_art( art["picture"], album, album["local_id"], key_label, "auto", 0, background )
                                    if d_success == 1:
                                        download_count += 1
                                        album[key_label] = True
                                        album["path"] = final_destination
                                        successfully_downloaded.append( album )
                                    else:
                                        log( "Download Error...  Check Path.", xbmc.LOGDEBUG )
                                        log( "    Path: %s" % repr( album["path"] ), xbmc.LOGDEBUG )
                                        d_error = True
                                else:
                                    pass
                            else:
                                log( "ALBUM NOT MATCHED ON FANART.TV", xbmc.LOGDEBUG )
                        else:
                            log( "ALBUM NOT MATCHED ON FANART.TV", xbmc.LOGDEBUG )
                    else:
                        log( "%s artwork file already exists, skipping..." % key_label, xbmc.LOGDEBUG )
        dialog_msg( "close", background = background )
        if d_error:
            dialog_msg( "ok", line1 = __language__(32026), line2 = "%s: %s" % ( __language__(32041), download_count ), background = background )
        else:
            dialog_msg( "ok", line1 = __language__(32040), line2 = "%s: %s" % ( __language__(32041), download_count ), background = background  )
        return download_count, successfully_downloaded
    except:
        print_exc()
        dialog_msg( "close", background = background )
Example #3
0
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)