Skip to content

Commit

Permalink
Merge pull request #303 from amCap1712/recording-entity-support
Browse files Browse the repository at this point in the history
CB-270: Implemented the reviewal of recordings
  • Loading branch information
amCap1712 authored Aug 22, 2021
2 parents a808e47 + e6b4255 commit 63f014f
Show file tree
Hide file tree
Showing 33 changed files with 578 additions and 92 deletions.
1 change: 1 addition & 0 deletions admin/schema_changes/18.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE entity_types ADD VALUE 'recording' AFTER 'label';
3 changes: 2 additions & 1 deletion admin/sql/create_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ CREATE TYPE entity_types AS ENUM (
'place',
'work',
'artist',
'label'
'label',
'recording'
);
1 change: 1 addition & 0 deletions critiquebrainz/db/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"work",
"artist",
"label",
"recording"
]

supported_languages = []
Expand Down
2 changes: 2 additions & 0 deletions critiquebrainz/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def create_app(debug=None, config_path=None):
from critiquebrainz.frontend.views.release_group import release_group_bp
from critiquebrainz.frontend.views.release import release_bp
from critiquebrainz.frontend.views.work import work_bp
from critiquebrainz.frontend.views.recording import recording_bp
from critiquebrainz.frontend.views.event import event_bp
from critiquebrainz.frontend.views.mapping import mapping_bp
from critiquebrainz.frontend.views.user import user_bp
Expand All @@ -160,6 +161,7 @@ def create_app(debug=None, config_path=None):
app.register_blueprint(release_group_bp, url_prefix='/release-group')
app.register_blueprint(release_bp, url_prefix='/release')
app.register_blueprint(work_bp, url_prefix='/work')
app.register_blueprint(recording_bp, url_prefix='/recording')
app.register_blueprint(event_bp, url_prefix='/event')
app.register_blueprint(place_bp, url_prefix='/place')
app.register_blueprint(mapping_bp, url_prefix='/mapping')
Expand Down
6 changes: 6 additions & 0 deletions critiquebrainz/frontend/external/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ def search_labels(query='', limit=None, offset=None):
"""Search for labels."""
api_resp = musicbrainzngs.search_labels(query=query, limit=limit, offset=offset)
return api_resp.get('label-count'), api_resp.get('label-list')


def search_recordings(query='', limit=None, offset=None):
"""Search for recordings."""
api_resp = musicbrainzngs.search_recordings(query=query, limit=limit, offset=offset)
return api_resp.get('recording-count'), api_resp.get('recording-list')
6 changes: 3 additions & 3 deletions critiquebrainz/frontend/external/musicbrainz_db/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def get_artist_by_id(mbid):
key = cache.gen_key('artist', mbid)
artist = cache.get(key)
if not artist:
artist = db.fetch_multiple_artists(
[mbid],
artist = db.get_artist_by_id(
mbid,
includes=['artist-rels', 'url-rels'],
unknown_entities_for_missing=True,
).get(mbid)
)
cache.set(key=key, val=artist, time=DEFAULT_CACHE_EXPIRATION)
return artist_rel.process(artist)
22 changes: 15 additions & 7 deletions critiquebrainz/frontend/external/musicbrainz_db/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
from brainzutils.musicbrainz_db.place import fetch_multiple_places
from brainzutils.musicbrainz_db.release_group import fetch_multiple_release_groups
from brainzutils.musicbrainz_db.work import fetch_multiple_works
from brainzutils.musicbrainz_db.recording import fetch_multiple_recordings

from critiquebrainz.frontend.external.musicbrainz_db.artist import get_artist_by_id
from critiquebrainz.frontend.external.musicbrainz_db.event import get_event_by_id
from critiquebrainz.frontend.external.musicbrainz_db.label import get_label_by_id
from critiquebrainz.frontend.external.musicbrainz_db.place import get_place_by_id
from critiquebrainz.frontend.external.musicbrainz_db.release_group import get_release_group_by_id
from critiquebrainz.frontend.external.musicbrainz_db.work import get_work_by_id
from critiquebrainz.frontend.external.musicbrainz_db.recording import get_recording_by_id


def get_multiple_entities(entities):
"""Fetch multiple entities using their MBIDs.
Args:
entites: List of tuples containing the entity ID and the entity type.
entities: List of tuples containing the entity ID and the entity type.
Returns:
Dictionary containing the basic information related to the entities.
Expand All @@ -29,12 +31,13 @@ def get_multiple_entities(entities):
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)]
release_group_mbids = [entity[0] for entity in entities if entity[1] == 'release_group']
artist_mbids = [entity[0] for entity in entities if entity[1] == 'artist']
label_mbids = [entity[0] for entity in entities if entity[1] == 'label']
recording_mbids = [entity[0] for entity in entities if entity[1] == 'recording']
place_mbids = [entity[0] for entity in entities if entity[1] == 'place']
event_mbids = [entity[0] for entity in entities if entity[1] == 'event']
work_mbids = [entity[0] for entity in entities if entity[1] == 'work']
entities_info.update(fetch_multiple_release_groups(
release_group_mbids,
includes=['artists'],
Expand All @@ -57,6 +60,9 @@ def get_multiple_entities(entities):
entities_info.update(fetch_multiple_works(
work_mbids,
))
entities_info.update(fetch_multiple_recordings(
recording_mbids,
))
return entities_info


Expand All @@ -74,4 +80,6 @@ def get_entity_by_id(id, type='release_group'):
entity = get_event_by_id(str(id))
elif type == 'work':
entity = get_work_by_id(str(id))
elif type == 'recording':
entity = get_recording_by_id(str(id))
return entity
6 changes: 3 additions & 3 deletions critiquebrainz/frontend/external/musicbrainz_db/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def get_event_by_id(mbid):
key = cache.gen_key('event', mbid)
event = cache.get(key)
if not event:
event = db.fetch_multiple_events(
[mbid],
event = db.get_event_by_id(
mbid,
includes=['artist-rels', 'place-rels', 'series-rels', 'url-rels', 'release-group-rels'],
unknown_entities_for_missing=True,
).get(mbid)
)
cache.set(key=key, val=event, time=DEFAULT_CACHE_EXPIRATION)
return event
6 changes: 3 additions & 3 deletions critiquebrainz/frontend/external/musicbrainz_db/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def get_label_by_id(mbid):
key = cache.gen_key('label', mbid)
label = cache.get(key)
if not label:
label = db.fetch_multiple_labels(
[mbid],
label = db.get_label_by_id(
mbid,
includes=['artist-rels', 'url-rels'],
unknown_entities_for_missing=True
).get(mbid)
)
cache.set(key=key, val=label, time=DEFAULT_CACHE_EXPIRATION)
return label_rel.process(label)
6 changes: 3 additions & 3 deletions critiquebrainz/frontend/external/musicbrainz_db/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def get_place_by_id(mbid):
key = cache.gen_key('place', mbid)
place = cache.get(key)
if not place:
place = db.fetch_multiple_places(
[mbid],
place = db.get_place_by_id(
mbid,
includes=['artist-rels', 'place-rels', 'release-group-rels', 'url-rels'],
unknown_entities_for_missing=True,
).get(mbid)
)
cache.set(key=key, val=place, time=DEFAULT_CACHE_EXPIRATION)
return place_rel.process(place)
23 changes: 23 additions & 0 deletions critiquebrainz/frontend/external/musicbrainz_db/recording.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from brainzutils import cache
from brainzutils.musicbrainz_db import recording as db

from critiquebrainz.frontend.external.musicbrainz_db import DEFAULT_CACHE_EXPIRATION


def get_recording_by_id(mbid):
"""Get recording with MusicBrainz ID.
Args:
mbid (uuid): MBID(gid) of the recording.
Returns:
Dictionary containing the recording information
"""
key = cache.gen_key('recording', mbid)
recording = cache.get(key)
if not recording:
recording = db.get_recording_by_mbid(
mbid,
includes=['artists', 'work-rels', 'url-rels'],
)
cache.set(key=key, val=recording, time=DEFAULT_CACHE_EXPIRATION)
return recording
6 changes: 3 additions & 3 deletions critiquebrainz/frontend/external/musicbrainz_db/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def get_release_by_id(mbid):
key = cache.gen_key('release', mbid)
release = cache.get(key)
if not release:
release = db.fetch_multiple_releases(
[mbid],
release = db.get_release_by_id(
mbid,
includes=['media', 'release-groups'],
unknown_entities_for_missing=True,
).get(mbid)
)
cache.set(key=key, val=release, time=DEFAULT_CACHE_EXPIRATION)
return release
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def get_release_group_by_id(mbid):
key = cache.gen_key('release-group', mbid)
release_group = cache.get(key)
if not release_group:
release_group = db.fetch_multiple_release_groups(
[mbid],
release_group = db.get_release_group_by_id(
mbid,
includes=['artists', 'releases', 'release-group-rels', 'url-rels', 'tags'],
unknown_entities_for_missing=True,
)[mbid]
)
cache.set(key=key, val=release_group, time=DEFAULT_CACHE_EXPIRATION)
return release_group_rel.process(release_group)

Expand Down
Loading

0 comments on commit 63f014f

Please sign in to comment.