" * Amz barcode doesn't match MB barcode (%s vs %s) => skipping"
                % (amz_barcode, release['barcode']))
            continue
        if amz_image is not None:
            amz_score = amz_image.Height * amz_image.Width
            colored_out(
                bcolors.NONE, ' * Amazon score:\t%s \t %s' %
                (amz_score, amz_image.URL.pyval))
            if amz_score > best_score:
                front_uri = amz_image.URL.pyval
                best_score = amz_score

    # Evaluate Spotify
    if spotify is not None and release[
            'barcode'] is not None and release['barcode'] != "":
        albums = spotify.search_albums('upc:%s' % release['barcode'])
        if len(albums) == 1:
            colored_out(
                bcolors.WARNING,
                ' * Spotify = https://embed.spotify.com/?uri=%s&view=coverart'
                % (albums[0]['href'], ))
            image_url = spotify.artwork_url(albums[0]['href'])
            if image_url is not None:
                try:
                    img_file = urllib2.urlopen(image_url)
                    im = Image.open(StringIO(img_file.read()))
                    spotify_score = im.size[0] * im.size[1]
                    colored_out(
                        bcolors.NONE, ' * Spotify score:\t%s \t %s' %
                        (spotify_score, image_url))
                    if spotify_score > best_score:
예제 #2
0
def save_processing(mb_release):
    if mb_release['processed'] is None:
        db.execute("INSERT INTO bot_isrc_spotify (release) VALUES (%s)", (mb_release['gid']))
    else:
        db.execute("UPDATE bot_isrc_spotify SET processed = now() WHERE release = %s", (mb_release['gid']))

sws = SpotifyWebService()
musicbrainzngs.auth(cfg.MB_USERNAME, cfg.MB_PASSWORD)

for release in db.execute(query_releases_wo_isrcs):

    mb_release = dict(release)

    colored_out(bcolors.OKBLUE, 'Looking up release "%s" https://musicbrainz.org/release/%s' % (mb_release['name'], mb_release['gid']))

    sp_albums = sws.search_albums('upc:%s' % mb_release['barcode'])
    if len(sp_albums) != 1:
        if len(sp_albums) == 0:
            out(' * no spotify release found')
        if len(sp_albums) > 1:
            out(' * multiple spotify releases found')
        save_processing(mb_release)
        continue
    sp_uri = sp_albums[0]['href']
    sp_release = sws.lookup(sp_uri, detail=2)

    for track in sp_release['tracks']:
        for extid in track['external-ids']:
            if extid['type'] == 'isrc':
                if extid['id'].upper()[:2] == 'TC':
                    print 'TuneCore song IDs detected! Bailing out'
예제 #3
0
        amz_image, amz_barcode = amz_get_info(release['amz_url'])
        # Amazon: check barcode matches
        if amz_barcode is not None and release['barcode'] is not None \
            and re.sub(r'^(0+)', '', amz_barcode) != re.sub(r'^(0+)', '', release['barcode']):
            colored_out(bcolors.FAIL, " * Amz barcode doesn't match MB barcode (%s vs %s) => skipping" % (amz_barcode, release['barcode']))
            continue
        if amz_image is not None:
            amz_score = amz_image.Height * amz_image.Width
            colored_out(bcolors.NONE, ' * Amazon score:\t%s \t %s' % (amz_score, amz_image.URL.pyval))
            if amz_score > best_score:
                front_uri = amz_image.URL.pyval
                best_score = amz_score

    # Evaluate Spotify
    if spotify is not None and release['barcode'] is not None and release['barcode'] != "":
        albums = spotify.search_albums('upc:%s' % release['barcode'])
        if len(albums) == 1:
            colored_out(bcolors.WARNING, ' * Spotify = https://embed.spotify.com/?uri=%s&view=coverart' % (albums[0]['href'],))
            image_url = spotify.artwork_url(albums[0]['href'])
            if image_url is not None:
                try:
                    img_file = urllib2.urlopen(image_url)
                    im = Image.open(StringIO(img_file.read()))
                    spotify_score = im.size[0] * im.size[1]
                    colored_out(bcolors.NONE, ' * Spotify score:\t%s \t %s' % (spotify_score, image_url))
                    if spotify_score > best_score:
                        front_uri = image_url
                        best_score = spotify_score
                except urllib2.HTTPError, e:
                    pass
예제 #4
0
            (mb_release['gid']))


sws = SpotifyWebService()
musicbrainzngs.auth(cfg.MB_USERNAME, cfg.MB_PASSWORD)

for release in db.execute(query_releases_wo_isrcs):

    mb_release = dict(release)

    colored_out(
        bcolors.OKBLUE,
        'Looking up release "%s" https://musicbrainz.org/release/%s' %
        (mb_release['name'], mb_release['gid']))

    sp_albums = sws.search_albums('upc:%s' % mb_release['barcode'])
    if len(sp_albums) != 1:
        if len(sp_albums) == 0:
            out(' * no spotify release found')
        if len(sp_albums) > 1:
            out(' * multiple spotify releases found')
        save_processing(mb_release)
        continue
    sp_uri = sp_albums[0]['href']
    sp_release = sws.lookup(sp_uri, detail=2)

    for track in sp_release['tracks']:
        for extid in track['external-ids']:
            if extid['type'] == 'isrc':
                if extid['id'].upper()[:2] == 'TC':
                    print 'TuneCore song IDs detected! Bailing out'