示例#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
示例#2
0
 def test_fetch_multiple_events(self):
     self.event_query.return_value = [taubertal_festival_2004, event_ra_hall_uk]
     events = mb_event.fetch_multiple_events(
         ['ebe6ce0f-22c0-4fe7-bfd4-7a0397c9fe94', '40e6153d-a042-4c95-a0a9-b0a47e3825ce'],
     )
     self.assertEqual(events['ebe6ce0f-22c0-4fe7-bfd4-7a0397c9fe94']['name'],
                      'Taubertal-Festival 2004, Day 1')
     self.assertEqual(events['40e6153d-a042-4c95-a0a9-b0a47e3825ce']['name'],
                      '1996-04-17: Royal Albert Hall, London, England, UK')
示例#3
0
 def test_fetch_multiple_events(self, engine):
     events = mb_event.fetch_multiple_events([
         'd4921d43-bf92-464e-aef4-bba8540fc5bd',
         'b335b093-b3a0-411f-9f3d-7f680a4992d6'
     ], )
     assert events['d4921d43-bf92-464e-aef4-bba8540fc5bd'][
         'name'] == 'Butterfly Whirl 2015'
     assert events['b335b093-b3a0-411f-9f3d-7f680a4992d6'][
         'name'] == 'KISS in Atlanta'
示例#4
0
 def test_fetch_multiple_events_empty(self, engine):
     """If an event id doesn't exist, don't return it in the list"""
     events = mb_event.fetch_multiple_events([
         'd4921d43-bf92-464e-aef4-bba8540fc5bd',
         '40e6153d-4444-4444-4444-b0a47e3825ce'
     ],
                                             includes=[
                                                 'artist-rels',
                                                 'place-rels',
                                                 'series-rels', 'url-rels',
                                                 'release-group-rels'
                                             ])
     assert list(events.keys()) == ['d4921d43-bf92-464e-aef4-bba8540fc5bd']
示例#5
0
 def test_fetch_multiple_events_redirect(self, engine):
     """"""
     events = mb_event.fetch_multiple_events(
         ['b8528315-ef77-46e2-bff9-d1b00d84dc3f'], )
     assert events == {
         'b8528315-ef77-46e2-bff9-d1b00d84dc3f': {
             'mbid': '499559c8-b84b-422e-8ad7-b746d48c21aa',
             'name':
             '1995-10-11: Riverport Amphitheatre, Maryland Heights, Missouri',
             'life-span': {
                 'begin': '1995-10-11',
                 'end': '1995-10-11'
             },
             'rating': 100,
             'type': 'Concert',
         }
     }
示例#6
0
 def test_fetch_multiple_events_empty(self):
     self.event_query.return_value = []
     events = mb_event.fetch_multiple_events(
         [
             'ebe6ce0f-22c0-4fe7-bfd4-7a0397c9fe94',
             '40e6153d-a042-4c95-a0a9-b0a47e3825ce'
         ],
         includes=[
             'artist-rels', 'place-rels', 'series-rels', 'url-rels',
             'release-group-rels'
         ],
         unknown_entities_for_missing=True)
     self.assertEqual(
         events['ebe6ce0f-22c0-4fe7-bfd4-7a0397c9fe94']['name'],
         unknown_event.name)
     self.assertEqual(
         events['40e6153d-a042-4c95-a0a9-b0a47e3825ce']['name'],
         unknown_event.name)
示例#7
0
def get_event_by_id(mbid):
    """Get event with the MusicBrainz ID.

    Args:
        mbid (uuid): MBID(gid) of the event.
    Returns:
        Dictionary containing the event information.
    """
    key = cache.gen_key('event', mbid)
    event = cache.get(key)
    if not event:
        event = db.fetch_multiple_events(
            [mbid],
            includes=[
                'artist-rels', 'place-rels', 'series-rels', 'url-rels',
                'release-group-rels'
            ],
        ).get(mbid)
        cache.set(key=key, val=event, time=DEFAULT_CACHE_EXPIRATION)
    return event