Exemplo n.º 1
0
def check_fanart_new_artwork(present_datecode):
    '''This function returns True if fanart.tv has new artwork, False if not.
       Also it returns the JSON Data'''
    log("Checking for new Artwork on fanart.tv since last run...",
        xbmc.LOGNOTICE)
    previous_datecode = retrieve_fanarttv_datecode()
    # fix: use global tempxml_folder instead of explicit definition
    if xbmcvfs.exists(
            os.path.join(tempxml_folder, "%s.xml" % previous_datecode)):
        xbmcvfs.delete(
            os.path.join(tempxml_folder, "%s.xml" % previous_datecode))
    url = new_music % (api_key, str(previous_datecode))
    htmlsource = (get_html_source(url,
                                  str(present_datecode),
                                  save_file=True,
                                  overwrite=False)).encode('utf-8', 'ignore')
    if htmlsource == "null":
        log("No new Artwork found on fanart.tv", xbmc.LOGNOTICE)
        return False, htmlsource
    else:
        try:
            log("New Artwork found on fanart.tv", xbmc.LOGNOTICE)
            data = simplejson.loads(htmlsource)
            return True, data
        except:
            htmlsource = "null"
            print_exc()
            return False, htmlsource
def get_recognized( all_artists, album_artists, background=False ):
    log( "Checking for artist match with fanart.tv - Get Recognized artists", xbmc.LOGNOTICE )
    album_artists_matched = []
    all_artists_matched = []
    true = 0
    count = 0
    name = ""
    artist_list = []
    all_artist_list = []
    fanart_test = ""
    previous_datecode = retrieve_fanarttv_datecode()
    d = datetime.utcnow()
    present_datecode = calendar.timegm( d.utctimetuple() )
    dialog_msg( "create", heading = "", background = background )
    new_artwork, data = check_fanart_new_artwork( present_datecode )
    if new_artwork:
        for artist in album_artists:
            percent = int( ( float( count )/len( album_artists ) )*100 )
            log( "Checking artist MBID: %s" % artist[ "musicbrainz_artistid" ], xbmc.LOGDEBUG )
            match = {}
            match = artist
            if match[ "musicbrainz_artistid" ]:
                match[ "has_art" ] = update_art( match[ "musicbrainz_artistid" ], data, artist[ "has_art" ] )
            album_artists_matched.append( match )
            dialog_msg( "update", percent = percent, line1 = __language__( 32185 ), line2 = "", line3 =  __language__( 32049 ) % artist[ "name" ], background = background )
            count += 1
        if enable_all_artists and all_artists:
            count = 0
            for artist in all_artists:
                percent = int( ( float( count )/len( all_artists ) )*100 )
                log( "Checking artist MBID: %s" % artist[ "musicbrainz_artistid" ], xbmc.LOGDEBUG )
                match = {}
                match = artist
                if match[ "musicbrainz_artistid" ]:
                    match[ "has_art" ] = update_art( match[ "musicbrainz_artistid" ], data,  artist[ "has_art" ] )
                all_artists_matched.append( match )
                dialog_msg( "update", percent = percent, line1 = __language__( 32185 ), line2 = "", line3 =  __language__( 32049 ) % artist[ "name" ], background = background )
                count += 1
    else:
        log( "No new music artwork on fanart.tv",  xbmc.LOGNOTICE )
        album_artists_matched = album_artists
        all_artists_matched = all_artists
    store_lalist( album_artists_matched, len( album_artists_matched ) )
    store_local_artist_table( all_artists_matched, background = background )
    store_fanarttv_datecode( present_datecode )
    dialog_msg( "close", background = background )
    log( "Finished Getting Recognized Artists", xbmc.LOGDEBUG )
    return all_artists_matched, album_artists_matched
def check_fanart_new_artwork( present_datecode ):
    '''This function returns True if fanart.tv has new artwork, False if not.
       Also it returns the JSON Data'''
    log( "Checking for new Artwork on fanart.tv since last run...", xbmc.LOGNOTICE )
    previous_datecode = retrieve_fanarttv_datecode()
    if xbmcvfs.exists( os.path.join( addon_work_folder, "tempxml", "%s.xml" % previous_datecode ) ):
        xbmcvfs.delete( os.path.join( addon_work_folder, "tempxml", "%s.xml" % previous_datecode ) )
    url = new_music % ( api_key, str( previous_datecode ) )
    htmlsource = ( get_html_source( url, str( present_datecode ), save_file = True, overwrite = False ) ).encode( 'utf-8', 'ignore' )
    if htmlsource == "null":
        log( "No new Artwork found on fanart.tv", xbmc.LOGNOTICE )
        return False, htmlsource
    else:
        try:
            log( "New Artwork found on fanart.tv", xbmc.LOGNOTICE )
            data = simplejson.loads( htmlsource )
            return True, data
        except:
            htmlsource = "null"
            print_exc()
            return False, htmlsource