def check_art( mbid, artist_type = "album" ):
    has_art = "False"
    url = music_url_json % ( api_key, str( mbid ), "all" )
    if artist_type == "album":
        htmlsource = ( get_html_source( url, str( mbid ), save_file = True, overwrite = True ) ).encode( 'utf-8', 'ignore' )
    else:
        htmlsource = ( get_html_source( url, str( mbid ), save_file = True, overwrite = True ) ).encode( 'utf-8', 'ignore' )
    if htmlsource == "null":
        log( "No artwork found for MBID: %s" % mbid, xbmc.LOGDEBUG )
        has_art = "False"
    else:
        log( "Artwork found for MBID: %s" % mbid, xbmc.LOGDEBUG )
        has_art = "True"
    return has_art
Exemplo n.º 2
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
Exemplo n.º 3
0
def get_musicbrainz_release_group(release_mbid):
    """ Retrieves the MusicBrainz Release Group MBID from a given release MBID
        
        Use:
            release_groupmbid = get_musicbrainz_release_group( release_mbid )
        
        release_mbid - valid release mbid
    """
    log("Retrieving MusicBrainz Release Group MBID from Album Release MBID",
        xbmc.LOGDEBUG)
    url = release_group_url_release_mbid % (server, quote_plus(release_mbid))
    mbid = ""
    htmlsource = get_html_source(url,
                                 release_mbid,
                                 save_file=False,
                                 overwrite=False)
    match = re.search(
        '''<release-group-list count="(?:.*?)">(.*?)</release-group-list>''',
        htmlsource)
    if match:
        mbid_match = re.search('''<release-group id="(.*?)"(?:.*?)">''',
                               match.group(1))
        if not mbid_match:
            mbid_match = re.search('''<release-group (?:.*?)id="(.*?)">''',
                                   match.group(1))
        if mbid_match:
            mbid = mbid_match.group(1)
    xbmc.sleep(mb_delay)
    return mbid
def update_art( mbid, data, existing_has_art ):
    has_art = existing_has_art
    for item in data:
        if item[ "id" ] == mbid:
            url = music_url_json % ( api_key, str( mbid ), "all" )
            has_art = "True"
            new_art = ( get_html_source( url, str( mbid ), save_file = True, overwrite = True ) ).encode( 'utf-8', 'ignore' )
            break
    return has_art
Exemplo n.º 5
0
def mbid_check(database_mbid, type):
    log("Looking up %s MBID. Current MBID: %s" % (type, database_mbid),
        xbmc.LOGNOTICE)
    new_mbid = ""
    mbid_match = False
    if type == "release-group":
        url = release_group_id_check % (server, database_mbid)
    elif type == "artist":
        url = artist_id_check % (server, database_mbid)
    htmlsource = get_html_source(url, "", save_file=False)
    if type == "release-group":
        match = re.search('''<release-group id="(.*?)"(?:.*?)>''', htmlsource)
        if match:
            new_mbid = match.group(1)
        else:
            match = re.search('''<release-group (?:.*?)id="(.*?)">''',
                              htmlsource)
            if match:
                new_mbid = match.group(1)
            else:
                match = re.search(
                    '''<release-group ext:score=(?:.*?)id="(.*?)">''',
                    htmlsource)
                if match:
                    new_mbid = match.group(1)
        if new_mbid == database_mbid:
            mbid_match = True
        else:
            mbid_match = False
    elif type == "artist":
        match = re.search('''<artist id="(.*?)"(?:.*?)>''', htmlsource)
        if match:
            new_mbid = match.group(1)
        else:
            match = re.search('''<artist(?:.*?)id="(.*?)">''', htmlsource)
            if match:
                new_mbid = match.group(1)
        if new_mbid == database_mbid:
            mbid_match = True
        else:
            mbid_match = False
    else:
        pass
    log("Current MBID: %s    New MBID: %s" % (database_mbid, new_mbid),
        xbmc.LOGDEBUG)
    if mbid_match:
        log("MBID is current. No Need to change", xbmc.LOGDEBUG)
    else:
        log("MBID is not current. Need to change", xbmc.LOGDEBUG)
    xbmc.sleep(mb_delay)
    return mbid_match, new_mbid
def mbid_check( database_mbid, type ):
    log( "Looking up %s MBID. Current MBID: %s" % ( type, database_mbid ), xbmc.LOGNOTICE )
    new_mbid = ""
    mbid_match = False
    if type == "release-group":
        url = release_group_id_check % ( server, database_mbid )
    elif type == "artist":
        url = artist_id_check % ( server, database_mbid )
    htmlsource = get_html_source( url, "", save_file = False)
    if type == "release-group":
        match = re.search( '''<release-group id="(.*?)"(?:.*?)>''', htmlsource )
        if match:
            new_mbid = match.group( 1 )
        else:
            match = re.search( '''<release-group (?:.*?)id="(.*?)">''', htmlsource )
            if match:
                new_mbid = match.group( 1 )
            else:
                match = re.search( '''<release-group ext:score=(?:.*?)id="(.*?)">''', htmlsource )
                if match:
                    new_mbid = match.group( 1 )
        if new_mbid == database_mbid:
            mbid_match = True
        else:
            mbid_match = False
    elif type == "artist":
        match = re.search( '''<artist id="(.*?)"(?:.*?)>''', htmlsource )
        if match:
            new_mbid = match.group( 1 )
        else:
            match = re.search( '''<artist(?:.*?)id="(.*?)">''', htmlsource )
            if match:
                new_mbid = match.group( 1 )
        if new_mbid == database_mbid:
            mbid_match = True
        else:
            mbid_match = False
    else:
        pass
    log( "Current MBID: %s    New MBID: %s" % ( database_mbid, new_mbid ), xbmc.LOGDEBUG )
    if mbid_match:
        log( "MBID is current. No Need to change", xbmc.LOGDEBUG )
    else:
        log( "MBID is not current. Need to change", xbmc.LOGDEBUG )
    xbmc.sleep( mb_delay )
    return mbid_match, new_mbid
Exemplo n.º 7
0
def get_musicbrainz_artist_id(artist_search, limit=1, alias=False):
    name = ""
    id = ""
    sortname = ""
    artist_name = smart_unicode(
        (artist_search.replace('"', '?').replace('&', 'and')))
    if not alias:
        url = artist_url % (server, quote_plus(
            artist_name.encode("utf-8")), limit)
    else:
        url = alias_url % (server, quote_plus(
            artist_name.encode("utf-8")), limit)
    htmlsource = get_html_source(url, "", save_file=False)
    match = re.search('''<artist(.*?)</artist>''', htmlsource)
    if match:
        score_match = re.search('''score="(.*?)"''', htmlsource)
        name_match = re.search('''<name>(.*?)</name>''', htmlsource)
        id_match = re.search('''<artist id="(.*?)"(?:.*?)>''', htmlsource)
        if not id_match:
            id_match = re.search('''<artist (?:.*?)id="(.*?)">''', htmlsource)
        sort_name_match = re.search('''<sort-name>(.*?)</sort-name>''',
                                    htmlsource)

        if score_match:
            score = score_match.group(1)
        if name_match:
            name = unescape(smart_unicode(name_match.group(1)))
        if id_match:
            id = id_match.group(1)
        if sort_name_match:
            sortname = unescape(smart_unicode(sort_name_match.group(1)))
        log("Score     : %s" % score, xbmc.LOGDEBUG)
        log("Id        : %s" % id, xbmc.LOGDEBUG)
        log("Name      : %s" % name, xbmc.LOGDEBUG)
        log("Sort Name : %s" % sortname, xbmc.LOGDEBUG)
    else:
        if not alias:
            log("No Artist ID found trying aliases: %s" % artist_search,
                xbmc.LOGDEBUG)
            name, id, sortname = get_musicbrainz_artist_id(
                artist_search, limit, True)
        else:
            log("No Artist ID found for Artist: %s" % artist_search,
                xbmc.LOGDEBUG)
    xbmc.sleep(mb_delay)
    return name, id, sortname
Exemplo n.º 8
0
def get_musicbrainz_artists(artist_search, limit=1):
    log("Artist: %s" % artist_search, xbmc.LOGDEBUG)
    score = ""
    name = ""
    id = ""
    sortname = ""
    artists = []
    artist_name = smart_unicode(
        (artist_search.replace('"', '?').replace('&', 'and')))
    url = artist_url % (server, quote_plus(artist_name.encode("utf-8")), limit)
    htmlsource = get_html_source(url, "", save_file=False, overwrite=False)
    match = re.findall('''<artist(.*?)</artist>''', htmlsource)
    if match:
        for item in match:
            artist = {}
            artist["score"] = ""
            artist["name"] = ""
            artist["id"] = ""
            artist["sortname"] = ""
            score_match = re.search('''score="(.*?)"''', item)
            name_match = re.search('''<name>(.*?)</name>''', item)
            id_match = re.search('''id="(.*?)"(?:.*?)>''', item)
            if not id_match:
                id_match = re.search('''id="(.*?)">''', item)
            sort_name_match = re.search('''<sort-name>(.*?)</sort-name>''',
                                        item)
            if score_match:
                artist["score"] = score_match.group(1)
            if name_match:
                artist["name"] = unescape(smart_unicode(name_match.group(1)))
            if id_match:
                artist["id"] = id_match.group(1)
            if sort_name_match:
                artist["sortname"] = unescape(
                    smart_unicode(sort_name_match.group(1)))
            log("Score     : %s" % artist["score"], xbmc.LOGDEBUG)
            log("Id        : %s" % artist["id"], xbmc.LOGDEBUG)
            log("Name      : %s" % artist["name"], xbmc.LOGDEBUG)
            log("Sort Name : %s" % artist["sortname"], xbmc.LOGDEBUG)
            artists.append(artist)
    else:
        log("No Artist ID found for Artist: %s" % repr(artist_search),
            xbmc.LOGDEBUG)
    xbmc.sleep(mb_delay)
    return artists
def get_musicbrainz_artists( artist_search, limit=1 ):
    log( "Artist: %s" % artist_search, xbmc.LOGDEBUG )
    score = ""
    name = ""
    id = ""
    sortname = ""
    artists = []
    artist_name = smart_unicode( artist_search.replace( '"', '?' ) )
    url = artist_url % ( server, quote_plus( artist_name.encode("utf-8") ), limit )
    htmlsource = get_html_source( url, "", save_file = False, overwrite = False )
    match = re.findall( '''<artist(.*?)</artist>''', htmlsource )
    if match:
        for item in match:
            artist = {}
            artist["score"] = ""
            artist["name"] = ""
            artist["id"] = ""
            artist["sortname"] = ""
            score_match = re.search( '''score="(.*?)"''', item )
            name_match = re.search( '''<name>(.*?)</name>''', item )
            id_match = re.search( '''id="(.*?)"(?:.*?)>''', item )
            if not id_match:
                id_match = re.search( '''id="(.*?)">''', item )
            sort_name_match = re.search( '''<sort-name>(.*?)</sort-name>''', item )
            if score_match:
                artist["score"] = score_match.group(1)
            if name_match:
                artist["name"] = unescape( smart_unicode( name_match.group(1) ) )
            if id_match:
                artist["id"] = id_match.group(1)
            if sort_name_match:
                artist["sortname"] = unescape( smart_unicode( sort_name_match.group(1) ) )
            log( "Score     : %s" % artist["score"], xbmc.LOGDEBUG )
            log( "Id        : %s" % artist["id"], xbmc.LOGDEBUG )
            log( "Name      : %s" % artist["name"], xbmc.LOGDEBUG )
            log( "Sort Name : %s" % artist["sortname"], xbmc.LOGDEBUG )
            artists.append(artist)
    else:
        log( "No Artist ID found for Artist: %s" % repr( artist_search ), xbmc.LOGDEBUG )
    xbmc.sleep( mb_delay )
    return artists
Exemplo n.º 10
0
def get_musicbrainz_release_group( release_mbid ):
    """ Retrieves the MusicBrainz Release Group MBID from a given release MBID
        
        Use:
            release_groupmbid = get_musicbrainz_release_group( release_mbid )
        
        release_mbid - valid release mbid
    """
    log( "Retrieving MusicBrainz Release Group MBID from Album Release MBID", xbmc.LOGDEBUG )
    url = release_group_url_release_mbid % ( server, quote_plus( release_mbid ) )
    mbid = ""
    htmlsource = get_html_source( url, release_mbid, save_file = False, overwrite = False )
    match = re.search( '''<release-group-list count="(?:.*?)">(.*?)</release-group-list>''', htmlsource )
    if match:
        mbid_match = re.search( '''<release-group id="(.*?)"(?:.*?)">''', match.group( 1 ) )
        if not mbid_match:
            mbid_match = re.search( '''<release-group (?:.*?)id="(.*?)">''', match.group( 1 ) )
        if mbid_match:
            mbid = mbid_match.group( 1 )
    xbmc.sleep( mb_delay )
    return mbid
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
Exemplo n.º 12
0
def get_musicbrainz_artist_id( artist, limit=1, alias = False ):
    name = ""
    id = ""
    sortname = ""
    artist_name = smart_unicode( artist.replace( '"', '?' ) )
    if not alias:
        url = artist_url % ( server, quote_plus( artist_name.encode("utf-8") ), limit )
    else:
        url = alias_url % ( server, quote_plus( artist_name.encode("utf-8") ), limit )
    htmlsource = get_html_source( url, "", save_file = False)
    match = re.search( '''<artist(.*?)</artist>''', htmlsource )
    if match:
        score_match = re.search( '''score="(.*?)"''', htmlsource )
        name_match = re.search( '''<name>(.*?)</name>''', htmlsource )
        id_match = re.search( '''<artist id="(.*?)"(?:.*?)>''', htmlsource )
        if not id_match:
            id_match = re.search( '''<artist (?:.*?)id="(.*?)">''', htmlsource )
        sort_name_match = re.search( '''<sort-name>(.*?)</sort-name>''', htmlsource )
        
        if score_match:
            score = score_match.group(1)
        if name_match:
            name = unescape( smart_unicode( name_match.group(1) ) )
        if id_match:
            id = id_match.group(1)
        if sort_name_match:
            sortname = unescape( smart_unicode( sort_name_match.group(1) ) )
        log( "Score     : %s" % score, xbmc.LOGDEBUG )
        log( "Id        : %s" % id, xbmc.LOGDEBUG )
        log( "Name      : %s" % name, xbmc.LOGDEBUG )
        log( "Sort Name : %s" % sortname, xbmc.LOGDEBUG )
    else:
        if not alias:
            log( "No Artist ID found trying aliases: %s" % artist, xbmc.LOGDEBUG )
            name, id, sortname = get_musicbrainz_artist_id( artist, limit, True )
        else:
            log( "No Artist ID found for Artist: %s" % artist, xbmc.LOGDEBUG )
    xbmc.sleep( mb_delay )
    return name, id, sortname
Exemplo n.º 13
0
def retrieve_fanarttv_json(id):
    log("Retrieving artwork for artist id: %s" % id, xbmc.LOGDEBUG)
    url = music_url_json % (api_key, id, "all")
    htmlsource = (get_html_source(url, id, save_file=False,
                                  overwrite=False)).encode('utf-8', 'ignore')
    artist_artwork = []
    backgrounds = []
    musiclogos = []
    artistthumbs = []
    hdlogos = []
    banners = []
    albums = []
    blank = {}
    fanart = {}
    clearlogo = {}
    artistthumb = {}
    album_art = {}
    hdlogo = {}
    banner = {}
    artist = ""
    artist_id = ""
    IMAGE_TYPES = [
        'musiclogo', 'artistthumb', 'artistbackground', 'hdmusiclogo',
        'musicbanner', 'albums'
    ]
    try:
        data = simplejson.loads(htmlsource)
        for artist, value in data.iteritems():
            for art in IMAGE_TYPES:
                if value.has_key(art):
                    for item in value[art]:
                        if art == "musiclogo":
                            musiclogos.append(item.get('url'))
                        if art == "hdmusiclogo":
                            hdlogos.append(item.get('url'))
                        if art == "artistbackground":
                            backgrounds.append(item.get('url'))
                        if art == "musicbanner":
                            banners.append(item.get('url'))
                        if art == "artistthumb":
                            artistthumbs.append(item.get('url'))
                        if art == "albums" and not albums:
                            for album_id in data[artist]["albums"]:
                                album_artwork = {}
                                album_artwork["musicbrainz_albumid"] = album_id
                                album_artwork["cdart"] = []
                                album_artwork["cover"] = ""
                                if value["albums"][album_id].has_key("cdart"):
                                    for item in value["albums"][album_id][
                                            "cdart"]:
                                        cdart = {}
                                        if item.has_key("disc"):
                                            cdart["disc"] = int(item["disc"])
                                        else:
                                            cdart["disc"] = 1
                                        if item.has_key("url"):
                                            cdart["cdart"] = item["url"]
                                        else:
                                            cdart["cdart"] = ""
                                        if item.has_key("size"):
                                            cdart["size"] = int(item["size"])
                                        album_artwork["cdart"].append(cdart)
                                try:
                                    if value["albums"][album_id]["albumcover"]:
                                        if len(value["albums"][album_id]
                                               ["albumcover"]) < 2:
                                            album_artwork["cover"] = value[
                                                "albums"][album_id][
                                                    "albumcover"][0]["url"]
                                except:
                                    album_artwork["cover"] = ""
                                albums.append(album_artwork)
    except:
        print_exc()
    fanart["backgrounds"] = backgrounds
    clearlogo["clearlogo"] = musiclogos
    hdlogo["hdlogo"] = hdlogos
    banner["banner"] = banners
    artistthumb["artistthumb"] = artistthumbs
    album_art["artwork"] = albums
    artist_artwork.append(fanart)
    artist_artwork.append(clearlogo)
    artist_artwork.append(artistthumb)
    artist_artwork.append(hdlogo)
    artist_artwork.append(banner)
    artist_artwork.append(album_art)
    print artist_artwork
    return artist_artwork
Exemplo n.º 14
0
def get_musicbrainz_album( album_title, artist, e_count, limit=1, with_singles=False, by_release=False, use_alias=False, use_live=False ):
    """ Retrieves information for Album from MusicBrainz using provided Album title and Artist name. 
        
        Use:
            album, albums = get_musicbrainz_album( album_title, artist, e_count, limit, with_singles, by_release )
        
        album_title  - the album title(must be unicode)
        artist       - the artist's name(must be unicode)
        e_count      - used internally(should be set to 0)
        limit        - limit the number of responses
        with_singles - set to True to look up single releases at the same time
        by_release   - use release name for search
    """
    match_within = "~2"
    album = {}
    albums = []
    count = e_count
    album["score"] = ""
    album["id"] = ""
    album["title"] = ""
    album["artist"] = ""
    album["artist_id"] = ""
    log( "Artist: %s" % smart_unicode( artist ), xbmc.LOGDEBUG )
    album_temp = smart_unicode( album_title )
    artist = smart_unicode( get_unicode( artist ) )
    album_title = smart_unicode( get_unicode( album_title ) )
    log( "Artist: %s" % artist, xbmc.LOGDEBUG )
    log( "Album: %s" % album_title, xbmc.LOGDEBUG )
    artist = artist.replace('"','?')
    album_title = album_title.replace('"','?')
    if limit == 1:
        if not use_alias:
            url = release_group_url_artist % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) )
            if not with_singles and not by_release and not use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums", xbmc.LOGDEBUG )
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles", xbmc.LOGDEBUG )
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums", xbmc.LOGDEBUG )
                url = url + query_limit % limit
            elif not with_singles:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name", xbmc.LOGDEBUG )
                url = release_group_url_artist % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) ) + query_limit % limit
        elif use_alias:
            url = release_group_url_alias % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) )
            if not with_singles and not by_release and not use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums", xbmc.LOGDEBUG )
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles", xbmc.LOGDEBUG )
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums", xbmc.LOGDEBUG )
                url = url + query_limit % limit
            elif not with_singles:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name", xbmc.LOGDEBUG )
                url = release_group_url_alias % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) ) + query_limit % limit
        htmlsource = get_html_source( url, "", save_file = False, overwrite = False )
        match = re.search( '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''', htmlsource )
        if match:
            try:
                mbid = re.search( '''<release-group id="(.*?)"(?:.*?)">''', htmlsource)
                if not mbid:
                    mbid = re.search( '''<release-group (?:.*?)id="(.*?)">''', htmlsource )
                mbtitle = re.search( '''<title>(.*?)</title>''', htmlsource)
                mbartist = re.search( '''<name>(.*?)</name>''', htmlsource)
                mbartistid = re.search( '''<artist id="(.*?)">''', htmlsource)
                album["id"] = mbid.group(1)
                album["title"] = unescape( smart_unicode( mbtitle.group(1) ) )
                album["artist"] = unescape( smart_unicode( mbartist.group(1) ) )
                album["artist_id"] = mbartistid.group(1)
            except:
                pass            
        if not album["id"]:
            xbmc.sleep( mb_delay ) # sleep for allowing proper use of webserver
            if not with_singles and not by_release and not use_alias and not use_live:
                log( "No releases found on MusicBrainz, Checking For Live Album", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, False, False, True ) # try again by using artist alias
            elif not with_singles and not by_release and not use_alias and use_live:
                log( "No releases found on MusicBrainz, Checking by Artist Alias", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, False, True, False ) # try again by using artist alias
            elif use_alias and not with_singles and not by_release and not use_live:
                log( "No releases found on MusicBrainz, Checking by Release Name", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, True, False, False ) # try again by using release name
            elif by_release and not with_singles and not use_alias:
                log( "No releases found on MusicBrainz, Checking by Release name and Artist Alias", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, True, True, False ) # try again by using release name and artist alias
            elif by_release and not with_singles and use_alias:
                log( "No releases found on MusicBrainz, checking singles", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, True, False, False, False ) # try again with singles
            elif with_singles and not use_alias and not by_release:
                log( "No releases found on MusicBrainz, checking singles and Artist Alias", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, True, False, True, False ) # try again with singles and artist alias
            else:
                log( "No releases found on MusicBrainz.", xbmc.LOGDEBUG )
                album["artist"], album["artist_id"], sort_name = get_musicbrainz_artist_id( artist )
    else:
        match_within = "~4"
        url = release_group_url_artist % ( server, ( album_title.encode("utf-8") ), match_within, ( artist.encode("utf-8") ) ) + query_limit % limit
        htmlsource = get_html_source( url, "", save_file = False, overwrite = False )
        match = re.search( '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''', htmlsource )
        if match:
            match_release_group = re.findall( '''<release-group(.*?)</release-group>''', match.group( 1 ) )
            if match_release_group:
                for item in match_release_group:
                    album = {}
                    album["score"] = ""
                    album["id"] = ""
                    album["title"] = ""
                    album["artist"] = ""
                    album["artist_id"] = ""
                    try:
                        mbscore = re.search( '''score="(.*?)"''', item)
                        mbid = re.search( '''<release-group id="(.*?)"(?:.*?)">''', item)
                        if not mbid:
                            mbid = re.search( '''id="(.*?)"(?:.*?)">''', item)
                            if not mbid:
                                mbid = re.search( '''<release-group (?:.*?)id="(.*?)">''', htmlsource )
                        mbtitle = re.search( '''<title>(.*?)</title>''', item)
                        mbartist = re.search( '''<name>(.*?)</name>''', item)
                        mbartistid = re.search( '''<artist id="(.*?)">''', item)
                        album["score"] = mbscore.group(1)
                        album["id"] = mbid.group(1)
                        album["title"] = unescape( smart_unicode( mbtitle.group(1) ) )
                        album["artist"] = unescape( smart_unicode( mbartist.group(1) ) )
                        album["artist_id"] = mbartistid.group(1)
                        log( "Score     : %s" % album["score"], xbmc.LOGDEBUG )
                        log( "Title     : %s" % album["title"], xbmc.LOGDEBUG )
                        log( "Id        : %s" % album["id"], xbmc.LOGDEBUG )
                        log( "Artist    : %s" % album["artist"], xbmc.LOGDEBUG )
                        log( "Artist ID : %s" % album["artist_id"], xbmc.LOGDEBUG )
                        albums.append(album)
                    except:
                        print_exc()
                    
            else:
                pass
        else:
            pass
    xbmc.sleep( mb_delay ) # sleep for allowing proper use of webserver
    return album, albums
def retrieve_fanarttv_json( id ):
    log( "Retrieving artwork for artist id: %s" % id, xbmc.LOGDEBUG )
    url = music_url_json % ( api_key, id, "all" )
    htmlsource = ( get_html_source( url, id, save_file = False, overwrite = False ) ).encode( 'utf-8', 'ignore' )
    artist_artwork = []
    backgrounds = []
    musiclogos = []
    artistthumbs = []
    hdlogos = []
    banners = []
    albums = []
    blank = {}
    fanart = {}
    clearlogo = {}
    artistthumb = {}
    album_art = {}
    hdlogo = {}
    banner = {}
    artist = ""
    artist_id = ""
    IMAGE_TYPES = [ 'musiclogo',
                    'artistthumb',
                    'artistbackground',
                    'hdmusiclogo',
                    'musicbanner',
                    'albums' ]
    try:
        data = simplejson.loads( htmlsource )
        for artist, value in data.iteritems():
            for art in IMAGE_TYPES:
                if value.has_key(art):
                    for item in value[art]:
                        if art == "musiclogo":
                            musiclogos.append( item.get('url') )
                        if art == "hdmusiclogo":
                            hdlogos.append( item.get('url') )
                        if art == "artistbackground":
                            backgrounds.append( item.get('url' ) )
                        if art == "musicbanner":
                            banners.append( item.get('url' ) )
                        if art == "artistthumb":
                            artistthumbs.append( item.get( 'url' ) )
                        if art == "albums" and not albums:
                            for album_id in data[ artist ][ "albums" ]:
                                album_artwork = {}
                                album_artwork["musicbrainz_albumid"] = album_id
                                album_artwork["cdart"] = []
                                album_artwork["cover"] = ""
                                if value[ "albums"][ album_id ].has_key( "cdart" ):
                                    for item in value[ "albums" ][ album_id ][ "cdart" ]:
                                        cdart = {}
                                        if item.has_key( "disc" ):
                                            cdart[ "disc" ] = int( item[ "disc" ] )
                                        else:
                                            cdart[ "disc" ] = 1
                                        if item.has_key( "url" ):
                                            cdart["cdart"] = item[ "url" ]
                                        else:
                                            cdart["cdart"] = ""
                                        if item.has_key( "size" ):
                                            cdart["size"] = int( item[ "size" ] )
                                        album_artwork["cdart"].append(cdart)
                                try:
                                    if value[ "albums" ][ album_id ][ "albumcover" ]:
                                        if len( value[ "albums" ][ album_id ][ "albumcover" ] ) < 2:
                                            album_artwork["cover"] = value[ "albums" ][ album_id ][ "albumcover" ][0][ "url" ]
                                except:
                                    album_artwork["cover"] = ""
                                albums.append( album_artwork )
    except:
        print_exc()
    fanart["backgrounds"] = backgrounds
    clearlogo["clearlogo"] = musiclogos
    hdlogo["hdlogo"] = hdlogos
    banner["banner"] = banners
    artistthumb["artistthumb"] = artistthumbs
    album_art["artwork"] = albums
    artist_artwork.append(fanart)
    artist_artwork.append(clearlogo)
    artist_artwork.append(artistthumb)
    artist_artwork.append(hdlogo)
    artist_artwork.append(banner)
    artist_artwork.append(album_art)
    print artist_artwork
    return artist_artwork
Exemplo n.º 16
0
def get_musicbrainz_album(album_title,
                          artist,
                          e_count,
                          limit=1,
                          with_singles=False,
                          by_release=False,
                          use_alias=False,
                          use_live=False):
    """ Retrieves information for Album from MusicBrainz using provided Album title and Artist name. 
        
        Use:
            album, albums = get_musicbrainz_album( album_title, artist, e_count, limit, with_singles, by_release )
        
        album_title  - the album title(must be unicode)
        artist       - the artist's name(must be unicode)
        e_count      - used internally(should be set to 0)
        limit        - limit the number of responses
        with_singles - set to True to look up single releases at the same time
        by_release   - use release name for search
    """
    match_within = "~2"
    album = {}
    albums = []
    count = e_count
    album["score"] = ""
    album["id"] = ""
    album["title"] = ""
    album["artist"] = ""
    album["artist_id"] = ""
    album_temp = smart_unicode(album_title)
    artist = smart_unicode(get_unicode(artist))
    album_title = smart_unicode(get_unicode(album_title))
    log("Artist: %s" % artist, xbmc.LOGDEBUG)
    log("Album: %s" % album_title, xbmc.LOGDEBUG)
    artist = artist.replace('"', '?')
    artist = artist.replace('&', 'and')
    album_title = album_title.replace('"', '?')
    album_title = album_title.replace('&', 'and')
    if limit == 1:
        if not use_alias:
            url = release_group_url_artist % (
                server, quote_plus(album_title.encode("utf-8")), match_within,
                quote_plus(artist.encode("utf-8")))
            if not with_singles and not by_release and not use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums",
                    xbmc.LOGDEBUG)
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles",
                    xbmc.LOGDEBUG)
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums",
                    xbmc.LOGDEBUG)
                url = url + query_limit % limit
            elif not with_singles:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name",
                    xbmc.LOGDEBUG)
                url = release_group_url_artist % (
                    server, quote_plus(
                        album_title.encode("utf-8")), match_within,
                    quote_plus(artist.encode("utf-8"))) + query_limit % limit
        elif use_alias:
            url = release_group_url_alias % (
                server, quote_plus(album_title.encode("utf-8")), match_within,
                quote_plus(artist.encode("utf-8")))
            if not with_singles and not by_release and not use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums",
                    xbmc.LOGDEBUG)
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles",
                    xbmc.LOGDEBUG)
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums",
                    xbmc.LOGDEBUG)
                url = url + query_limit % limit
            elif not with_singles:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name",
                    xbmc.LOGDEBUG)
                url = release_group_url_alias % (
                    server, quote_plus(
                        album_title.encode("utf-8")), match_within,
                    quote_plus(artist.encode("utf-8"))) + query_limit % limit
        htmlsource = get_html_source(url, "", save_file=False, overwrite=False)
        match = re.search(
            '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''',
            htmlsource)
        if match:
            try:
                mbid = re.search('''<release-group id="(.*?)"(?:.*?)">''',
                                 htmlsource)
                if not mbid:
                    mbid = re.search('''<release-group (?:.*?)id="(.*?)">''',
                                     htmlsource)
                mbtitle = re.search('''<title>(.*?)</title>''', htmlsource)
                mbartist = re.search('''<name>(.*?)</name>''', htmlsource)
                mbartistid = re.search('''<artist id="(.*?)">''', htmlsource)
                album["id"] = mbid.group(1)
                album["title"] = unescape(smart_unicode(mbtitle.group(1)))
                album["artist"] = unescape(smart_unicode(mbartist.group(1)))
                album["artist_id"] = mbartistid.group(1)
            except:
                pass
        if not album["id"]:
            xbmc.sleep(mb_delay)  # sleep for allowing proper use of webserver
            if not with_singles and not by_release and not use_alias and not use_live:
                log(
                    "No releases found on MusicBrainz, Checking For Live Album",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, False, False,
                    True)  # try again by using artist alias
            elif not with_singles and not by_release and not use_alias and use_live:
                log(
                    "No releases found on MusicBrainz, Checking by Artist Alias",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, False, True,
                    False)  # try again by using artist alias
            elif use_alias and not with_singles and not by_release and not use_live:
                log(
                    "No releases found on MusicBrainz, Checking by Release Name",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, True, False,
                    False)  # try again by using release name
            elif by_release and not with_singles and not use_alias:
                log(
                    "No releases found on MusicBrainz, Checking by Release name and Artist Alias",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, True, True,
                    False)  # try again by using release name and artist alias
            elif by_release and not with_singles and use_alias:
                log("No releases found on MusicBrainz, checking singles",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, True, False, False,
                    False)  # try again with singles
            elif with_singles and not use_alias and not by_release:
                log(
                    "No releases found on MusicBrainz, checking singles and Artist Alias",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, True, False, True,
                    False)  # try again with singles and artist alias
            else:
                log("No releases found on MusicBrainz.", xbmc.LOGDEBUG)
                album["artist"], album[
                    "artist_id"], sort_name = get_musicbrainz_artist_id(artist)
    else:
        match_within = "~4"
        url = release_group_url_artist % (
            server, (album_title.encode("utf-8")), match_within,
            (artist.encode("utf-8"))) + query_limit % limit
        htmlsource = get_html_source(url, "", save_file=False, overwrite=False)
        match = re.search(
            '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''',
            htmlsource)
        if match:
            match_release_group = re.findall(
                '''<release-group(.*?)</release-group>''', match.group(1))
            if match_release_group:
                for item in match_release_group:
                    album = {}
                    album["score"] = ""
                    album["id"] = ""
                    album["title"] = ""
                    album["artist"] = ""
                    album["artist_id"] = ""
                    try:
                        mbscore = re.search('''score="(.*?)"''', item)
                        mbid = re.search(
                            '''<release-group id="(.*?)"(?:.*?)">''', item)
                        if not mbid:
                            mbid = re.search('''id="(.*?)"(?:.*?)">''', item)
                            if not mbid:
                                mbid = re.search(
                                    '''<release-group (?:.*?)id="(.*?)">''',
                                    htmlsource)
                        mbtitle = re.search('''<title>(.*?)</title>''', item)
                        mbartist = re.search('''<name>(.*?)</name>''', item)
                        mbartistid = re.search('''<artist id="(.*?)">''', item)
                        album["score"] = mbscore.group(1)
                        album["id"] = mbid.group(1)
                        album["title"] = unescape(
                            smart_unicode(mbtitle.group(1)))
                        album["artist"] = unescape(
                            smart_unicode(mbartist.group(1)))
                        album["artist_id"] = mbartistid.group(1)
                        log("Score     : %s" % album["score"], xbmc.LOGDEBUG)
                        log("Title     : %s" % album["title"], xbmc.LOGDEBUG)
                        log("Id        : %s" % album["id"], xbmc.LOGDEBUG)
                        log("Artist    : %s" % album["artist"], xbmc.LOGDEBUG)
                        log("Artist ID : %s" % album["artist_id"],
                            xbmc.LOGDEBUG)
                        albums.append(album)
                    except:
                        print_exc()

            else:
                pass
        else:
            pass
    xbmc.sleep(mb_delay)  # sleep for allowing proper use of webserver
    return album, albums