Exemplo n.º 1
0
def getDictionaryOfArtistsIDs(maxArtists):
    limit = 100
    offset = 0
    artists = []
    page = 1
    #print("fetching page number %d.." % page)
    result = musicbrainzngs.search_artists(ended="false",
                                           country="US",
                                           limit=limit)
    page_artists = result['artist-list']
    artists += page_artists
    if "artist-count" in result:
        count = result['artist-count']
    ##while len(page_artists) >= limit:
    while len(artists) < maxArtists:
        offset += limit
        page += 1
        #print("fetching page number %d.." % page)
        result = musicbrainzngs.search_artists(ended="false",
                                               country="US",
                                               limit=limit,
                                               offset=offset)
        page_artists = result['artist-list']
        artists += page_artists
    #print("")

    #for artist in artists:
    #print(u"{id}: {name}".format(id=artist['id'], name=artist["name"]))

    return artists
Exemplo n.º 2
0
def main(*argv):
    m.set_useragent("applicatiason", "0.201", "http://recabal.com")
    m.set_hostname("localhost:8080")
    m.auth("vm", "musicbrainz")

    f = open(sys.argv[1], 'r')
    for line in f.xreadlines():

        line = line.strip()
        lifeSpanString = "false,false"

        art_dict = m.search_artists(artist=line,
                                    limit=1,
                                    strict=True,
                                    tag="jazz")

        if art_dict['artist-count'] != 0:
            lifeSpanString = getLifeSpan(art_dict)

        else:
            art_dict = m.search_artists(artist=line, limit=1, strict=True)
            if art_dict['artist-count'] != 0:
                lifeSpanString = getLifeSpan(art_dict)

        print line + "," + lifeSpanString

    f.close()
Exemplo n.º 3
0
def getArtistInfo(artist, topGenres=3):
    srch = mb.search_artists(artist=artist).get('artist-list')
    if len(srch) > 0:
        info = mb.search_artists(artist=artist).get('artist-list')[0]
        (id, name, country, city, genre) = (info.get('id'), info.get('name'),
                                            info.get('country'), getArea(info),
                                            getTopGenres(info,
                                                         topGenres=topGenres))
        tmp = [name, country, city, id]
        tmp.extend(genre)
        return tmp
    else:
        tmp = [artist, None, None, None]
        tmp.extend(topGenres * [None])
        return tmp
Exemplo n.º 4
0
def artistID(artistName):
    result = musicbrainzngs.search_artists(artist=artistName,
                                           type="group",
                                           country="US")
    artistDetails = result['artist-list']

    return artistDetails[0]['id']
Exemplo n.º 5
0
def obtener_artistas():
    musicbrainzngs.set_useragent('musicbrainzngs', '2.0')

    results = musicbrainzngs.search_artists(area='Los Angeles',
                                            country="us",
                                            tag=['rock', 'metal'],
                                            limit=100)
    # q = musicbrainzngs.search_works(query='artist.name:Ozzy Osbourne',type='album')
    # q = musicbrainzngs.search_releases(artist='Ozzy Osbourne', country="us", limit=3)
    # pprint.pprint(q)
    # pprint.pprint(results)
    # i=0
    for artist in results['artist-list']:
        if 'type' in artist:
            tipo = artist['type']
        else:
            tipo = 'Group'
        bolillo = artista.artist(artist['id'], artist["name"], 'atun',
                                 artist['area']['name'], artist['ext:score'],
                                 tipo)
        # print('-------------------------------')
        # print(bolillo)
        # print(i,'===',artist['id'], artist["name"], artist['area']['name'], artist['ext:score'],artist['type'])
        # i+=1
        DataBase.Agregar_Elemento_Artista(bolillo)
Exemplo n.º 6
0
def artist_search(name, country=""):
    """
    Poišče glasbenika z imenom `name`, iz države `country`. seznam slovarjev s ključi:
        'name': (artist_name, artist_type, artist_mb_id)
        'area': (area_name, area_type, area_mb_id)
        'life-span': [date_started, date_ended]
        'genre': [list of genres preformed]
    """

    out = list()
    artists = mb.search_artists(name)["artist-list"]  # iskanje glasbenikov
    print("-----------\n", artists)

    for selected in artists:
        print(selected[""])

        # ni iz prave države
        if country and country != selected["area"]["name"]:
            continue

        area = selected["area"]
        l_s = selected["life-span"]
        genre = selected["tag-list"]

        data = dict()
        data["name"] = (selected["name"], selected["type"], selected["id"])
        data["area"] = (area["name"], area["type"], area["id"])
        data["life-span"] = [l_s["begin"], l_s["ended"]]
        data["genre"] = [g["name"] for g in genre]

        out.append(data)

    return out
Exemplo n.º 7
0
def validate_artist(artist_name):
    '''
    Makes sure we have the artist in the DB, otherwise
    it downloads the relevant information about them and stores it in the DB
    '''
    artist_id = artist_in_db(artist_name)
    if artist_id:
        return artist_id
    logger.debug("Getting MusicBrainz info for %s", artist_name)
    response = try_mb_request(lambda: mb.search_artists(artist=artist_name))
    if 0 == response['artist-count']:
        logger.warning('Got 0 possible artists for "%s", skipping', artist_name)
        country_code = -1
        is_solo = True
        mb_id = None
        name = artist_name
    else:
        artist_json = response['artist-list'][0] # Currently we take the first, maybe we should take others?
        if 'area' in artist_json and 'name' in artist_json['area']:
            country = artist_json['area']['name']
        else:
            country = -1
        name = artist_json['name']
        if 'type' in artist_json:
            is_solo = 'Person' == artist_json['type']
        else:
            is_solo = True # We just assume this for now
        country_code = validate_country(country)
        mb_id = artist_json['id']
        # This is needed because sometimes the name in artist_name doesn't match the name 
        # in the json, and in those cases we might need the extra check
        artist_id = artist_in_db_by_mbid(mb_id)
        if artist_id:
            return artist_id
    return insert_artist(name, is_solo=is_solo, country_code=country_code, mb_id=mb_id)
Exemplo n.º 8
0
def get_artist_tags(artist, limit, strict=False):

    # not very accurate and causes problem if the limit is not set to 1 (we just get the first result)
    # but good enough for now for what we want to do
    tags_string = ''
    result = m.search_artists(limit=limit, artist=artist, strict=strict)
    for artist in result['artist-list']:
        # print(u"\n{id}: {name}".format(id=artist['id'], name=artist["name"]))
        print(u"|______\t{name} ({score}%)".format(score=artist['ext:score'],
                                                   name=artist["name"]))
        tags = artist.get("tag-list", "")
        # add 000 in front of the counter
        for tag in tags:
            tag['count'] = '{:0>4}'.format(tag.get("count", ""))
        # sort by number of tags (ascending)
        import operator
        sorted_tags = sorted(tags,
                             key=operator.itemgetter('count'),
                             reverse=True)
        # print and add to returned string
        for tag in sorted_tags:
            name = tag.get("name", "")
            count = tag.get("count", "")
            print("|\t" + name + "(" + count + ")")
            tags_string += name + ', '
    return tags_string
Exemplo n.º 9
0
def fetch_artist(artist_mbid, **kwarg):
    """fetch artist info from musicBrainz
    """
    result = musicbrainzngs.search_artists(query='', limit=1, offset=None, strict=False, arid = artist_mbid)
    artist_info = {};
    if 'artist-list' in result:
        if 'type' in result['artist-list'][0]:
            artist_info['artist_type'] = result['artist-list'][0]['type']
        else:
            artist_info['artist_type'] = ''
        if 'gender' in result['artist-list'][0]:
            artist_info['artist_gender'] = result['artist-list'][0]['gender']
        else:
            artist_info['artist_gender'] = ''
        if 'begin-area' in result['artist-list'][0]:
            artist_info['artist_begin_area'] = result['artist-list'][0]['begin-area']['name']
        else:
            artist_info['artist_begin_area'] = ''
        if 'country' in result['artist-list'][0]:
            artist_info['artist_country'] = result['artist-list'][0]['country']
        else:
            artist_info['artist_country'] = ''
        if 'life-span' in result['artist-list'][0] and 'begin' in result['artist-list'][0]['life-span']:
            artist_info['artist_begin_date'] = result['artist-list'][0]['life-span']['begin']
        else:
            artist_info['artist_begin_date'] = ''
        if 'tag-list' in result['artist-list'][0]:
            tag_list = result['artist-list'][0]['tag-list']
            artist_info['artist_tags'] = ';'.join([tag['name'] for tag in tag_list])
        else:
            artist_info['artist_tags'] = ''
    return artist_info
Exemplo n.º 10
0
def get_artist_tracks_from_musicbrainz(artist):
    """
    Create Album, Track, and Solo records for artists we find in the MusicBrainzNGS API

    :param artist: an artist's name as a string to search for
    :return: Queryset of Solos
    """
    search_results = mb.search_artists(artist)
    best_result = search_results['artist-list'][0]

    if 'jazz' not in [d['name'] for d in best_result['tag-list']]:
        return Solo.objects.none()

    instrument = Solo.get_instrument_from_musicbrainz_tags(best_result['tag-list'])

    for album_dict in mb.browse_releases(best_result['id'], includes=['recordings'])['release-list']:

        album = Album.objects.create(name=album_dict['title'], artist=artist, slug=slugify(album_dict['title']))

        for track_dict in album_dict['medium-list'][0]['track-list']:
            track = Track.objects.create(album=album, name=track_dict['recording']['title'],
                                         track_number=track_dict['position'],
                                         slug=slugify(track_dict['recording']['title']))

            Solo.objects.create(track=track, artist=artist, instrument=instrument, slug=slugify(artist))

    return Solo.objects.filter(artist=artist)
def get_artist_tracks_from_musicbrianz_api(artist):
    search_results = mb.search_artists(artist)
    result = search_results['artist-list'][0]

    genre = Artist.get_genre_from_musicbrainz_tag_list(result['tag-list'])

    for album_dict in mb.browse_releases(result['id'],
                                         includes=['recordings'
                                                   ])['release-list']:
        album = Album.objects.create(name=album_dict['title'],
                                     artist=artist,
                                     slug=slugify(album_dict['title']))

        for track_dict in album_dict['medium-list'][0]['track-list']:
            track = Track.objects.create(album=album,
                                         name=track_dict['recording']['title'],
                                         track_number=track_dict['position'],
                                         slug=slugify(
                                             track_dict['recording']['title']))

            Artist.objects.create(track=track,
                                  artist=artist,
                                  genre=genre,
                                  slug=slugify(artist))

    return Artist.objects.filter(artist=artist)
Exemplo n.º 12
0
def main(s):

    result = m.search_artists(artist=s)
    best_ratio = -1
    name = ''
    artist_id = ''
    for artist in result['artist-list']:
        ratio = fuzz.token_set_ratio(s, artist['name'])
        if ratio > best_ratio:
            best_ratio = ratio
            artist_id = artist['id']
            name = artist['name']
            if ratio == 100:
                break

    if (artist_id == ''):
        print("No artist by name ", s)
        return

    result = m.search_releases(arid=artist_id, limit=15)
    artist = m.get_artist_by_id(artist_id)

    print(json.dumps(artist, sort_keys=True, indent=4))

    print("\n::::::::::::\n")
    print(json.dumps(result, sort_keys=True, indent=4))
Exemplo n.º 13
0
    def get_artist_tracks_from_musicbrainz(cls, artist):
        """
        Create Album, Track, and Solo records for artists we find in the MusicBrainzNGS API

        :param artist: an artist's name as a string to search for
        :return: Queryset of Solos
        """
        search_results = mb.search_artists(artist)
        best_result = search_results['artist-list'][0]
        instrument = Solo.get_instrument_from_musicbrainz_tags(
            best_result['tag-list'])

        for album_dict in mb.browse_releases(best_result['id'],
                                             includes=['recordings'
                                                       ])['release-list']:
            album = Album.objects.create(name=album_dict['title'],
                                         artist=artist,
                                         slug=slugify(album_dict['title']))

            for track_dict in album_dict['medium-list'][0]['track-list']:
                track = Track.objects.create(
                    album=album,
                    name=track_dict['recording']['title'],
                    track_number=track_dict['position'],
                    slug=slugify(track_dict['recording']['title']))

                Solo.objects.create(track=track,
                                    artist=artist,
                                    instrument=instrument,
                                    slug=slugify(artist))

        return Solo.objects.filter(artist=artist)
Exemplo n.º 14
0
def get_release_list(artist_str):
    """ Gets a release list from musicbrains API. """
    username = '******'
    password = '******'

    musicbrainzngs.set_useragent(username, password)
    artist_list = musicbrainzngs.search_artists(
        artist=artist_str)['artist-list']
    artist = sorted(artist_list,
                    reverse=True,
                    key=lambda artist: int(artist['ext:score']))[0]
    artist_id = artist['id']

    limit = 100
    offset = 0
    release_list = []
    release_count = 1

    while offset < release_count:
        print 'Requesting tracks {0} - {1}'.format(str(offset),
                                                   str(offset + limit))
        result = musicbrainzngs.browse_releases(artist=artist_id,
                                                release_status=['official'],
                                                release_type=['album'],
                                                includes=['recordings'],
                                                limit=limit,
                                                offset=offset)
        release_count = result['release-count']
        release_list += result['release-list']
        offset += limit

    return release_list
Exemplo n.º 15
0
 def searach_Artist_in_Area(self, area, country, tag,
                            limit):  #tag=['rock','metal']
     result = musicbrainzngs.search_artists(area=area,
                                            country=country,
                                            tag=tag,
                                            limit=limit)
     return result
Exemplo n.º 16
0
def get_artists_from_freemuse(region, country):
    artists = set()
    # TODO: parse through all pages not just first one
    url = "https://freemuse.org/regions" + "/" + region + "/" + country
    page = requests.get(url)
    soup = BeautifulSoup(page.content, 'html.parser')
    items = soup.find_all(class_="item-list")
    for item in items:
        entry = item.find(class_="entry")
        article = entry.find('p').getText()
        doc = nlp(article)
        # keep only persons
        # TODO: sometimes actually ORG is relevant too
        entities = [x.text for x in doc.ents if (x.label_ == 'PERSON')]
        if entities:
            for entity in entities:
                # cross check person with musicbrainz so we make sure the artist exists in the specified country
                # TODO: not very robust. find some way to double check

                artist_in_musicbrainz = musicbrainzngs.search_artists(
                    artist=entity,
                    country=pycountry.countries.get(
                        name=country).alpha_2)['artist-list'][0]['name']
                artists.add(artist_in_musicbrainz)
    return (artists)
Exemplo n.º 17
0
	def assign_songs(self, cleaned_tweets):
		print "Matching songs to tweets"
		cleaner_tweets = []
		tweets_used = 0
		for cleaned_tweet in cleaned_tweets:
			if " by " in cleaned_tweet['text']:
				split_text = cleaned_tweet['text'].split(' by ')
				artists_list = mbz.search_artists(split_text[0])
				try:
					mbID = artists_list['artist-list'][0]['id']
					works = mbz.search_recordings(query=split_text[0],
															arid=mbID)
					tweet = dict()	
					tweet['song'] = works['recording-list'][0]['title']
					tweet['text'] = cleaned_tweet['text']
					tweet['artist'] = artists_list['artist-list'][0]['name']
					tweet['musicbrainzID'] = works['recording-list'][0]['id']
					tweet['userID'] = cleaned_tweet['userID']
					cleaner_tweets.append(tweet)
					tweets_used += 1

				except (UnicodeEncodeError, IndexError):
					print "Unable to find song/artist"
		
		print "Tweets used: %s" % (tweets_used)
		return cleaner_tweets
Exemplo n.º 18
0
def search(request, query_type, query):
    artist_results = []
    album_results = []

    if query_type == 'artist':
        data = musicbrainzngs.search_artists(query)

        for artist in data['artist-list']:
            artist_results.append(
                [artist['name'], artist['id'],
                 artist.get('disambiguation')])

    elif query_type == 'album':
        data = musicbrainzngs.search_release_groups(query)

        #def get_album_artists(credits):
        #if len(credits) > 1:
        #artists = []
        #for item in credits:
        #	artists.append(item['artist']['name'])

        #return artists
        #else:
        #return credits[0]['artist']['name']

        for album in data['release-group-list']:
            album_results.append([
                album['title'], album['id'],
                album['artist-credit'][0]['artist']['name']
            ])

    return render(request, 'home/home.html', {
        'artist_list': artist_results,
        'album_list': album_results
    })
Exemplo n.º 19
0
 def _search_artist(self, provider, known):
     logger.info('In _search_artist(provider={}, {})'.format(provider, known))
     RESULTS_TO_REVIEW = 3
     search = [lambda: self.lastfm.search_for_artist(known).get_next_page(),
               lambda: brainz.search_artists(known)['artist-list']][provider]
     Artist = [LastArtist, BrainzArtist][provider]
     output = None
     try:
         output = search()
     except Exception as exc:
         logger.critical('Exception in search')
         logger.exception(exc)
         return None
     if output:
         logger.debug('got output')
         for i, result in zip(range(RESULTS_TO_REVIEW), output):
             artist = Artist(result)
             logger.info('Got artist result ' + str(artist.name))
             if (diff(artist.name, known) < 0.3 or (provider == BRAINZ
                                                    and 'alias-list' in result
                                                    and any(diff(alist, known) < 0.25 for alist in result['alias-list']))):
                 return artist
             else:
                 logger.info(artist.name + ' differs from ' + known)
     else:
         logger.debug('no output')
     return None
Exemplo n.º 20
0
def artist_info(
        current_file):  #name/type(Group/Person)/country/Begin/Begin area
    data = []
    key = ['name', 'type', 'country', 'life-span', 'begin-area']
    mbz.set_useragent("AIudio", "0.1")
    song = info(current_file)
    result = mbz.search_artists(artist=song['artist'])
    describe = result['artist-list'][0]
    for par in key:
        if par == 'life-span':
            try:
                data.append(describe[par]['begin'])
            except KeyError:
                data.append('None')
        elif par == 'begin-area':
            try:
                data.append(describe[par]['name'])
            except KeyError:
                data.append('None')
        else:
            try:
                data.append(describe[par])
            except KeyError:
                data.append('None')
    return data
Exemplo n.º 21
0
def add_musicbrainz_artist(cache, item):
    artist_name = item['artist']

    found, entry = cache.lookup('artist:{}'.format(artist_name))

    if found:
        log.debug("Found artist:{} in cache".format(artist_name))
    else:
        log.debug("Didn't find artist:{} in cache, running remote query".format(artist_name))
        result = musicbrainzngs.search_artists(artist=artist_name)['artist-list']
        if result:
            entry = result[0]
        else:
            entry = None

        cache.store('artist:{}'.format(artist_name), entry)

    if entry is None:
        warnings = item.get('musicbrainz.warnings', [])
        warnings += ["Unable to find artist on musicbrainz"]
        item['musicbrainz.warnings'] = warnings
    else:
        item['musicbrainz.artist'] = entry['id']
        if 'country' in entry:
            item['musicbrainz.artist.country'] = entry['country']

    return item
Exemplo n.º 22
0
 def query_artist(self, query: str, selector: Callable[[artist.Artist], bool],
                  country=None,
                  qtype: str = None) -> List[artist.Artist]:
     field = {}
     if country is not None:
         field['country'] = country.alpha_2
     if qtype is not None:
         field['type'] = qtype
     # search fields
     result = filter(
         selector,
         map(
             lambda artist: artist.Artist(
                 None,
                 name=artist.get("name", ""),
                 artist_type=Musicbrainz.parse_artist_type(artist.get("type")),
                 gender=Musicbrainz.parse_gender(artist.get("gender")),
                 country=Musicbrainz.parse_country(artist.get("country")),
                 birth=Musicbrainz.parse_birth(artist.get("life-span", {}).get("begin")),
                 death=Musicbrainz.parse_death(artist.get("life-span", {}).get("end")),
                 mbid=artist.get("id"),
             ),
             musicbrainzngs.search_artists(query, **field)['artist-list']
         )
     )
     # more infomation searching
     return list(result)
Exemplo n.º 23
0
def find_artist_by_name(name, limit=10, wanted_keys=('name', 'id', 'country', 'ext:score', 'type')):
    with musicbrainz_lock:
        params = {'artist': name.lower(), 'alias': name.lower()}
        search_results = musicbrainzngs.search_artists(limit=limit, **params)['artist-list']
        sorted_by_score = sorted(search_results, cmp=lambda x, y: max(x, y), key=lambda d: int(d['ext:score']))
        # return a list of dicts containing only the wanted values
        return [{k: v for k, v in d.items() if k in wanted_keys} for d in sorted_by_score]
Exemplo n.º 24
0
def findArtist(name, limit=1):
    artistlist = []
    artistResults = None

    chars = set('!?*-')
    if any((c in chars) for c in name):
        name = '"' + name + '"'

    criteria = {'artist': name.lower()}

    with mb_lock:
        try:
            artistResults = musicbrainzngs.search_artists(limit=limit, **criteria)['artist-list']
        except ValueError as e:
            if "at least one query term is required" in e.message:
                logger.error(
                    "Tried to search without a term, or an empty one. Provided artist (probably emtpy): %s",
                    name)
                return False
            else:
                raise
        except musicbrainzngs.WebServiceError as e:
            logger.warn('Attempt to query MusicBrainz for %s failed (%s)' % (name, str(e)))
            mb_lock.snooze(5)

    if not artistResults:
        return False
    for result in artistResults:
        if 'disambiguation' in result:
            uniquename = unicode(result['sort-name'] + " (" + result['disambiguation'] + ")")
        else:
            uniquename = unicode(result['sort-name'])
        if result['name'] != uniquename and limit == 1:
            logger.info(
                'Found an artist with a disambiguation: %s - doing an album based search' % name)
            artistdict = findArtistbyAlbum(name)
            if not artistdict:
                logger.info(
                    'Cannot determine the best match from an artist/album search. Using top match instead')
                artistlist.append({
                    # Just need the artist id if the limit is 1
                    #    'name':             unicode(result['sort-name']),
                    #    'uniquename':        uniquename,
                    'id': unicode(result['id']),
                    #    'url':                 unicode("http://musicbrainz.org/artist/" + result['id']),#probably needs to be changed
                    #    'score':            int(result['ext:score'])
                })
            else:
                artistlist.append(artistdict)
        else:
            artistlist.append({
                'name': unicode(result['sort-name']),
                'uniquename': uniquename,
                'id': unicode(result['id']),
                'url': unicode("http://musicbrainz.org/artist/" + result['id']),
                # probably needs to be changed
                'score': int(result['ext:score'])
            })
    return artistlist
Exemplo n.º 25
0
def search_artists(query='', limit=None, offset=None):
    """Search for artists."""
    api_resp = musicbrainzngs.search_artists(query=query,
                                             sortname=query,
                                             alias=query,
                                             limit=limit,
                                             offset=offset)
    return api_resp.get('artist-count'), api_resp.get('artist-list')
Exemplo n.º 26
0
def get_artist_id(name):
    """Find the ID of an artist by their name."""
    try:
        return next(
            filter(lambda a: a["name"].lower() == name.lower(),
                   musicbrainzngs.search_artists(name)["artist-list"]))["id"]
    except StopIteration:
        raise ValueError(f"Artist {name} not literally found")
Exemplo n.º 27
0
 def __init__(self, artist):
     self.artist = artist
     self.artist_id = musicbrainzngs.search_artists(
         artist=artist)['artist-list'][0][
             'id']  #  TODO apply checking in case match is partial
     works = musicbrainzngs.get_artist_by_id(self.artist_id,
                                             includes=["works"])
     self.tracks = [work['title'] for work in works['artist']['work-list']]
Exemplo n.º 28
0
def searchForArtistByName(name):
    initializeConnection()

    searchResults = mb.search_artists(artist=name)
    artists = []
    for artist in searchResults['artist-list']:
        artists.append(MusicBrainzArtist(artist['id'], artist['name']))
    return artists
Exemplo n.º 29
0
 def _retrieve_data(self, artist_name) -> dict:
     try:
         result = musicbrainzngs.search_artists(artist_name)
         return result
     except (HTTPError, musicbrainzngs.musicbrainz.ResponseError,
             TypeError) as e:
         print(e)
         return {}
Exemplo n.º 30
0
def get_artist_place_of_origin(artist_name):
    artist = musicbrainzngs.search_artists(artist_name)
    try:
        origin_country = artist['artist-list'][0]['area']['name']
    except:
        print('Either the artist or their origin cannot be found!')
        exit()
    return origin_country
Exemplo n.º 31
0
 def go(self):
     query = self.query.lower() + '*'
     return {
         'results' : map(lambda artist: {
             'id'  : artist['id'],
             'name' : artist['sort-name']
         }, musicbrainzngs.search_artists(query.encode('utf-8'), limit=10).get('artist-list', []))
     }
Exemplo n.º 32
0
def search_artist(evt):
    result = m.search_artists(artist=mainwin['searchfield'].value)
    resultList = []
    print("steeb found %s artists" % colored.cyan(len(result["artist-list"])))
    for idx, artist in enumerate(result["artist-list"]):
        resultList.append([artist["name"], artist["id"]])

    lv = mainwin['artistslist']
    lv.items = resultList
Exemplo n.º 33
0
def search_artist(query):
    r = mbz.search_artists(query, limit=5)

    artists = [{
        k: artist[k]
        for k in ('name', 'disambiguation', 'id') if k in artist
    } for artist in r['artist-list']]

    return {'query': query, 'artists': artists}
Exemplo n.º 34
0
def artist_data(artistname):
    try:
        data = musicbrainzngs.search_artists(query=artistname,
                                             limit=1,
                                             strict=False)
        if len(data["artist-list"]) >= 1:
            return data["artist-list"][0]
    except Exception as e:
        logging.warning("error while loading musicbrainz data for %s: %s",
                        artistname, e)
Exemplo n.º 35
0
 def mbz_query(self, artist, recording):
     query_dict = {'recordings': None, 'artists': None}
     if recording:
         query_dict['recordings'] = mbz.search_recordings(recording, artist)
         return query_dict
     elif artist:
         query_dict['artists'] = mbz.search_artists(artist)
         return query_dict
     else:
         return None
Exemplo n.º 36
0
def search_artist(queryArtistname):
    listArtists = mb.search_artists(artist=queryArtistname)['artist-list']
#    check that artists have correct name
    listArtistsRelevantNames = []
    for artist in listArtists:
        # check relevance of artist. TODO: break do offset and limit, not to miss artist 
        if artist['name'] == queryArtistname:
            listArtistsRelevantNames.append(artist)
     
    return listArtistsRelevantNames
Exemplo n.º 37
0
def get_artist_id(artist):
    '''Get the musicbrainz artist id for feeding into `musicbrainzngs.browse_releases`'''
    possible_ids = mb.search_artists(artist=artist, strict=True)['artist-list']
    try:
        artist = [
            res['id'] for res in possible_ids if int(res['ext:score']) == 100
        ][0]
    except IndexError:
        raise ArtistNotFoundError(f'Artist {artist} not found')
    return artist
Exemplo n.º 38
0
def search_artist(queryArtistname):
    listArtists = mb.search_artists(artist=queryArtistname)['artist-list']
#    check that artists have correct name
    listArtistsRelevantNames = []
    for artist in listArtists:
        # check relevance of artist. TODO: break do offset and limit, not to miss artist 
        if artist['name'] == queryArtistname:
            listArtistsRelevantNames.append(artist)
     
    return listArtistsRelevantNames
Exemplo n.º 39
0
    def _request(query, artist, album=None, track=None):
        results = None
        if track:
            results = musicbrainzngs.search_recordings(query=query)
        elif album:
            results = musicbrainzngs.search_releases(query=query)
        elif artist:
            results = musicbrainzngs.search_artists(query=query)

        return results
Exemplo n.º 40
0
def api_search_artist(name):
    try:
        mbz.set_useragent("Artistics", "v1.0", "*****@*****.**")
        result = mbz.search_artists(artist=name)
    except mbz.WebServiceError as exc:
        result = {}

    if "artist-list" in result:
        return result["artist-list"]
    return None
def RetrieveArtistsList(outLoc,oset=0,query="type:person"):
    outDoc = open(outLoc,"a")
    art_list = "artist-list"
    art_count = "artist-count"
    alias_list = "alias-list"
    name = "name"
    artists = mb.search_artists(query=query,limit=100)
    offset = oset
    print artists[art_count]
    while offset < artists[art_count]:
        for artist in artists[art_list]:
            outDoc.write(artist[name].encode('UTF-8') + "\n")
            if alias_list in artist:
                for alias in artist[alias_list]:
                    if "alias" in alias:
                        outDoc.write(alias["alias"].encode('UTF-8') + "\n")
        time.sleep(3)
        offset += 100
        print offset
        artists = mb.search_artists(query="type:person",limit=100,offset=offset)
    outDoc.close()
    print "finished"
Exemplo n.º 42
0
	def GetMusicBrainz(self):
		mbrainz.set_useragent("Example music app", "0.1", "http://example.com/music")
		result = mbrainz.search_artists(self.name)['artist-list'][0]
		# for result in results:
		#   if int(result['ext:score']) > 75:
		#       break
		#print result
		self.musicbrainz_id = result['id']
		self.mbrainz_cache = mbrainz.get_artist_by_id(self.musicbrainz_id, ['artist-rels', 'url-rels'])['artist']
		if 'url-relation-list' in self.mbrainz_cache:
			self.social_media = self.mbrainz_cache.pop('url-relation-list')
		if 'artist-relation-list' in self.mbrainz_cache:
			self.aliases = self.mbrainz_cache.pop('artist-relation-list')
Exemplo n.º 43
0
def artist_mbid_find(artist_name):
    """
    Returns an artist MBID
    """
    artist_name = artist_name.decode('latin-1').encode('ascii', 'asciify')
    mb_artist_list = m.search_artists(artist_name)['artist-list'][0]
    mb_artist_name = mb_artist_list['name'].strip().encode('ascii', 'asciify')
    try: mb_artist_alias = mb_artist_list['alias-list']
    except: mb_artist_alias = ''
    mb_artist_id = mb_artist_list['id']

    
    if mb_artist_name and ((artist_name.lower() == mb_artist_name.lower()) or (artist_name in mb_artist_alias)):
        return mb_artist_id
Exemplo n.º 44
0
def get_artists_by_name(name):

    artists = dict()
    result = musicbrainzngs.search_artists(artist=name)

    for artist in result['artist-list']:

        artist_name = artist['name']
        artist_mbid = artist['id']

        if artist['ext:score'] == "100":
            artists.update({artist_mbid:artist_name})

    return artists
Exemplo n.º 45
0
def main(*argv):
	m.set_useragent("applicatiason", "0.201", "http://recabal.com")
	m.set_hostname("localhost:8080")
	m.auth("vm", "musicbrainz")
	
	f = open(sys.argv[1],'r')
	for line in f.xreadlines():
		
		line = line.strip();
		lifeSpanString = "false,false"

		art_dict = m.search_artists(artist=line,limit=1,strict=True,tag="jazz")
		
		if art_dict['artist-count']!=0:
			lifeSpanString = getLifeSpan(art_dict)
			
		else:
			art_dict = m.search_artists(artist=line,limit=1,strict=True)
			if art_dict['artist-count']!=0:
				lifeSpanString = getLifeSpan(art_dict)			

		print line+","+lifeSpanString
				
	f.close()
Exemplo n.º 46
0
def searchMusicBrainzArtist(artist):
	"""searchMusicBrainzArtist takes an artist name as a string and returns a list of artists
	that match the searched name."""
	
	result = musicbrainzngs.search_artists(artist=artist, limit=5)
	# On success, result is a dictionary with a single key:
	# "artist-list", which is a list of dictionaries.
	results = []
	if not result['artist-list']:
		return results
	for artist in result['artist-list']:
		
		# If we haven't seen this artist name yet, add it to the return list
		if artist['name'] not in results:
			results.append(artist['name'])
	return results
Exemplo n.º 47
0
def bulk_import_artist():
    terms = [
        # 'bb king',
        # 'elvis',
        # 'black sabbath',
        # 'fugazi',
        # 'minor threat',
        # 'converge',
        # '\'68',
        # 'old man gloom',
        # 'citizen',
        # 'blues brothers',
        # 'cult of luna',
        # 'our lady',
        # 'so long forgotten',
        # 'cash',
        # 'z',
        # 'ramones',
        # 'kesha',
        # 'nine inch nails',
        # 'bill nye',
        # 'my bloody valentine',
        # 'ride',
        # 'slabdragger',
        # 'slowdive',
        #  'oasis',
        # 'reo',
        # 'cloakroom',
        # 'underoath',
        # 'brand new',
        # 'taking back sunday',
        # 'the cure',
        # 'jesu',
        # 'jesus and the mary chain',
        # 'zozobra',
        # 'cave in',
        # 'led zeppelin',
        'pity sex',
        'looming', 
        'our lady',
    ]
    for search in terms:
        print 'searching {}'.format(search)
        result = mb.search_artists(artist=search, type="group", country="US")
        for artist in result['artist-list']:
            import_artist(artist)
Exemplo n.º 48
0
def get_artists_for_city(location):
    #TODO add celery here
    city = location.name
    musicbrainzngs.set_useragent("CultureRadio", 1)
    response = musicbrainzngs.search_artists(area=city, beginarea=city, endarea=city)
    response_artist_list = response.get('artist-list')
    for artist in response_artist_list:
        spotify_artists = get_spotify_artists_for_name(artist.get('name'))
        if len(spotify_artists) == 0:
            continue
        for spotify_artist in spotify_artists:
            uri, created = SpotifyData.objects.get_or_create(uri=spotify_artist.get('uri'))
            uri.save()
            a, created = Artist.objects.get_or_create(name=spotify_artist.get('name'), spotifyUri=uri)
            a.location.add(location)
            a.save()
            get_tracks_for_artist(a)
Exemplo n.º 49
0
    def test_search_artists(self):
        musicbrainzngs.search_artists("Dynamo Go")
        self.assertEqual("http://musicbrainz.org/ws/2/artist/?query=Dynamo+Go", self.opener.get_url())

        musicbrainzngs.search_artists(artist="Dynamo Go")
        expected_query = 'artist:(dynamo go)'
        expected = 'http://musicbrainz.org/ws/2/artist/?query=%s' % musicbrainzngs.compat.quote_plus(expected_query)
        self.assertEquals(expected, self.opener.get_url())

        # Invalid query field
        with self.assertRaises(musicbrainzngs.InvalidSearchFieldError):
            musicbrainzngs.search_artists(foo="value")
Exemplo n.º 50
0
def artist_name_checker_mb(input_file, column_no):
    """
    Checks if the name of a BDMC artist is on MB. Returns
    on_MB list 
    non_MB list
    """
    on_MB = []
    non_MB = []

    un_elem, all_elem = unique_elements(input_file, int(column_no))

    for j, artist in enumerate(un_elem[0:]):
        print j
        artist_mb_name = ''
        artist_mb_name_ascii = ''
        artist_mb_type = ''
        artist_mb_country = ''
        artist_mb_alias = ''
        time.sleep(1)                       # musicbrainz TOS

        artist_dec = artist.decode('latin-1')
        artist_ascii = artist_dec.encode('ascii', 'asciify')

        try: artist_mb = m.search_artists(artist_dec)['artist-list'][0]
        except: artist_mb = ''
        try: artist_mb_name = artist_mb['name']
        except: pass
        try: artist_mb_name_ascii = artist_mb_name.encode('ascii', 'asciify')
        except: artist_mb_name_ascii = ''
        try: artist_mb_type = artist_mb['type']
        except: pass
        try: artist_mb_country = artist_mb['country']
        except: pass
        try: artist_mb_alias = artist_mb['alias-list']
        except: artist_mb_alias = ''
        

        if artist_mb_name and ((artist_ascii.upper() == artist_mb_name_ascii.upper()) or (artist_ascii in artist_mb_alias)):
            on_MB.append(artist)

        else:
            non_MB.append(artist)

    return on_MB, non_MB
Exemplo n.º 51
0
def resolve_title_as_artist_musicbrainz(artist_name, sim_threshold=0.5):
	try:
		logging.info("Resolving %s as artist using MusicBrainz" % artist_name)
		mb.set_useragent("Juggle Mobile", "0.1", "http://juggle.fe.up.pt")
		
		res = mb.search_artists(artist=artist_name)['artist-list']
		res = sorted(res, key=lambda artist: int(artist['ext:score']), reverse=True)
		
		if len(res) > 0 and sentence_similarity(artist_name, res[0]['name']) > sim_threshold:
			html = urllib2.urlopen('http://musicbrainz.org/artist/%s' % res[0]['id']).read()
			soup = BeautifulSoup(html, 'lxml')
			wikipedia = soup.select('li.wikipedia a[href]')
			if len(wikipedia) > 0:
				return (artist_name, wikipedia[0]['href'][wikipedia[0]['href'].rfind('/')+1:].replace('_', ' '))
	except:
		logging.warning("Request to MusicBrainz failed for %s, skipping resolution" % artist_name)
		pass 

	return (artist_name, None)
Exemplo n.º 52
0
def getArtist(artist,apihandle):
  mbArtists = [ (x['name'],x['score'])
    for x in mb.search_artists(query=mbquote(artist),limit=int(50*mbMultiplier))['artist-list']
    if 'name' in x and 'score' in x]
  mbDict = { }
  for mbAr in mbArtists:
    if mbAr[0] not in mbDict:
      vals = [x[1]**2 for x in mbArtists if x==mbAr[0]]
      mbDict[mbAr[0]] = [sqrt(mean(vals))/100]
  maxWhatcdScore = 0
  for mbAr,mbScores in mbDict.items():
    whatcd_artist = apihandle.request("artist", artistname=whatquote(mbAr))["response"]
    artist = unescape(whatcd_artist['name'])
    mbScores.append(log(mean(3*whatcd_artist["statistics"]["numSeeders"],2*whatcd_artist["statistics"]["numSnatches"])))
    if mbScores[-1]>maxWhatcdScore:
      maxWhatcdScore = mbScores[-1]
    mbScores.append(2*Levenshtein.ratio(artist.lower(),mbAr.lower()))
  for mbScores in mbDict.values():
    mbScores[1] /= maxWhatcdScore
  return max([(sum(scores),name)
    for name, scores in mbDict.items()]
    +[(1.5,artist)])[1]
Exemplo n.º 53
0
def search_artists(artist, limit):
    from lxml import etree

    root = etree.XML(u'<artists></artists>')
    result = musicbrainzngs.search_artists(artist=artist, limit=limit)

    if debug:
        pprint.pprint(result)

    if result['artist-list']:
        for (idx, artist) in enumerate(result['artist-list']):
            artistNode = etree.SubElement(root, "id")
            etree.SubElement(artistNode, "id").text = artist['id']
            etree.SubElement(artistNode, "name").text = artist['name']
            etree.SubElement(artistNode, "sort-name").text = artist['sort-name']
    else:
        etree.SubElement(root, "error").text = "No Artists found"
        log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))
        sys.exit(1)

    log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))

    sys.exit(0)
Exemplo n.º 54
0
def get_release_list(artist_str):
    """ Gets a release list from musicbrains API. """
    username = '******'
    password = '******'
    
    musicbrainzngs.set_useragent(username, password)
    artist_list = musicbrainzngs.search_artists(artist=artist_str)['artist-list']
    artist = sorted(artist_list, reverse=True, key=lambda artist:int(artist['ext:score']))[0]
    artist_id = artist['id']

    limit = 100
    offset = 0
    release_list = []
    release_count = 1

    while offset < release_count:
        print 'Requesting tracks {0} - {1}'.format(str(offset), str(offset+limit))
        result = musicbrainzngs.browse_releases(artist=artist_id, release_status=['official'], release_type=['album'], includes=['recordings'], limit=limit, offset=offset)
        release_count = result['release-count']
        release_list += result['release-list']
        offset += limit
    
    return release_list
Exemplo n.º 55
0
    def getArtistID(self, known_data):

        '''
        Match the given 'artist' entry to a MBrainz Artist ID
        Returns Artist MB-ID
        '''

        # Blocking Call to MBrainz Server
        result = musicbrainzngs.search_artists(known_data['artist'])

        for x, r in enumerate(result['artist-list']):

            # Added attempt to make a match if search is ambiguous
            # eg. (more than 1 artist called "X")
            try:

                if 'genre' in known_data:

                    if known_data['genre'].lower() in \
                       r['disambiguation'].lower():

                        self.Logger.msg('Returning Artist ID - {}'.format(
                            result['artist-list'][x]['id'])
                        )

                        return result['artist-list'][x]['id']

            except:

                continue

        self.Logger.msg('Returning Fallback Artist ID - {}'.format(
            result['artist-list'][0]['id'])
        )

        # Return a default result if no other match is made
        return result['artist-list'][0]['id']
Exemplo n.º 56
0
def search_artists(query='', limit=None, offset=None):
    """Search for artists."""
    api_resp = musicbrainzngs.search_artists(query=query, sortname=query, alias=query, limit=limit, offset=offset)
    return api_resp.get('artist-count'), api_resp.get('artist-list')
Exemplo n.º 57
0
 def search_artist(name):
     results = musicbrainzngs.search_artists(name)
     return results
Exemplo n.º 58
0
def getAlbumArtistNames(album,artist, apihandle, song=None):
  '''
  Given a supposed album and artist, determine the real ones
  '''
  def searchWhatAlbums(args):
    if len(args)==0:
      return []
    whatResponse = apihandle.request(action='browse',searchstr=args[0])
    if whatResponse['status']=='success':
      args.pop(0)
      return searchWhatAlbums(args)+[x for x in whatResponse['response']['results'] if 'artist' in x and 'groupName' in x]
    return []
  mbAlbums = []
  parens = re.compile('[\(\[].*[\)\]]')
  if song is not None:
    includes = ['recordings']
    artists = set(re.split(' &|and|ft\.?|featuring|feat\.? ',artist))
    if len(artists) > 1:
      artists.add(artist)
    for ar in artists:
      mbAlbums += [dict(list(x.items())+[("artist-credit-phrase", releases['artist-credit-phrase'])]) for releases in mb.search_recordings(query=song, limit=int(50*mbMultiplier), artistname=mbquote(ar), release=mbquote(album))['recording-list'] for x in releases['release-list']]
      mbAlbums += mb.search_releases(artist=mbquote(ar),query=mbquote(album),limit=int(25*mbMultiplier))['release-list']
      lastfmres = [x['mbid'] for x in lookup('lastfm','songsearch',{'artist':ar, 'song':song})['results']['trackmatches']['track'] if 'mbid' in x and len(x['mbid'])>0]
      if len(lastfmres)>0:
        for lastfmRecId in set(lastfmres):
          try:
            lastfmAlbum = mb.get_recording_by_id(id=lastfmRecId,includes=['releases','artist-credits'])
            for alb in lastfmAlbum['recording'].pop('release-list'):
              alb['medium-list'] = [{}]
              alb['medium-list'][0]['track-list'] = []
              alb['medium-list'][0]['track-list'].append(lastfmAlbum)
              alb['artist-credit-phrase'] = lastfmAlbum['recording']['artist-credit-phrase']
              mbAlbums.append(alb)
          except Exception as e:
            print(e)
  else:
    includes = []
    mbArtists = mb.search_artists(query=mbquote(artist),limit=int(40*mbMultiplier))['artist-list']
    mbAlbums += mb.search_releases(artist=mbquote(artist),query=mbquote(album),limit=int(50*mbMultiplier))['release-list']
    for mbArtist in mbArtists:
      if Levenshtein.ratio(artist.lower(),mbArtist['name'].lower()) > 0.75:
        mbAlbums+=[ dict(list(x.items())+[('artist-credit-phrase',mbArtist['name'])]) for x in mb.browse_releases(artist=mbArtist['id'],includes=includes,limit=25)['release-list']]
  if (len(album)<7 and ('/' in album or ' & ' in album) and 's' in album.lower() and 't' in album.lower()) or ('self' in album.lower() and 'titled' in album.lower()):
    mbAlbums += mb.search_releases(artist=mbquote(artist),query=mbquote(artist),limit=int(25*mbMultiplier))['release-list']
  temp = []
  for x in mbAlbums[:]:
    if x["id"] in temp and not ('medium-list' in x and len(x['medium-list'])>0 and all('track-list' in z and len(z['track-list'])>0 for z in x['medium-list'])):
      mbAlbums.remove(x)
    else:
      temp.append(x['id'])
  print("Done searching musicbrainz for album suggestions, have "+str(len(mbAlbums))+" to rank")
  
  ranks = {}
  for x in mbAlbums:
    ranks[x['id']] = Levenshtein.ratio(album.lower(),x['title'].lower())
    if song is not None:
      x['song'] = {}
      temp = ([(y['recording']['title'] if 'recording' in y else y['title'],
          int(float(
            y['recording']['length'] if 'recording' in y and 'length' in y['recording'] 
            else (y['track_or_recording_length'] if 'track_or_recording_length' in x 
            else y['length'] if 'length' in x else 0)
          )/1000.))
        for tracklist in x['medium-list']
        for y in tracklist['track-list']]
        if 'medium-list' in x and len(x['medium-list'])>0 and all('track-list' in z and len(z['track-list'])>0 for z in x['medium-list'])
        else getSongs(
          {"artist":x['artist-credit-phrase'], 
          "groupName":x['title']}))
      x['song']['name'], x['song']['duration'] = (max(temp, 
        key=lambda y: Levenshtein.ratio(y[0].lower(),song.lower())) if len(temp)>0 else ("",-1))
      if ranks[x['id']] < Levenshtein.ratio(x['song']['name'].lower(),song.lower()):
        ranks[x['id']] /= 6
        ranks[x['id']] +=  (Levenshtein.ratio(x['song']['name'].lower(),song.lower())
          + Levenshtein.ratio(parens.sub('',x['song']['name'].lower()),parens.sub('',song.lower())) )*5/12
      else:
        ranks[x['id']] /= 3
        ranks[x['id']] +=  (Levenshtein.ratio(x['song']['name'].lower(),song.lower())
          + Levenshtein.ratio(parens.sub('',x['song']['name'].lower()),parens.sub('',song.lower())) )/3
    ranks[x['id']] += Levenshtein.ratio(artist.lower(),x['artist-credit-phrase'].lower())*7/6
  if len(ranks) == 0:
    return None
  mbAlbumId, mbAlbumRank = max(ranks.items(),key=(lambda x:x[1]))
  mbAlbum = [x for x in mbAlbums if x['id']==mbAlbumId][0]
  print("For the artist and album derived from the provided dir ("+artist+" and "+album+" respectively),\nthe following artist and album was matched on musicbrains:")
  print("Artist: "+mbAlbum['artist-credit-phrase'])
  print("Album: "+mbAlbum['title'])
  whatAlbums = searchWhatAlbums([mbAlbum['title']+' '+mbAlbum['artist-credit-phrase'], artist+' '+album])
  if len(whatAlbums) == 0:
    whatAlbums = searchWhatAlbums([artist,album,mbAlbum['title'],mbAlbum['artist-credit-phrase']])
    if len(whatAlbums) == 0:
      return None
  whatAlbums = sorted(whatAlbums, key=(lambda x:
      Levenshtein.ratio(x['groupName'],mbAlbum['title'])
      +Levenshtein.ratio(x['groupName'].lower(),album.lower())*3/8
      +Levenshtein.ratio(x['artist'],mbAlbum['artist-credit-phrase'])
      +Levenshtein.ratio(x['artist'].lower(),artist.lower())*5/8),
    reverse=True)#[:min(10,len(whatAlbums))]
  whatAlbum = whatAlbums[0]
  whatAlbum['artist-credit-phrase'] = mbAlbum['artist-credit-phrase']
  if song is not None:
    whatAlbum['song'] = mbAlbum['song']
  print("For the album and artist found on musicbrainz, the following torrent group was found on what:")
  print("Artist: "+whatAlbum['artist'])
  print("Album: "+whatAlbum['groupName'])
  return whatAlbum
 def testSearchArtist(self):
     musicbrainzngs.search_artists("Dynamo Go")
     self.assertEqual("http://musicbrainz.org/ws/2/artist/?query=Dynamo+Go", self.opener.get_url())