Beispiel #1
0
def get_multiple_entities(entities):
    """Fetch multiple entities using their MBIDs.

    Args:
        entites: List of tuples containing the entity ID and the entity type.

    Returns:
        Dictionary containing the basic information related to the entities.
        {
            "id": uuid,
            "name/title": str,
        }
        Information related to the artists of release groups and the
        coordinates of the places is also included.
    """
    entities_info = {}
    release_group_mbids = [
        entity[0] for entity in filter(
            lambda entity: entity[1] == 'release_group', entities)
    ]
    artist_mbids = [
        entity[0]
        for entity in filter(lambda entity: entity[1] == 'artist', entities)
    ]
    label_mbids = [
        entity[0]
        for entity in filter(lambda entity: entity[1] == 'label', entities)
    ]
    place_mbids = [
        entity[0]
        for entity in filter(lambda entity: entity[1] == 'place', entities)
    ]
    event_mbids = [
        entity[0]
        for entity in filter(lambda entity: entity[1] == 'event', entities)
    ]
    work_mbids = [
        entity[0]
        for entity in filter(lambda entity: entity[1] == 'work', entities)
    ]
    entities_info.update(
        fetch_multiple_release_groups(
            release_group_mbids,
            includes=['artists'],
            unknown_entities_for_missing=True,
        ))
    entities_info.update(fetch_multiple_artists(artist_mbids, ))
    entities_info.update(fetch_multiple_labels(label_mbids, ))
    entities_info.update(
        fetch_multiple_places(
            place_mbids,
            unknown_entities_for_missing=True,
        ))
    entities_info.update(
        fetch_multiple_events(
            event_mbids,
            unknown_entities_for_missing=True,
        ))
    entities_info.update(fetch_multiple_works(work_mbids, ))
    return entities_info
 def test_fetch_multiple_artists_redirect(self, engine):
     """Artist with a redirect uses redirected mbid in dictionary key, but canonical id in returned data"""
     artists = mb_artist.fetch_multiple_artists(["fe008f22-07be-46f0-9206-7cab2d26e89d"])
     assert len(artists) == 1
     assert artists["fe008f22-07be-46f0-9206-7cab2d26e89d"] == {
         "mbid": "f59c5520-5f46-4d2c-b2c4-822eabf53419",
         "name": "Linkin Park",
         "sort_name": "Linkin Park",
         "comment": "American rock band",
         "life-span": {"begin": "1999"},
         "rating": 85,
         "type": "Group"
     }
Beispiel #3
0
 def test_fetch_multiple_artists_empty(self):
     self.artist_query.return_value = []
     artists = mb_artist.fetch_multiple_artists(
         [
             "f59c5520-5f46-4d2c-b2c4-822eabf53419",
             "f82bcf78-5b69-4622-a5ef-73800768d9ac",
         ],
         includes=['artist-rels', 'url-rels'],
         unknown_entities_for_missing=True)
     self.assertEqual(
         artists["f82bcf78-5b69-4622-a5ef-73800768d9ac"]["name"],
         unknown_artist.name)
     self.assertEqual(
         artists["f59c5520-5f46-4d2c-b2c4-822eabf53419"]["name"],
         unknown_artist.name)
Beispiel #4
0
def get_artist_by_id(mbid):
    """Get artist with MusicBrainz ID.

    Args:
        mbid (uuid): MBID(gid) of the artist.
    Returns:
        Dictionary containing the artist information
    """
    key = cache.gen_key(mbid)
    artist = cache.get(key)
    if not artist:
        artist = fetch_multiple_artists(
            [mbid],
            includes=['artist-rels', 'url-rels'],
        ).get(mbid)
        cache.set(key=key, val=artist, time=DEFAULT_CACHE_EXPIRATION)
    return artist_rel.process(artist)
 def test_fetch_multiple_artists(self):
     self.artist_query.return_value = [artist_jay_z, artist_linkin_park]
     artists = mb_artist.fetch_multiple_artists([
         "f59c5520-5f46-4d2c-b2c4-822eabf53419",
         "f82bcf78-5b69-4622-a5ef-73800768d9ac",
     ])
     self.assertDictEqual(artists["f82bcf78-5b69-4622-a5ef-73800768d9ac"], {
         "id": "f82bcf78-5b69-4622-a5ef-73800768d9ac",
         "name": "JAY Z",
         "sort_name": "JAY Z",
         "type": "Person",
     })
     self.assertDictEqual(artists["f59c5520-5f46-4d2c-b2c4-822eabf53419"], {
         "id": "f59c5520-5f46-4d2c-b2c4-822eabf53419",
         "name": "Linkin Park",
         "sort_name": "Linkin Park",
         "type": "Group",
     })
 def test_fetch_multiple_artists(self, engine):
     artists = mb_artist.fetch_multiple_artists([
         "f59c5520-5f46-4d2c-b2c4-822eabf53419",
         "f82bcf78-5b69-4622-a5ef-73800768d9ac",
     ])
     assert artists["f82bcf78-5b69-4622-a5ef-73800768d9ac"] == {
         "mbid": "f82bcf78-5b69-4622-a5ef-73800768d9ac",
         "name": "JAY‐Z",
         "sort_name": "JAY‐Z",
         "type": "Person",
         "comment": "US rapper",
         "life-span": {"begin": "1969-12-04"},
         "rating": 71,
     }
     assert artists["f59c5520-5f46-4d2c-b2c4-822eabf53419"] == {
         "mbid": "f59c5520-5f46-4d2c-b2c4-822eabf53419",
         "name": "Linkin Park",
         "sort_name": "Linkin Park",
         "type": "Group",
         "comment": "American rock band",
         "life-span": {"begin": "1999"},
         "rating": 85,
     }
 def test_fetch_multiple_artists_missing(self, engine):
     """If an artist id doesn't exist, don't fetch it"""
     artists = mb_artist.fetch_multiple_artists(["f59c5520-5f46-4d2c-b2c4-822eabf53419",
                                                 "f59c5520-aaaa-aaaa-b2c4-822eabf53419"],
                                                includes=['artist-rels', 'url-rels'])
     assert list(artists.keys()) == ["f59c5520-5f46-4d2c-b2c4-822eabf53419"]