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_labels(self, engine):
     labels = mb_label.fetch_multiple_labels([
         'c595c289-47ce-4fba-b999-b87503e8cb71',
         '4cccc72a-0bd0-433a-905e-dad87871397d'
     ])
     assert len(labels) == 2
     assert labels["c595c289-47ce-4fba-b999-b87503e8cb71"] == {
         "mbid": "c595c289-47ce-4fba-b999-b87503e8cb71",
         "name": "Warner Bros. Records",
         "comment":
         '1958–2019; “WB” logo, with or without “records” beneath or on banner across',
         "type": "Imprint",
         "area": "United States",
         "life-span": {
             "begin": "1958-03-19",
             "end": "2019-05-28"
         },
     }
     assert labels["4cccc72a-0bd0-433a-905e-dad87871397d"] == {
         "mbid": "4cccc72a-0bd0-433a-905e-dad87871397d",
         "name": "Roc‐A‐Fella Records",
         "type": "Original Production",
         "area": "United States",
         "life-span": {
             "begin": "1996",
             "end": "2013"
         },
         "rating": 100
     }
 def test_fetch_multiple_labels_missing(self, engine):
     labels = mb_label.fetch_multiple_labels(
         [
             '50c384a2-0b44-401b-b893-8181173339c7',
             '50c384a2-0000-0000-0000-8181173339c7'
         ],
         includes=['artist-rels', 'url-rels'])
     assert list(labels.keys()) == ['50c384a2-0b44-401b-b893-8181173339c7']
 def test_fetch_multiple_labels_redirect(self, engine):
     labels = mb_label.fetch_multiple_labels(
         ['67cf4cad-c039-4f01-bc84-f8dab7791ed7'])
     assert len(labels) == 1
     assert labels["67cf4cad-c039-4f01-bc84-f8dab7791ed7"] == {
         "mbid": "50c384a2-0b44-401b-b893-8181173339c7",
         "name": "Atlantic",
         "type": "Imprint",
         "area": "United States",
         "comment": "Warner Music imprint",
         "life-span": {
             "begin": "1947"
         },
         "rating": 100,
     }
Beispiel #5
0
def get_label_by_id(mbid):
    """Get label with MusicBrainz ID.

    Args:
        mbid (uuid): MBID(gid) of the label.
    Returns:
        Dictionary containing the label information
    """
    key = cache.gen_key(mbid)
    label = cache.get(key)
    if not label:
        label = fetch_multiple_labels(
            [mbid],
            includes=['artist-rels', 'url-rels'],
        ).get(mbid)
        cache.set(key=key, val=label, time=DEFAULT_CACHE_EXPIRATION)
    return label_rel.process(label)
Beispiel #6
0
 def test_fetch_multiple_labels(self):
     self.label_query.return_value = [label_dreamville, label_roc_a_fella]
     labels = mb_label.fetch_multiple_labels([
         '1aed8c3b-8e1e-46f8-b558-06357ff5f298',
         '4cccc72a-0bd0-433a-905e-dad87871397d'
     ])
     self.assertDictEqual(
         labels["1aed8c3b-8e1e-46f8-b558-06357ff5f298"], {
             "id": "1aed8c3b-8e1e-46f8-b558-06357ff5f298",
             "name": "Dreamville",
             "type": "Imprint",
             "area": "United States",
         })
     self.assertDictEqual(
         labels["4cccc72a-0bd0-433a-905e-dad87871397d"], {
             "id": "4cccc72a-0bd0-433a-905e-dad87871397d",
             "name": "Roc-A-Fella Records",
             "type": "Original Production",
             "area": "United States",
         })