Esempio n. 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
Esempio n. 2
0
 def test_fetch_multiple_works_redirect(self, engine):
     works = mb_work.fetch_multiple_works([
         '4531bed5-073c-37a8-9500-70de8583c0a1',
     ])
     assert works == {
         '4531bed5-073c-37a8-9500-70de8583c0a1': {
             "mbid": "36e33f94-ef5f-36b5-97b0-c1ed9c5a542f",
             "name": "Jesus Walks",
             "type": "Song",
         }
     }
 def test_fetch_multiple_works_empty(self):
     self.work_query.return_value = []
     works = mb_work.fetch_multiple_works(
         [
             '54ce5e07-2aca-4578-83d8-5a41a7b2f434',
             '757504fb-a130-4b84-9eb5-1b37164f12dd'
         ],
         includes=['artist-rels', 'recording-rels'],
         unknown_entities_for_missing=True)
     self.assertEqual(works["54ce5e07-2aca-4578-83d8-5a41a7b2f434"]["name"],
                      unknown_work.name)
     self.assertEqual(works["757504fb-a130-4b84-9eb5-1b37164f12dd"]["name"],
                      unknown_work.name)
Esempio n. 4
0
 def test_fetch_multiple_works(self, engine):
     works = mb_work.fetch_multiple_works([
         'd35f8fb8-52ab-4a12-b1c8-f2054d10cf88',
         '1deb7377-f980-4adb-8f0f-a36355461f38'
     ])
     assert works["d35f8fb8-52ab-4a12-b1c8-f2054d10cf88"] == {
         "mbid": "d35f8fb8-52ab-4a12-b1c8-f2054d10cf88",
         "name": "Apple Bush",
         "type": "Song",
     }
     assert works["1deb7377-f980-4adb-8f0f-a36355461f38"] == {
         "mbid": "1deb7377-f980-4adb-8f0f-a36355461f38",
         "name": "Fields of Regret",
         "type": "Song",
     }
Esempio n. 5
0
def get_work_by_id(mbid):
    """Get work with MusicBrainz ID.

    Args:
        mbid (uuid): MBID(gid) of the work.
    Returns:
        Dictionary containing the work information
    """
    key = cache.gen_key('work', mbid)
    work = cache.get(key)
    if not work:
        work = db.fetch_multiple_works(
            [mbid],
            includes=['artist-rels', 'recording-rels'],
        ).get(mbid)
        cache.set(key=key, val=work, time=DEFAULT_CACHE_EXPIRATION)
    return work
Esempio n. 6
0
 def test_fetch_multiple_works(self):
     self.work_query.return_value = [work_a_lot, work_aquemini]
     works = mb_work.fetch_multiple_works([
         '54ce5e07-2aca-4578-83d8-5a41a7b2f434',
         '757504fb-a130-4b84-9eb5-1b37164f12dd'
     ])
     self.assertDictEqual(
         works["54ce5e07-2aca-4578-83d8-5a41a7b2f434"], {
             "id": "54ce5e07-2aca-4578-83d8-5a41a7b2f434",
             "name": "a lot",
             "type": "Song",
         })
     self.assertDictEqual(
         works["757504fb-a130-4b84-9eb5-1b37164f12dd"], {
             "id": "757504fb-a130-4b84-9eb5-1b37164f12dd",
             "name": "Aquemini",
             "type": "Song",
         })
Esempio n. 7
0
 def test_fetch_multiple_works_missing(self, engine):
     works = mb_work.fetch_multiple_works([
         '36e33f94-ef5f-36b5-97b0-c1ed9c5a542f',
         '36e33f94-eeee-eeee-eeee-c1ed9c5a542f'
     ])
     assert list(works.keys()) == ['36e33f94-ef5f-36b5-97b0-c1ed9c5a542f']