def fix_dups(c, nfo_map):
    map_album_artists = set()  # collections.defaultdict(set)
    for idAlbum, strArtist, idArtist1, idArtist2 in sql(
        c,
        """
		select a1.idalbum, a1.strArtist, a1.idArtist, a2.idArtist 
		from album_artist a1, album_artist a2 
		where 
		a1.idAlbum  = a2.idAlbum and 
		a1.strArtist = a2.strArtist and 
		a1.idartist > a2.idArtist""",
    ):
        map_album_artists.add(idArtist1)
        map_album_artists.add(idArtist2)

    for idArtist1 in sql(
        c,
        """
		select a1.idArtist 
		from artist a1
		where 
		
		a1.strArtist = '1111'
		""",
    ):
        map_album_artists.add(idArtist1[0])

    print map_album_artists
    for id, mb, st in list(
        sql(
            c,
            """select idArtist, strMusicBrainzArtistId, strArtist from artist where idArtist in ({}) """.format(
                quote(sorted(map_album_artists))
            ),
        )
    ):

        mb = mb.strip()
        strArtist = nfo_map.get(mb.lower())
        if strArtist is None or strArtist == "1111":
            res = scrapers.brainz_lookup_artist_by_mb(None, mb, True)
            time.sleep(1)
            # print repr(res)
            strArtist = res[0]["artist"]["name"]

        strArtist = strArtist.replace("'", "''")
        print "&&", repr(st), mb, repr(strArtist)
        sql(c, u"""update album_artist set strArtist = '{}' where idArtist = '{}' """.format(strArtist, id))
        sql(c, u"""update song_artist set strArtist = '{}' where idArtist = '{}' """.format(strArtist, id))
        sql(c, u"""update artist set strArtist = '{}' where idArtist = '{}' """.format(strArtist, id))
def artists_scrape(ifile, artists, skip=False):
    nfo_map = nfo_read(ifile)
    missing = set(artists.map_mb_id) - set(nfo_map)

    if not skip:
        for mbid in missing:
            # if mbid not in artists.map_orig_mbids_id
            try:
                nfo_map[mbid] = scrapers.brainz_lookup_artist_by_mb(None, mbid, True)[0]["artist"]["name"]
            except:
                nfo_map[mbid] = None
            time.sleep(1)
    else:
        for mbid in missing:
            # if mbid not in nfo_map:
            nfo_map[mbid] = "1111"

    return nfo_map