def testGetArtist(self):
        artistid = "952a4205-023d-4235-897c-6fdb6f58dfaa"
        musicbrainzngs.get_artist_by_id(artistid)
        self.assertEqual("http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa", _common.opener.get_url())

        # Test an include
        musicbrainzngs.get_artist_by_id(artistid, "recordings")
        self.assertEqual("http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings", _common.opener.get_url())
示例#2
0
    def testGetArtist(self):
        artistid = "952a4205-023d-4235-897c-6fdb6f58dfaa"
        musicbrainzngs.get_artist_by_id(artistid)
        self.assertEqual(
            "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa",
            _common.opener.get_url())

        # Test an include
        musicbrainzngs.get_artist_by_id(artistid, "recordings")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings",
            _common.opener.get_url())
示例#3
0
def main():
    m.set_useragent("application", "0.01", "http://example.com")
    print m.get_artist_by_id("952a4205-023d-4235-897c-6fdb6f58dfaa", [])
    #print m.get_label_by_id("aab2e720-bdd2-4565-afc2-460743585f16")
    #print m.get_release_by_id("e94757ff-2655-4690-b369-4012beba6114")
    #print m.get_release_group_by_id("9377d65d-ffd5-35d6-b64d-43f86ef9188d")
    #print m.get_recording_by_id("cb4d4d70-930c-4d1a-a157-776de18be66a")
    #print m.get_work_by_id("7e48685c-72dd-3a8b-9274-4777efb2aa75")

    #print m.get_releases_by_discid("BG.iuI50.qn1DOBAWIk8fUYoeHM-")
    #print m.get_recordings_by_isrc("GBAYE9300106")

    m.auth("", "")
示例#4
0
def main():
	m.set_useragent("application", "0.01", "http://example.com")
	print m.get_artist_by_id("952a4205-023d-4235-897c-6fdb6f58dfaa", [])
	#print m.get_label_by_id("aab2e720-bdd2-4565-afc2-460743585f16")
	#print m.get_release_by_id("e94757ff-2655-4690-b369-4012beba6114")
	#print m.get_release_group_by_id("9377d65d-ffd5-35d6-b64d-43f86ef9188d")
	#print m.get_recording_by_id("cb4d4d70-930c-4d1a-a157-776de18be66a")
	#print m.get_work_by_id("7e48685c-72dd-3a8b-9274-4777efb2aa75")

	#print m.get_releases_by_discid("BG.iuI50.qn1DOBAWIk8fUYoeHM-")
	#print m.get_recordings_by_isrc("GBAYE9300106")

	m.auth("", "")
    def testGetArtist(self):
        artistid = "952a4205-023d-4235-897c-6fdb6f58dfaa"
        musicbrainzngs.get_artist_by_id(artistid)
        self.assertEqual(
            "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa",
            self.opener.get_url())

        # Test an include
        musicbrainzngs.get_artist_by_id(artistid, "recordings")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings",
            self.opener.get_url())

        # More than one include
        musicbrainzngs.get_artist_by_id(artistid, ["recordings", "aliases"])
        expected = "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings+aliases"
        self.assertEqual(expected, self.opener.get_url())

        # with valid filters
        musicbrainzngs.get_artist_by_id(artistid, ["release-groups"],
                                        release_type=["album"])
        self.assertTrue("type=album" in self.opener.get_url())

        # with invalid filters
        self.assertRaises(musicbrainzngs.UsageError,
                          musicbrainzngs.get_artist_by_id,
                          artistid, ["release-groups"],
                          release_status=["official"])
    def testGetArtist(self):
        artistid = "952a4205-023d-4235-897c-6fdb6f58dfaa"
        musicbrainzngs.get_artist_by_id(artistid)
        self.assertEqual(
            "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa", self.opener.get_url()
        )

        # Test an include
        musicbrainzngs.get_artist_by_id(artistid, "recordings")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings",
            self.opener.get_url(),
        )

        # More than one include
        musicbrainzngs.get_artist_by_id(artistid, ["recordings", "aliases"])
        expected = "http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings+aliases"
        self.assertEqual(expected, self.opener.get_url())

        # with valid filters
        musicbrainzngs.get_artist_by_id(artistid, ["release-groups"], release_type=["album"])
        self.assertTrue("type=album" in self.opener.get_url())

        # with invalid filters
        self.assertRaises(
            musicbrainzngs.UsageError,
            musicbrainzngs.get_artist_by_id,
            artistid,
            ["release-groups"],
            release_status=["official"],
        )
示例#7
0
 def musicbrainz_connect(self, mb_user, mb_pass, mb_appid):
     # If you plan to submit data, authenticate
     m.auth(mb_user, mb_pass)
     m.set_useragent(mb_appid[0], mb_appid[1])  # 0=version, 1=app
     # If you are connecting to a different server
     # m.set_hostname("beta.musicbrainz.org")
     # m.set_rate_limit(limit_or_interval=1.0, new_requests=1)
     try:  # test request
         m.get_artist_by_id("952a4205-023d-4235-897c-6fdb6f58dfaa", [])
         self.ONLINE = True
         return True
     except WebServiceError as exc:
         log.error("connecting to MusicBrainz: %s" % exc)
         self.ONLINE = False
         return False
示例#8
0
 def aliases_for_artist(self, artistid):
     a = mb.get_artist_by_id(artistid, includes=["aliases"])
     a = a["artist"]
     ret = []
     for alias in a.get("alias-list", []):
         ret.append(alias["alias"])
     return list(set(ret))
示例#9
0
def add_musicbrainz_artist_urls(cache, item):
    if 'musicbrainz.artist' not in item:
        # We assume add_musicbrainz_artist() was already called, so
        # we assume we couldn't find this artist in the cache.
        pass
    else:
        artist_name = item['artist']
        artist_musicbrainz_id = item['musicbrainz.artist']
        found, result_urls = cache.lookup('artist:{}:urls'.format(artist_musicbrainz_id))
        if found:
            log.debug("Found artist urls for {} in cache".format(artist_name))
        else:
            log.debug("Didn't find artist urls for {} in cache, running remote query".format(artist_name))

            result = musicbrainzngs.get_artist_by_id(item['musicbrainz.artist'], includes='url-rels')

            result_urls = result['artist'].get('url-relation-list', [])

            cache.store('artist:{}:urls'.format(artist_musicbrainz_id), result_urls)

        item_urls = item.get('musicbrainz.artist.urls', [])
        for result_url in result_urls:
            item_urls.append(
                { 'musicbrainz.url.type': result_url['type'], 'musicbrainz.url.target': result_url['target'] })
        item['musicbrainz.artist.urls'] = item_urls
    return item
示例#10
0
 def aliases_for_artist(self, artistid):
     a = mb.get_artist_by_id(artistid, includes=["aliases"])
     a = a["artist"]
     ret = []
     for alias in a.get("alias-list", []):
         ret.append(alias["alias"])
     return list(set(ret))
示例#11
0
def get_artist(artistid):
    from lxml import etree

    root = etree.XML(u'<artist></artist>')

    # lookup the artist id
    result = musicbrainzngs.get_artist_by_id(artistid, includes=['url-rels'])

    if debug:
        pprint.pprint(result)

    if result:
        etree.SubElement(root, "id").text = result['artist']['id']
        etree.SubElement(root, "name").text = result['artist']['name']
        etree.SubElement(root, "sort-name").text = result['artist']['sort-name']

        if 'url-relation-list' in result['artist']:
            urls = result['artist']['url-relation-list']
            if urls:
                for (idx, url) in enumerate(urls):
                    node = etree.SubElement(root, "url")
                    node.text = url['target']
                    node.set("type", url['type'])
    else:
        etree.SubElement(root, "error").text = "MusicBrainz ID was not 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)
示例#12
0
def artist_gender(artist_musicbrainz_id) -> 'artist_gender':
    """States whether the artist is a male or a female

    Arguments:
        artist_musicbrainz_id {str} -- 

    Returns:
        str -- Either Male or Female
    """
    if artist_musicbrainz_id is not None:
        artist = musicbrainzngs.get_artist_by_id(
            artist_musicbrainz_id['value'])
        try:
            artist_type = artist['artist']['gender']
        except KeyError:
            logging.getLogger('root.features').warning(
                f"Artist {artist_musicbrainz_id} has no gender, skipping")
            return None

        if artist['artist']['gender'] not in ['Male', 'Female']:
            logging.getLogger(
                f"Artist {artist_musicbrainz_id} has unknown gender {artist['artist']['gender']}, skipping"
            )
            return None
        else:
            return {'value': artist['artist']['gender']}
示例#13
0
def music_get_artist_tracks(artist_id: str, locale: str):
    try:
        recordings = musicbrainzngs.browse_recordings(
            artist_id, limit=100)["recording-list"]
    except ResponseError as error:
        abort(error.cause.code)
        return
    artist = musicbrainzngs.get_artist_by_id(artist_id)["artist"]
    artist_name: str = artist["name"]

    doc: Document = minidom.Document()
    feed: Element = create_feed(doc, artist_name, artist_id, request.endpoint)

    for recording in recordings:
        id: str = recording["id"]
        title: str = recording["title"]
        entry: Element = create_entry(
            doc, title, id,
            f"/v3.2/{locale}/music/artist/{artist_id}/tracks/{id}")
        feed.appendChild(entry)

        # Create primaryArtist element
        primary_artist_elem: Element = doc.createElement("primaryArtist")
        primary_artist_props = {"id": artist_id, "name": artist_name}
        set_values_as_elements(doc, primary_artist_elem, primary_artist_props)
        entry.appendChild(primary_artist_elem)

    xml_str = doc.toprettyxml(indent="\t")
    return Response(xml_str, mimetype=MIME_XML)
示例#14
0
    def entity_lookup(artist, album=None, track=None):
        query = MusicEntityGenerator._build_query(artist, album, track)
        results = MusicEntityGenerator._request(query, artist, album, track)

        # Parse result into (artist, releases, recording)
        if results:
            if track:
                results = results['recording-list']
            elif album:
                results = results['release-list']
            else:
                results = results['artist-list']

            if len(results) > 0:
                _recording = None
                _releases = None
                _artist = None

                if track:
                    (_recording, _releases) = \
                        MusicEntityGenerator._parse_recordings(results)
                    _artist = musicbrainzngs.get_artist_by_id(
                        _recording['artist-credit'][0]['artist']['id']
                    )['artist']
                elif album:
                    _artist, _releases = \
                        MusicEntityGenerator._parse_releases(results)
                elif artist:
                    _artist = results[0]

                return _artist, _releases, _recording
        return None
示例#15
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))
示例#16
0
def main():
    m.set_useragent("application", "0.01", "http://example.com")
    print(m.get_artist_by_id("952a4205-023d-4235-897c-6fdb6f58dfaa", []))
    print(m.get_label_by_id("aab2e720-bdd2-4565-afc2-460743585f16"))
    print(m.get_release_by_id("e94757ff-2655-4690-b369-4012beba6114"))
    print(m.get_release_group_by_id("9377d65d-ffd5-35d6-b64d-43f86ef9188d"))
    print(m.get_recording_by_id("cb4d4d70-930c-4d1a-a157-776de18be66a"))
    print(m.get_work_by_id("7e48685c-72dd-3a8b-9274-4777efb2aa75"))

    print(m.get_releases_by_discid("BG.iuI50.qn1DOBAWIk8fUYoeHM-"))
    print(m.get_recordings_by_puid("070359fc-8219-e62b-7bfd-5a01e742b490"))
    print(m.get_recordings_by_isrc("GBAYE9300106"))

    m.auth("", "")
    m.submit_barcodes(
        {"e94757ff-2655-4690-b369-4012beba6114": "9421021463277"})
    m.submit_tags(recording_tags={
        "cb4d4d70-930c-4d1a-a157-776de18be66a": ["these", "are", "my", "tags"]
    })
    m.submit_tags(
        artist_tags={"952a4205-023d-4235-897c-6fdb6f58dfaa": ["NZ", "twee"]})

    m.submit_ratings(
        recording_ratings={"cb4d4d70-930c-4d1a-a157-776de18be66a": 20})
    m.submit_echoprints(
        {"e97f805a-ab48-4c52-855e-07049142113d": "anechoprint1234567"})
示例#17
0
def artist_genres(artist_musicbrainz_id) -> 'musical_genre_musicbrainz_id':
    """Extracts the genres interpreted by an artist

    Arguments:
        artist_musicbrainz_id {str} -- 

    Returns:
        list -- List of musicbrainz genres ids. 
    """
    artist = musicbrainzngs.get_artist_by_id(artist_musicbrainz_id['value'],
                                             includes=['tags'])['artist']
    genres = []

    try:
        tags = artist['tag-list']
    except:
        logging.getLogger('root.features').warning(
            f"No tag list associated with artist {artist_musicbrainz_id['value']}"
        )
        return None

    for tag in tags:
        try:
            musicbrainz_genre_id = genres_musicbrainz(tag['name'])
            genres.append(musicbrainz_genre_id)
        except KeyError:
            continue

    if len(genres) > 0:
        return [{'value': g} for g in genres]
    else:
        logging.getLogger('root.features').warning(
            f"No genres associated with artist {artist_musicbrainz_id['value']}"
        )
示例#18
0
def music_get_artist_tracks(artist_id: str, locale: str):
    recordings = musicbrainzngs.browse_recordings(artist_id,
                                                  limit=100)["recording-list"]
    artist = musicbrainzngs.get_artist_by_id(artist_id)["artist"]
    artist_name: str = artist["name"]

    doc: Document = minidom.Document()
    feed: Element = create_feed(doc, artist_id, artist_name, request.endpoint)

    for recording in recordings:
        id: str = recording["id"]
        title: str = recording["title"]
        entry: Element = create_entry(
            doc, title, id,
            f"/v3.2/{locale}/music/artist/{artist_id}/tracks/{id}")
        feed.appendChild(entry)

        # Create primaryArtist element
        primary_artist_elem: Element = doc.createElement("primaryArtist")

        artist_id_element: Element = doc.createElement("id")
        set_element_value(artist_id_element, artist_id)
        primary_artist_elem.appendChild(artist_id_element)

        artist_name_element: Element = doc.createElement("name")
        set_element_value(artist_name_element, artist_name)
        primary_artist_elem.appendChild(artist_name_element)
        entry.appendChild(primary_artist_elem)

    #doc.appendChild(feed)
    xml_str = doc.toprettyxml(indent="\t")
    return Response(xml_str, mimetype=MIME_XML)
示例#19
0
    def get_drops_for_musicbrainz_belgians(self):
        for mbid in self.mbids:
            try:
                musicbrainzngs.set_useragent("versgeperst", "0.1", contact=None)
                mbartist = musicbrainzngs.get_artist_by_id(mbid, includes=['url-rels'])
                if 'url-relation-list' not in mbartist['artist']:
                    mbartist['artist']['url-relation-list'] = []
                print(mbartist)

                types = ['streaming music', 'purchase for download', 'bandcamp', 'soundcloud', 'youtube', 'free streaming']

                for url in mbartist['artist']['url-relation-list']:
                    if url['type'] in types:
                        current_url = url['target']

                        for platform in ["youtube", "spotify", "deezer", "itunes", "bandcamp", "soundcloud"]:
                            print("platform", platform, current_url)
                            cls = getattr(self, platform)
                            print(cls.do_it(current_url))
                            if cls.do_it(current_url):
                                platform_data = cls.get_drops_for_artist(mbartist, current_url)
                                self.data.extend(platform_data)

            except Exception as e:
                print(e)

        self.df = DataFrame(self.data)
        self.df.sort_values(by=['release_date', 'band', 'drop'], ascending=False, inplace=True)
        self.df.drop_duplicates(subset=["drop_url"], inplace=True)
        self.df.to_excel('output/versgedropt.xlsx')
示例#20
0
def get_artist(artistid):
    from lxml import etree

    root = etree.XML(u'<artist></artist>')

    # lookup the artist id
    result = musicbrainzngs.get_artist_by_id(artistid, includes=['url-rels'])

    if debug:
        pprint.pprint(result)

    if result:
        etree.SubElement(root, "id").text = result['artist']['id']
        etree.SubElement(root, "name").text = result['artist']['name']
        etree.SubElement(root, "sort-name").text = result['artist']['sort-name']

        if 'url-relation-list' in result['artist']:
            urls = result['artist']['url-relation-list']
            if urls:
                for (idx, url) in enumerate(urls):
                    node = etree.SubElement(root, "url")
                    node.text = url['target']
                    node.set("type", url['type'])
    else:
        etree.SubElement(root, "error").text = "MusicBrainz ID was not found"
        log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)))
        sys.exit(1)

    log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)))
    sys.exit(0)
示例#21
0
def extract_artist_data():
    print "artist,name,country,gender,genere,year"
    with gzip.open(artists_file, 'r') as art_fh:
        art_csv = csv.reader(art_fh, delimiter=',', quotechar='"')
        next(art_csv, None)
        for row in art_csv:
            c**t = ""
            gender = ""
            genere = ""
            year = ""
            try:
                artist_dict = musicbrainzngs.get_artist_by_id(str(row[0]))
                artist_info = artist_dict['artist']
                
                if artist_info.get('country') is not None:
                    c**t = artist_info['country']

                if artist_info.get('gender') is not None:
                    gender = artist_info['gender']

                if artist_info.get('disambiguation') is not None:
                    genere = artist_info['disambiguation']

                if artist_info.get('life-span') is not None:
                    if artist_info['life-span'].get('begin') is not None:
                        year = artist_info['life-span']['begin'][:4]

                print str(row[0])+","+str(row[1])+","+str(c**t)+","+str(gender)+","+str(genere)+","+str(year)

            except:
                print str(row[0])+","+str(row[1])+",,,,"
示例#22
0
def artist_wikidata_id(artist_musicbrainz_id) -> 'artist_wikidata_id':
    """Given the artist musicbrainz id, it returns the uri of its wikidata page.

    This allows us to retrieve the artist page in the 89% of the cases

    Arguments:
        artist_name {str} - -

    Returns:
        uri - - uri
    """
    artist = musicbrainzngs.get_artist_by_id(
        artist_musicbrainz_id['value'], includes=['url-rels'])['artist']

    try:
        urls = artist['url-relation-list']
    except KeyError:
        logging.getLogger('root.features').warning(
            f"No relations to external pages specified for {artist_musicbrainz_id['value']}")
        return None

    url_wikidata = [u for u in urls if u['type'] ==
                    'wikidata' and u['direction'] == 'forward']
    if len(url_wikidata) > 0:
        return {'value': f"wd:{url_wikidata[0]['target'].split('/')[-1]}"}
    else:
        logging.getLogger('root.features').warning(
            f"No wikidata page specified for artist {artist_musicbrainz_id['value']}")
        return None
示例#23
0
    def get_tags_from_album_artist(self, upc):
        """
            get artists tags fro album from music brainz
        :param upc: album upc
        :return:
        """
        album_tags = []
        if upc in self.MB_UPC_CACHE:
            return self.MB_UPC_CACHE[upc]

        response = musicbrainzngs.search_releases(
            query='barcode:{}'.format(upc))
        if response['release-count'] == 0:
            return []
        release = response['release-list'][0]
        for artist_credit in release['artist-credit']:
            if type(artist_credit) == str:
                continue
            artist_id = artist_credit['artist']['id']
            if artist_id in self.MB_ARTIST_CACHE:
                album_tags += self.MB_ARTIST_CACHE[artist_id]
            else:
                artist_info = musicbrainzngs.get_artist_by_id(
                    artist_id, includes=['tags'])['artist']
                if 'tag-list' in artist_info:
                    tags = [tag['name'] for tag in artist_info['tag-list']]
                    self.MB_ARTIST_CACHE[artist_id] = tags
                    album_tags += tags
        self.MB_UPC_CACHE[upc] = album_tags
        return album_tags
示例#24
0
def get_more_artist_info(mbid):
    out_dict = dict(area=None, life_span=None, top_tags=[])
    try:
        mb_info = musicbrainzngs.get_artist_by_id(mbid, includes=['tags'])
        mb_info = mb_info['artist']
        if 'area' in mb_info:
            out_dict['area'] = mb_info['area']['name']
        if 'life-span' in mb_info:
            life_span = mb_info['life-span']
            begin = ''
            end = ''
            if 'begin' in life_span:
                begin = life_span['begin']
            if 'end' in life_span:
                end = life_span['end']
            out_dict['life_span'] = '{} - {}'.format(begin, end)
        if 'tag-list' in mb_info:
            tag_dicts = mb_info['tag-list']
            sorted_tag_list = sorted(tag_dicts, key=lambda i: -int(i['count']))
            sorted_tag_list = [x['name'] for x in sorted_tag_list]
            out_dict['top_tags'] = sorted_tag_list[:3]
    except requests.HTTPError as err:
        print("HTTPError: {0}".format(err))
        pass
    except musicbrainzngs.ResponseError as err:
        print("ResponseError: {0}".format(err))
        pass
    return out_dict
示例#25
0
def get_artist_from_mbid(mbid: str) -> Tuple[Union[int, dict], dict]:
    try:
        mb_artist: dict = musicbrainzngs.get_artist_by_id(mbid, includes=["url-rels", "tags"])["artist"]
    except ResponseError as error:
        return error.cause.code, dict()

    dz_artist = get_artist_from_mbobj(mb_artist)
    return dz_artist, mb_artist
示例#26
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']]
示例#27
0
文件: steeb.py 项目: napcae/steeb
def get_albums(evt):
    result = m.get_artist_by_id(evt.target.get_selected_items()[0]['id'], includes=["release-groups"], release_type=["album", "ep"])
    resultList = []
    print(result)
    for idx, album in enumerate(result["artist"]["release-group-list"]):
        resultList.append([album["title"], album["id"]])

    lv = mainwin['albumslist']
    lv.items = resultList
示例#28
0
def lookup_artists(artists):
    artist_map = {}
    for a in artists:
        mba = mb.get_artist_by_id(a, includes=["tags"])["artist"]
        artist_map[a] = {
            "name": mba["name"],
            "tags": sort_tags(mba.get("tag-list", []))
        }
    return artist_map
示例#29
0
 def __init__(self, mbz_id):
     self.mbz_id = mbz_id
     musicbrainzngs.set_useragent("gigographics.mdg.io", "0.1", "http://gigographics.mdg.io")
     self.data = {
         'artist' : {
             'name' : musicbrainzngs.get_artist_by_id(self.mbz_id)['artist']['name'],
             'mbz_id' : self.mbz_id
         }
     }
def artist_relationships(
    artist_musicbrainz_id
) -> [
        'record_label_musicbrainz_id',
        'release_group_musicbrainz_id',
        'artist_musicbrainz_id',
        'place_musicbrainz_id',
        'event_musicbrainz_id',
        'recording_musicbrainz_id',
        'release_musicbrainz_id',
        'work_musicbrainz_id',
]:
    """Return every relation among an artist an another musicbrainz entity.

       We specify the type of the arrival node by distinguishing the relationship type.
       Moreover, we specify the edge_type as the id of the relationship in musicbrainz.

       Notice: URL, series, instruments relationships are discarded
    """
    relationships_found = []

    if artist_musicbrainz_id is not None:

        relationship_types = [
            'artist',
            'label',
            'place',
            'event',
            'recording',
            'release',
            'release-group',
            'work',
        ]
        artist = musicbrainzngs.get_artist_by_id(
            artist_musicbrainz_id['value'],
            includes=[f"{t}-rels" for t in relationship_types])['artist']
        for t in relationship_types:

            try:
                k = f"{t}-relation-list" if t != 'release-group' else "release_group-relation-list"
                relationships_of_type_t = artist[k]
            except KeyError:
                continue

            for relationship in relationships_of_type_t:

                if relationship['direction'] == 'forward':

                    d = {
                        'edge_type': relationship['type-id'],
                        'node_type': _node_type(t),
                        'value': relationship['target']
                    }
                    relationships_found.append(d)

    return relationships_found
def query_artist(artist_id):
    def check_for_official_album(album_release_list):
        for release_list in album_release_list:
            if release_list['status'] == 'Official':
                return True
        return False

    artist_query = musicbrainzngs.get_artist_by_id(
        artist_id, includes=['artist-rels', 'release-groups'])

    artist_list = {"artist_list": []}

    artist_object = {"meta": {}, "album_list": []}

    artist_name = artist_query["artist"]["name"]

    # Get members through artist id query
    members_of_group = []
    if artist_query['artist']['type'] == 'Group':
        for member in artist_query['artist']['artist-relation-list']:

            if member['type'] == 'member of band':
                members_of_group.append(member['artist']['name'])
    else:
        for member in artist_query['artist']['artist-relation-list']:

            if member['type'] == 'is person':
                members_of_group.append(member['artist']['name'])

    # Get albums through the release group relationship
    releases = artist_query['artist']['release-group-list']

    album_list = []
    for release in releases:

        if release['type'] == 'Album':
            album_info = musicbrainzngs.get_release_group_by_id(
                release['id'], includes=['releases'])

            album_release_list = album_info['release-group']['release-list']
            if check_for_official_album(album_release_list) == True:  # and :
                album = {
                    "name": release['title'],
                    "release_date": release['first-release-date']
                }
                artist_object["album_list"].append(album)

    meta = {"name": artist_name, "members": members_of_group}
    artist_object["meta"].update(meta)

    artist_list["artist_list"].append(artist_object)

    artists_file = '%s.json' % (artist_name)
    f = open(artists_file, 'w')
    f.write(json.dumps(artist_list, indent=4, sort_keys=False))
    f.close()
示例#32
0
def getArtistById( artist_id ):
    try:
        result = musicbrainzngs.get_artist_by_id( artist_id )
    except WebServiceError as exc:
        print("Something went wrong with the request: %s" % exc)
    else:
        if( result ):
            return ( result['artist']['name'] , result['artist']['id'] )
        else:
            return(0,0)
示例#33
0
def api_get_artist(id):
    try:
        mbz.set_useragent("Artistics", "v1.0", "*****@*****.**")
        result = mbz.get_artist_by_id(id)
    except mbz.WebServiceError as exc:
        result = {}

    if "artist" in result:
        return result["artist"]
    return None
示例#34
0
def GetAlbumsOfArtist(artist_mbid):
    artist = Artist.objects.filter(mbid=artist_mbid)
    if len(artist) != 1:
        return

    # musicbrainzngs.get_release_group_by_id(id, includes=[], release_status=[], release_type=[])
    res = musicbrainzngs.get_artist_by_id(artist_mbid, includes=['releases'])
    print res

    """
示例#35
0
def get_artist_details(artist_id):
    """
    Send request to musicbrainz api using musicbrainzngs module and save artist details
    :param artist_id: unique mbid of the artist
    :return: id, name, type and place details of the artist
    """
    global artist_requests_count

    if artist_id in artist_cache:
        artist_details = artist_cache[artist_id]
    else:
        try:
            result = musicbrainzngs.get_artist_by_id(artist_id)
        except musicbrainzngs.WebServiceError as exc:
            print("Something went wrong with the request: %s" % exc)
            return
        else:
            artist = result["artist"]

            artist_details = {"id": artist["id"],
                              "name": artist["name"],
                              "type": None,
                              "area_id": None,
                              "area_name": None,
                              "begin_area_id": None,
                              "begin_area_name": None,
                              "place_id": None,
                              "place": None}

            if "type" in artist:
                artist_details["type"] = artist["type"]

            if "area" in artist and artist["area"] is not None and "id" in artist["area"] and "name" in artist["area"]:
                artist_details["area_id"] = artist["area"]["id"]
                artist_details["area_name"] = artist["area"]["name"]
            if "begin-area" in artist and artist["begin-area"] is not None and "id" in artist[
                "begin-area"] and "name" in artist["begin-area"]:
                artist_details["begin_area_id"] = artist["begin-area"]["id"]
                artist_details["begin_area_name"] = artist["begin-area"]["name"]

            # populate place with begin-area_name if it"s not null, else area_name if it"s not null, else None
            if artist_details["begin_area_name"] is not None:
                artist_details["place"] = artist_details["begin_area_name"]
                artist_details["place_id"] = artist_details["begin_area_id"]
            elif artist_details["area_name"] is not None:
                artist_details["place"] = artist_details["area_name"]
                artist_details["place_id"] = artist_details["area_id"]

            artist_cache[artist_id] = artist_details

    artist_requests_count += 1
    if artist_requests_count % cache_save_frequency == 0:
        request_utils.save_cache_to_disk(artist_cache, artist_cache_path)
        print("saved cache")
    return artist_details
示例#36
0
 def get_mb_artist_by_id(self, mb_id):
     try:
         return m.get_artist_by_id(mb_id, [])
     except WebServiceError as exc:
         log.error("requesting data from MusicBrainz: %s (WebServiceError)" % exc)
         log.debug("MODELS: get_mb_artist_by_id returns False.")
         return False
     except Exception as exc:
         log.error("requesting data from MusicBrainz: %s (Exception)" % exc)
         log.debug("MODELS: get_mb_artist_by_id returns empty dict.")
         return {}
    def make_query(self, params):

        if params["type"] == "artist":
            return musicbrainzngs.get_artist_by_id(params["mbid"])
        elif params["type"] == "album":
            return musicbrainzngs.get_release_by_id(params["mbid"])
        elif params["type"] == "tracklist":
            return musicbrainzngs.get_release_by_id(params["mbid"],
                                                    includes=["recordings"])["release"]["medium-list"][0]["track-list"]
        elif params["type"] == "track":
            return musicbrainzngs.get_recording_by_id(params["mbid"], includes=["artists"])
def get_members(music_brains_artist):
    relationships = music_brains_artist.get('artist-relation-list', [])
    member_ids = [
        relation['target'] for relation in relationships
        if relation['type'] == 'member of band'
    ]
    members = {}
    for member_id in member_ids:
        if member_id not in members:
            members[member_id] = musicbrainzngs.get_artist_by_id(
                member_id)['artist']
    return members.values()
示例#39
0
def download_group_connection(group_id, mb_id):
    '''
    Downloads and connects the members of a specific group
    '''
    links = try_mb_request(lambda: mb.get_artist_by_id(mb_id, "artist-rels"))
    per_artist = links['artist']
    relation_list = per_artist['artist-relation-list']
    for relation in relation_list:
        if relation['type'] != 'member of band':
            continue
        member_mb_id = relation['artist']['id']
        add_connection(group_id, mb_id, member_mb_id)
示例#40
0
def getDictionaryOfArtistsDetails(artists):
    artistsInfo = []
    for artist in artists:
        artist_id = artist['id']
        try:
            result = musicbrainzngs.get_artist_by_id(artist_id,
                                                     includes=["url-rels"])
        except musicbrainzngs.WebServiceError as exc:
            print("Something went wrong with the request: %s" % exc)
        else:
            artist = result["artist"]
            artistsInfo += artist
            print(artist)
示例#41
0
文件: musicbrainz.py 项目: 6/GeoDJ
 def get_artist(self, musicbrainz_id, includes=[]):
     if musicbrainz_id is None or musicbrainz_id.strip() == "":
         return None
     try:
         result = musicbrainzngs.get_artist_by_id(musicbrainz_id, includes=includes)
     except musicbrainzngs.WebServiceError as exc:
         print "Something went wrong with the request: %s" % exc
         return None
     except musicbrainzngs.MusicBrainzError as exc:
         print "Something went wrong with MusicBrainz: %s" % exc
         return None
     else:
         return result
示例#42
0
def get_artist(artist_mbid):
    result = None
    try:
        result = mbz.get_artist_by_id(artist_mbid)
    except mbz.ResponseError as err:
        status = err.cause.code
    else:
        status = 404
        if result['artist']['id'] not in blacklisted_artists:
            status = 200
            result = result["artist"]

    return {'status': status, 'artist': result}
示例#43
0
文件: models.py 项目: swist/ripple
	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')
示例#44
0
def get_artist(artist_id):
    try:
        artist = mbz.get_artist_by_id(artist_id)['artist']
    except musicbrainzngs.musicbrainz.ResponseError:
        raise ValueError('invalid artist_id: {artist_id}')

    assert artist_id == artist[
        'id'], f"id mismatch: {artist_id}, {artist['id']}"

    return {
        'id': artist_id,
        'name': artist['name'],
        'area': artist.get('area', {}).get('name')
    }
示例#45
0
def status_view(request):
    bar = 25
    output = ''
    hostname = '192.168.54.101:5000'
    musicbrainzngs.set_hostname(hostname)
    musicbrainzngs.auth("user", "password")
    musicbrainzngs.set_useragent(
        'c3sbrainz',
        '0.1a',
        '*****@*****.**'
        )
    artistid = "952a4205-023d-4235-897c-6fdb6f58dfaa"
    #import pdb
    #pdb.set_trace()
    print(dir(musicbrainzngs))
    #output = dir(musicbrainzngs)
    output = musicbrainzngs.get_artist_by_id(artistid)
    print  musicbrainzngs.get_artist_by_id(artistid)
    return {
        'foo': 'foo',
        'bar': bar,
        'hostname': hostname,
        'output': output
        }
示例#46
0
    def getAlbumID(self, known_data):

        '''
        Match the given 'artist_id' entry to their 'releases'
        Returns Release-Group MB-ID
        '''

        # Blocking call to MBrainz
        result = musicbrainzngs.get_artist_by_id(
            known_data['artist_id'],
            includes=[
                'release-groups',
            ],
            release_type=[
                'album'
            ]
        )

        current_best_ratio = 0

        for release_grp in result['artist']['release-group-list']:

            ratio = fuzz.ratio(
                known_data['album'].lower(),
                release_grp['title'].lower()
            )

            self.Logger.msg('Ratio-> {}'.format(ratio))

            if current_best_ratio < ratio:

                current_best_ratio = ratio
                current_best_match = release_grp['id']

                if current_best_ratio == 100:
                    break

                self.Logger.msg('Better Ratio Found')
                continue

            self.Logger.msg('Better Ratio in Storage')

        self.Logger.msg('Returning Current Best Match-> {}'.format(
            current_best_match)
        )

        return current_best_match
示例#47
0
    def _parse_releases(releases):
        _release = None
        _results = []

        for release in releases:
            if MusicEntityGenerator._validate_score(_release, release):
                if _release is None:
                    _release = release

                # Find all valid releases (Official releases)
                if MusicEntityGenerator._valid_release(release):
                    _results.append((release, release['label-info-list']))

        _artist = musicbrainzngs.get_artist_by_id(
            _release['artist-credit'][0]['artist']['id']
        )['artist']
        return _artist, _results
示例#48
0
def complete_info(mbs_artist):
	artists = {}
	# If artist is group run group_members
	print('{} is the artist obj'.format(mbs_artist))
	if mbs_artist['type'] != 'Person':
		members = group_members(mbs_artist['id'])

		for member in members:
			# Lookup artist by id and get gender
			midx   = members[member].rfind('/')
			sleep(1) # Rate limit one per second
			person = mbs.get_artist_by_id(members[member][midx + 1:])
			artists[member] = person['artist']['gender']
	else:
		print('Extracting gender of {}'.format(mbs_artist))
		artists[mbs_artist['name']] = mbs_artist['gender']

	return artists
示例#49
0
def get_artist_by_id(id):
    """Get artist with the MusicBrainz ID.

    Returns:
        Artist object with the following includes: url-rels, artist-rels.
    """
    key = cache.gen_key(id)
    artist = cache.get(key)
    if not artist:
        try:
            artist = musicbrainzngs.get_artist_by_id(id, ['url-rels', 'artist-rels']).get('artist')
        except ResponseError as e:
            if e.cause.code == 404:
                return None
            else:
                raise InternalServerError(e.cause.msg)
        artist = artist_rel.process(artist)
        cache.set(key=key, val=artist, time=DEFAULT_CACHE_EXPIRATION)
    return artist
示例#50
0
def add_artist_to_db(artist_id, session):
    # type: (six.stringtypes, Any) -> None
    """
    Adds an artist to the db, including all album and tracks information
    :param artist_id: musicbrainzid
    :type artist_id: str
    :param session: valid SQLAlchemy Session
    :return: None
    """
    logger.info('adding artist {} to db'.format(artist_id))
    with musicbrainz_lock:
        artist_info = musicbrainzngs.get_artist_by_id(artist_id)['artist']

    artist = Artist(name=artist_info['name'],
                    musicbrainz_id=artist_id,
                    status=Status.Wanted)
    session.add(artist)

    release_groups = get_release_groups_for_artist(artist.musicbrainz_id)

    for group_info in release_groups:
        logger.debug('found {type} {name}'.format(type=group_info['type'], name=ensure_unicode(group_info['title'])))
        album = Album(title=ensure_unicode(group_info['title']),
                      musicbrainz_id=group_info['id'],
                      type=group_info['type'],
                      artist=artist,
                      status=Status.Wanted
                      )

        session.add(album)

        releases = get_releases_for_release_group(album.musicbrainz_id)
        for release_info in releases:
            add_album_and_tracks_to_db(album, release_info, session)

        # Chose oldest release (it's usually the original release)
        chosen_release = session.query(Release).join(Album).filter(Album.musicbrainz_id == group_info['id']).order_by(
            Release.release_date.asc()).first()
        if chosen_release:
            chosen_release.is_selected = True

    with write_lock:
        session.commit()
示例#51
0
 def get_artist_by_id(self, id, includes=[]):
     """Get artist with the MusicBrainz ID.
     Available includes: recordings, releases, release-groups, works, various-artists, discids, media, isrcs,
     aliases, annotation, tags, user-tags, ratings, user-ratings, area-rels, artist-rels, label-rels, place-rels,
     recording-rels, release-rels, release-group-rels, url-rels, work-rels.
     """
     key = generate_cache_key(id, type='artist', source='api', params=includes)
     artist = cache.get(key)
     if not artist:
         try:
             artist = get_artist_by_id(id, includes).get('artist')
         except ResponseError as e:
             if e.cause.code == 404:
                 raise APIError(code=e.cause.code,
                                desc="Sorry, we could not find an artist with that MusicBrainz ID.")
             else:
                 raise APIError(code=e.cause.code, desc=e.cause.msg)
         artist = artist_rel.process(artist)
         cache.set(key, artist, DEFAULT_CACHE_EXPIRATION)
     return artist
def get_artist_by_id(artist_id):
    global artist_cache, artist_requests_count

    # check if I already saved the artist
    if artist_id in artist_cache:
        artist_details = artist_cache[artist_id]

    else:
        try:
            result = musicbrainzngs.get_artist_by_id(artist_id)
        except musicbrainzngs.WebServiceError as exc:
            print("Something went wrong with the request: %s" % exc)
            return
        else:
            artist_details = extract_artist_details(result)
            artist_cache[artist_id] = artist_details

            artist_requests_count += 1
            if artist_requests_count % cache_save_frequency == 0:
                save_cache_to_disk(artist_cache, artist_cache_path)

    return artist_details
示例#53
0
def postprocess_deep(store, tags):
    artists = dict([(item[-38:-2], item) for item in 
                        store.subjects(RDF.type, MS['Artist'])])
    albums = dict([(item[-38:-2], item) for item in 
                        store.subjects(RDF.type, MS['Album'])])

    for mbid, uri in artists.iteritems():
        try:
            print('API: artist %s' % mbid, file=sys.stderr)
            artist_data = mb.get_artist_by_id(mbid)
            name = artist_data['artist']['name']
            sortname = artist_data['artist']['sort-name']
            store.add((uri, MS['name'], Literal(name)))
            store.add((uri, MS['sortname'], Literal(sortname)))
            if 'country' in artist_data['artist'].keys():
                country = artist_data['artist']['country']
                store.add((uri, MS['country'], Literal(country)))
            if 'type' in artist_data['artist'].keys():
                a_type = artist_data['artist']['type']
                store.add((uri, MS['type'], Literal(a_type)))
        except:
            continue

    for mbid, uri in albums.iteritems():
        try:
            print('API: album %s' % mbid, file=sys.stderr)
            album_data = mb.get_release_by_id(mbid, ['labels'])
            for label_data in album_data['release'].get('label-info-list', []):
                label = URIRef('http://musicbrainz.org/label/%s#_' % 
                               label_data['label']['id']) 
                store.add((uri, MS['label'], label))
                if label not in store.subjects(RDF.type, MS['Label']):
                    print('    label %s' % 
                             label_data['label']['id'], file=sys.stderr)
                    add_label(store, label, label_data)
        except:
            continue
示例#54
0
    def fetch_extra_trackinfo(self, username, info):
        """Updates info with extra trackinfo from the last.fm API and
        MusicBrainz API"""
        try:
            self.log.debug("Asking via track")
            api_result = self.app.track.get_info(track=info['title'],
                                                 artist=info['artist'],
                                                 username=username)
        except lastfm.exceptions.InvalidParameters:
            self.log.warning("Last.fm returned InvalidParameters "
                             "for trackinfo")
            return
        except Exception:
            self.log.exception("Got a random for trackinfo")
            return

        if 'userplaycount' in api_result:
            info['playcount'] = int(api_result['userplaycount'])

        # getting tags from musicbrainz(if they have id)
        if 'art_mbid' in info and info['art_mbid'] != '':
            mb = musicbrainzngs.get_artist_by_id(
                info['art_mbid'], includes='tags')

            if 'tag-list' in mb['artist']:
                sorted_tags = sorted(
                    mb['artist']['tag-list'], key=itemgetter('count'),
                    reverse=True)

                tags = []
                for tag in sorted_tags:
                    tags.append(tag['name'])
                info['tags'] = tags

        if 'userloved' in api_result and not info['loved']:
            info['loved'] = bool(int(api_result['userloved']))
示例#55
0
for query in queries:
    # search artist
    try:
        resp = json.loads(api.artistSearch(query))
        #print resp
        filtresp = {key:resp[key] for key in resp.keys() if (resp[key]['music_brainz_id'] is not None) }
        print filtresp
        
        for key in filtresp.keys():
            nbs_id = key
            mbz_id = filtresp[key]['music_brainz_id']
            nbs_name = filtresp[key]['name']

            try:
                result = musicbrainzngs.get_artist_by_id(mbz_id)
            except WebServiceError as exc:
                print("Something went wrong with the request: %s" % exc)
            else:
                mbz_name = ''; mbz_name=''; country='';begin_area=''
                life_span_begin='';mbz_type='';isni_list=''
                try: 
                    mbz_name = result['artist']['name']
                except:
                    pass
                try:
                    area = result['artist']['area']['name']
                except:
                    pass
                try:
                    country = result['artist']['country']
示例#56
0
def getArtist(artistid, extrasonly=False):

    with mb_lock:
        artist_dict = {}

        artist = None

        try:
            limit = 200
            artist = musicbrainzngs.get_artist_by_id(artistid)['artist']
            newRgs = None
            artist['release-group-list'] = []
            while newRgs == None or len(newRgs) >= limit:
                newRgs = musicbrainzngs.browse_release_groups(artistid,release_type="album",offset=len(artist['release-group-list']),limit=limit)['release-group-list']
                artist['release-group-list'] += newRgs
        except musicbrainzngs.WebServiceError as e:
            logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e)))
            time.sleep(5)
        except Exception,e:
            pass

        if not artist:
            return False

        #if 'disambiguation' in artist:
        #    uniquename = unicode(artist['sort-name'] + " (" + artist['disambiguation'] + ")")
        #else:
        #    uniquename = unicode(artist['sort-name'])

        artist_dict['artist_name'] = unicode(artist['name'])

        # Not using the following values anywhere yet so we don't need to grab them.
        # Was causing an exception to be raised if they didn't exist.
        #
        #artist_dict['artist_sortname'] = unicode(artist['sort-name'])
        #artist_dict['artist_uniquename'] = uniquename
        #artist_dict['artist_type'] = unicode(artist['type'])

        #artist_dict['artist_begindate'] = None
        #artist_dict['artist_enddate'] = None
        #if 'life-span' in artist:
        #    if 'begin' in artist['life-span']:
        #        artist_dict['artist_begindate'] = unicode(artist['life-span']['begin'])
        #    if 'end' in artist['life-span']:
        #        artist_dict['artist_enddate'] = unicode(artist['life-span']['end'])


        releasegroups = []

        if not extrasonly:
            for rg in artist['release-group-list']:
                if "secondary-type-list" in rg.keys(): #only add releases without a secondary type
                    continue
                releasegroups.append({
                            'title':      unicode(rg['title']),
                            'id':         unicode(rg['id']),
                            'url':        u"http://musicbrainz.org/release-group/" + rg['id'],
                            'type':       unicode(rg['type'])
                    })

        # See if we need to grab extras. Artist specific extras take precedence over global option
        # Global options are set when adding a new artist
        myDB = db.DBConnection()

        try:
            db_artist = myDB.action('SELECT IncludeExtras, Extras from artists WHERE ArtistID=?', [artistid]).fetchone()
            includeExtras = db_artist['IncludeExtras']
        except IndexError:
            includeExtras = False

        if includeExtras:

            # Need to convert extras string from something like '2,5.6' to ['ep','live','remix'] (append new extras to end)
            if db_artist['Extras']:
                extras = map(int, db_artist['Extras'].split(','))
            else:
                extras = []
            extras_list = ["single", "ep", "compilation", "soundtrack", "live", "remix", "spokenword", "audiobook", "other", "dj-mix", "mixtape/street", "broadcast", "interview", "demo"]

            includes = []

            i = 1
            for extra in extras_list:
                if i in extras:
                    includes.append(extra)
                i += 1

            for include in includes:

                mb_extras_list = []

                try:
                    limit = 200
                    newRgs = None
                    while newRgs == None or len(newRgs) >= limit:
                        newRgs = musicbrainzngs.browse_release_groups(artistid,release_type=include,offset=len(mb_extras_list),limit=limit)['release-group-list']
                        mb_extras_list += newRgs
                except musicbrainzngs.WebServiceError as e:
                    logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e)))
                    time.sleep(5)

                for rg in mb_extras_list:

                    rg_type = rg['type']
                    if rg_type == 'Album' and 'secondary-type-list' in rg:
                        secondary_type = rg['secondary-type-list'][0]
                        if secondary_type != rg_type:
                            rg_type = secondary_type

                    releasegroups.append({
                            'title':        unicode(rg['title']),
                            'id':           unicode(rg['id']),
                            'url':          u"http://musicbrainz.org/release-group/" + rg['id'],
                            'type':         unicode(rg_type)
                        })

        artist_dict['releasegroups'] = releasegroups

        return artist_dict
示例#57
0
文件: mb.py 项目: chiviak/headphones
def getArtist(artistid, extrasonly=False):
    artist_dict = {}
    artist = None
    try:
        limit = 100
        with mb_lock:
            artist = musicbrainzngs.get_artist_by_id(artistid)['artist']
        newRgs = None
        artist['release-group-list'] = []
        while newRgs is None or len(newRgs) >= limit:
            with mb_lock:
                newRgs = musicbrainzngs.browse_release_groups(
                    artistid,
                    release_type="album",
                    offset=len(artist['release-group-list']),
                    limit=limit)
            newRgs = newRgs['release-group-list']
            artist['release-group-list'] += newRgs
    except musicbrainzngs.WebServiceError as e:
        logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e)))
        mb_lock.snooze(5)
    except Exception as e:
        pass

    if not artist:
        return False

    artist_dict['artist_name'] = unicode(artist['name'])

    releasegroups = []

    if not extrasonly:
        for rg in artist['release-group-list']:
            if "secondary-type-list" in rg.keys(): #only add releases without a secondary type
                continue
            releasegroups.append({
                'title': unicode(rg['title']),
                'id': unicode(rg['id']),
                'url': u"http://musicbrainz.org/release-group/" + rg['id'],
                'type': unicode(rg['type'])
            })

    # See if we need to grab extras. Artist specific extras take precedence over global option
    # Global options are set when adding a new artist
    myDB = db.DBConnection()

    try:
        db_artist = myDB.action('SELECT IncludeExtras, Extras from artists WHERE ArtistID=?', [artistid]).fetchone()
        includeExtras = db_artist['IncludeExtras']
    except IndexError:
        includeExtras = False

    if includeExtras:

        # Need to convert extras string from something like '2,5.6' to ['ep','live','remix'] (append new extras to end)
        if db_artist['Extras']:
            extras = map(int, db_artist['Extras'].split(','))
        else:
            extras = []
        extras_list = headphones.POSSIBLE_EXTRAS

        includes = []

        i = 1
        for extra in extras_list:
            if i in extras:
                includes.append(extra)
            i += 1

        for include in includes:

            mb_extras_list = []

            try:
                limit = 100
                newRgs = None
                while newRgs is None or len(newRgs) >= limit:
                    with mb_lock:
                        newRgs = musicbrainzngs.browse_release_groups(
                            artistid, release_type=include, offset=len(mb_extras_list), limit=limit)
                    newRgs = newRgs['release-group-list']
                    mb_extras_list += newRgs
            except musicbrainzngs.WebServiceError as e:
                logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s (%s)' % (artistid, str(e)))
                mb_lock.snooze(5)

            for rg in mb_extras_list:
                rg_type = rg['type']
                if rg_type == 'Album' and 'secondary-type-list' in rg:
                    secondary_type = rg['secondary-type-list'][0]
                    if secondary_type != rg_type:
                        rg_type = secondary_type

                releasegroups.append({
                    'title': unicode(rg['title']),
                    'id': unicode(rg['id']),
                    'url': u"http://musicbrainz.org/release-group/" + rg['id'],
                    'type': unicode(rg_type)
                })
    artist_dict['releasegroups'] = releasegroups
    return artist_dict
示例#58
0
    def get_artist_info(mbid):
        result = musicbrainzngs.get_artist_by_id(mbid, ['url-rels', 'tags'])
        releases = musicbrainzngs.browse_releases(artist=mbid, limit=100)

        result['artist']['release-list'] = releases['release-list']
        return result
示例#59
0
 def get_artist(mbid):
     artist = musicbrainzngs.get_artist_by_id(mbid, ['releases'])
     return artist