Пример #1
0
def getSpotifyMetadata(track, search_artist=True):
    artist_id = None
    possible_tracks = []
    recordings = spotify.search(q='artist:' + track[0] + ' track:' + track[1], type='track')
    for recording in recordings['tracks']['items']:  # keys in recordings: items,next,href,limit,offset,total,previous
        for artist in recording['artists']:
            '''
            Spotify may return different versions of the same song, e.g. a Radio Edit, or the same song released on another label
            '''
            if utils.is_similar(artist['name'].lower(), track[0]) and (
                    utils.checkTrackNamingConvention(recording['name'].lower(),
                                                     track[1], normalize=True)):
                if artist_id is None:
                    artist_id = artist['id']
                possible_tracks.append(recording)
    getSpotifyTrackMetadata(possible_tracks)
    if search_artist:
        if artist_id is None:
            artists = spotify.search(q='artist:' + track[0], type='artist')
            for artist in artists['artists']['items']:
                # TODO: multiple artists with same name => let user choose
                if utils.is_similar(artist['name'].lower(), track[0]):
                    getSpotifyArtistMetadata(artist)
                    break
        else:
            getSpotifyArtistMetadata(spotify.artist(artist_id))
Пример #2
0
def getSpotifyMetadata(track, search_artist=True):
    artist_id = None
    possible_tracks = []
    recordings = spotify.search(q='artist:' + track[0] + ' track:' + track[1],
                                type='track')
    for recording in recordings['tracks'][
            'items']:  # keys in recordings: items,next,href,limit,offset,total,previous
        for artist in recording['artists']:
            '''
            Spotify may return different versions of the same song, e.g. a Radio Edit, or the same song released on another label
            '''
            if utils.is_similar(
                    artist['name'].lower(),
                    track[0]) and (utils.checkTrackNamingConvention(
                        recording['name'].lower(), track[1], normalize=True)):
                if artist_id is None:
                    artist_id = artist['id']
                possible_tracks.append(recording)
    getSpotifyTrackMetadata(possible_tracks)
    if search_artist:
        if artist_id is None:
            artists = spotify.search(q='artist:' + track[0], type='artist')
            for artist in artists['artists']['items']:
                # TODO: multiple artists with same name => let user choose
                if utils.is_similar(artist['name'].lower(), track[0]):
                    getSpotifyArtistMetadata(artist)
                    break
        else:
            getSpotifyArtistMetadata(spotify.artist(artist_id))
Пример #3
0
def getMusicbrainzMetadata(track, search_artist=True):
    global tries
    artist_id = None
    possible_tracks = []
    exists_remix = True
    offset = 0
    try:
        recordings = musicbrainzngs.search_recordings(query=track[1].replace('/', ''),
                                                      artistname=track[0].replace('/', ''),
                                                      limit=MUSICBRAINZ_LIMIT,
                                                      offset=offset * MUSICBRAINZ_LIMIT)
        for recording in recordings["recording-list"]:
            for artist_credit in recording['artist-credit']:
                if 'artist' in artist_credit and utils.is_similar(artist_credit['artist']['name'].lower(), track[0],
                                                                  normalize=True):
                    if utils.checkTrackNamingConvention(recording['title'].lower(), track[1]):
                        if 'release-list' in recording:
                            for release in recording['release-list']:
                                if 'status' in release:
                                    if release['status'] == 'Official':
                                        possible_tracks.append(recording)
                                        if artist_id is None:
                                            artist_id = artist_credit['artist']['id']
                                    elif release['status'] == 'Bootleg':
                                        exists_remix = True
                                else:
                                    if utils.isTrackRemixByName(recording['title']):
                                        exists_remix = True
                                    else:
                                        possible_tracks.append(recording)
        getMusicbrainzTrackMetadata(possible_tracks, exists_remix)
        if search_artist:
            if artist_id is None:
                choice = False
                artists = musicbrainzngs.search_artists(track[0].replace('/', ''),
                                                        ("artist", "begin", "end", "country", "ended", "gender",
                                                         "tag", "type", "area", "beginarea", "endarea"))
                for (i, artist) in enumerate(artists['artist-list']):
                    '''
                    resolve any disambiguations
                    if the current artist has the same name as the next artist in the list, then let the user choose the right one
                    '''
                    if len(artists['artist-list']) - 1 > i and utils.is_similar(artist['name'],
                                                                                artists['artist-list'][i + 1]['name'],
                                                                                normalize=True) and utils.is_similar(
                        track[0], artist['name'], normalize=True):
                        choice = True
                        if i == 0:
                            print u"Sorry, the artist '{0}' is ambigious, please chose the right one:\n[{1}] None of the options".format(
                                artist['name'], i)
                        print u"[{0}] {1}: {2}".format(i + 1, artist['name'],
                                                       artist[
                                                           'disambiguation'] if 'disambiguation' in artist else "no description")
                    elif choice:
                        print u"[{0}] {1}: {2}".format(i + 1, artist['name'], artist[
                            'disambiguation'] if 'disambiguation' in artist else "no description")
                        input = raw_input("Your choice: ")
                        try:
                            artist_int = int(input)
                            if artist_int == 0:
                                return
                            # FIXME: why does musicbrainzngs.search_artist() not provide this information? => double request necessary
                            # getMusicbrainzArtistMetadata(artists['artist-list'][artist_int - 1])
                            getMusicbrainzArtistMetadata(
                                musicbrainzngs.get_artist_by_id(artists['artist-list'][artist_int - 1]['id'],
                                                                ['recordings', 'releases',
                                                                 'release-groups', 'works',
                                                                 'aliases', 'artist-rels',
                                                                 'label-rels', 'tags', 'ratings'])[
                                    'artist'])
                        except ValueError:
                            pass  # TODO
                        break
                    elif utils.is_similar(artist['name'], track[0], normalize=True):
                        # FIXME: why does musicbrainzngs.search_artist() not provide this information? => double request necessary
                        getMusicbrainzArtistMetadata(musicbrainzngs.get_artist_by_id(artist['id'],
                                                                                     ['recordings', 'releases',
                                                                                      'release-groups', 'works',
                                                                                      'aliases', 'artist-rels',
                                                                                      'label-rels', 'tags', 'ratings'])[
                                                         'artist'])
                        break
            else:
                getMusicbrainzArtistMetadata(musicbrainzngs.get_artist_by_id(artist_id,
                                                                             ['recordings', 'releases',
                                                                              'release-groups', 'works',
                                                                              'aliases', 'artist-rels',
                                                                              'label-rels', 'tags', 'ratings'])[
                                                 'artist'])
    except musicbrainzngs.NetworkError:
        tries += 1
        track_md.error = True
        print colored("| The Musicbrainz service seems to be not available right now...", 'red')
    except musicbrainzngs.musicbrainz.ResponseError as e:
        track_md.error = True
        print colored("| {}".format(e), 'red')
Пример #4
0
def getMusicbrainzMetadata(track, search_artist=True):
    global tries
    artist_id = None
    possible_tracks = []
    exists_remix = True
    offset = 0
    try:
        recordings = musicbrainzngs.search_recordings(
            query=track[1].replace('/', ''),
            artistname=track[0].replace('/', ''),
            limit=MUSICBRAINZ_LIMIT,
            offset=offset * MUSICBRAINZ_LIMIT)
        for recording in recordings["recording-list"]:
            for artist_credit in recording['artist-credit']:
                if 'artist' in artist_credit and utils.is_similar(
                        artist_credit['artist']['name'].lower(),
                        track[0],
                        normalize=True):
                    if utils.checkTrackNamingConvention(
                            recording['title'].lower(), track[1]):
                        if 'release-list' in recording:
                            for release in recording['release-list']:
                                if 'status' in release:
                                    if release['status'] == 'Official':
                                        possible_tracks.append(recording)
                                        if artist_id is None:
                                            artist_id = artist_credit[
                                                'artist']['id']
                                    elif release['status'] == 'Bootleg':
                                        exists_remix = True
                                else:
                                    if utils.isTrackRemixByName(
                                            recording['title']):
                                        exists_remix = True
                                    else:
                                        possible_tracks.append(recording)
        getMusicbrainzTrackMetadata(possible_tracks, exists_remix)
        if search_artist:
            if artist_id is None:
                choice = False
                artists = musicbrainzngs.search_artists(
                    track[0].replace('/', ''),
                    ("artist", "begin", "end", "country", "ended", "gender",
                     "tag", "type", "area", "beginarea", "endarea"))
                for (i, artist) in enumerate(artists['artist-list']):
                    '''
                    resolve any disambiguations
                    if the current artist has the same name as the next artist in the list, then let the user choose the right one
                    '''
                    if len(artists['artist-list']) - 1 > i and utils.is_similar(
                            artist['name'],
                            artists['artist-list'][i + 1]['name'],
                            normalize=True) and utils.is_similar(
                                track[0], artist['name'], normalize=True):
                        choice = True
                        if i == 0:
                            print u"Sorry, the artist '{0}' is ambigious, please chose the right one:\n[{1}] None of the options".format(
                                artist['name'], i)
                        print u"[{0}] {1}: {2}".format(
                            i + 1, artist['name'], artist['disambiguation'] if
                            'disambiguation' in artist else "no description")
                    elif choice:
                        print u"[{0}] {1}: {2}".format(
                            i + 1, artist['name'], artist['disambiguation'] if
                            'disambiguation' in artist else "no description")
                        input = raw_input("Your choice: ")
                        try:
                            artist_int = int(input)
                            if artist_int == 0:
                                return
                            # FIXME: why does musicbrainzngs.search_artist() not provide this information? => double request necessary
                            # getMusicbrainzArtistMetadata(artists['artist-list'][artist_int - 1])
                            getMusicbrainzArtistMetadata(
                                musicbrainzngs.get_artist_by_id(
                                    artists['artist-list'][artist_int -
                                                           1]['id'],
                                    [
                                        'recordings', 'releases',
                                        'release-groups', 'works', 'aliases',
                                        'artist-rels', 'label-rels', 'tags',
                                        'ratings'
                                    ])['artist'])
                        except ValueError:
                            pass  # TODO
                        break
                    elif utils.is_similar(artist['name'],
                                          track[0],
                                          normalize=True):
                        # FIXME: why does musicbrainzngs.search_artist() not provide this information? => double request necessary
                        getMusicbrainzArtistMetadata(
                            musicbrainzngs.get_artist_by_id(
                                artist['id'], [
                                    'recordings', 'releases', 'release-groups',
                                    'works', 'aliases', 'artist-rels',
                                    'label-rels', 'tags', 'ratings'
                                ])['artist'])
                        break
            else:
                getMusicbrainzArtistMetadata(
                    musicbrainzngs.get_artist_by_id(artist_id, [
                        'recordings', 'releases', 'release-groups', 'works',
                        'aliases', 'artist-rels', 'label-rels', 'tags',
                        'ratings'
                    ])['artist'])
    except musicbrainzngs.NetworkError:
        tries += 1
        track_md.error = True
        print colored(
            "| The Musicbrainz service seems to be not available right now...",
            'red')
    except musicbrainzngs.musicbrainz.ResponseError as e:
        track_md.error = True
        print colored("| {}".format(e), 'red')