def get_releases_using_recording_mbid(recording_mbid): """Returns a list of releases that contain the recording with the given recording MBID. Args: recording_mbid (UUID): recording MBID for which releases are to be fetched. Returns: serial_releases (list): list with dictionary elements of following format: { 'id': <release MBID>, 'name': <release Title>, } """ # First fetch the recording so that redirects don't create any problem recording_redirect = recording.get_recording_by_mbid(recording_mbid) recording_mbid = recording_redirect['id'] with mb_session() as db: releases = db.query(models.Release).\ join(models.Medium).\ join(models.Track).\ join(models.Recording).\ filter(models.Recording.gid == recording_mbid).all() serial_releases = [serialize_releases(release) for release in releases] if not serial_releases: raise mb_exceptions.NoDataFoundException("Couldn't find release for recording with MBID: %s." % str(recording_mbid)) return serial_releases
def fetch_multiple_releases(mbids, includes=None, unknown_entities_for_missing=False): """Get info related to multiple releases using their MusicBrainz IDs. Args: mbids (list): List of MBIDs of releases. includes (list): List of information to be included. Returns: Dictionary containing info of multiple releases keyed by their mbid. """ if includes is None: includes = [] includes_data = defaultdict(dict) check_includes('release', includes) with mb_session() as db: query = db.query(models.Release) if 'release-groups' in includes: query = query.options(joinedload('release_group')) if 'media' in includes: # Fetch media with tracks query = query.options(joinedload('mediums')).\ options(joinedload('mediums.tracks')).\ options(joinedload('mediums.format')).\ options(joinedload('mediums.tracks.recording')) releases = get_entities_by_gids( query=query, entity_type='release', mbids=mbids, unknown_entities_for_missing=unknown_entities_for_missing, ) release_ids = [release.id for release in releases.values()] if 'release-groups' in includes: for release in releases.values(): includes_data[ release.id]['release-groups'] = release.release_group if 'media' in includes: for release in releases.values(): includes_data[release.id]['media'] = release.mediums if 'url-rels' in includes: get_relationship_info( db=db, target_type='url', source_type='release', source_entity_ids=release_ids, includes_data=includes_data, ) releases = { str(mbid): serialize_releases(releases[mbid], includes_data[releases[mbid].id]) for mbid in mbids } return releases
def fetch_multiple_releases(mbids, includes=None): """Get info related to multiple releases using their MusicBrainz IDs. Args: mbids (list): List of MBIDs of releases. includes (list): List of information to be included. Returns: Dictionary containing info of multiple releases keyed by their mbid. """ if includes is None: includes = [] includes_data = defaultdict(dict) check_includes('release', includes) with mb_session() as db: query = db.query(models.Release) if 'release-groups' in includes: query = query.options(joinedload('release_group')) if 'media' in includes: # Fetch media with tracks query = query.options(joinedload('mediums')).\ options(joinedload('mediums.tracks')).\ options(joinedload('mediums.format')).\ options(joinedload('mediums.tracks.recording')) releases = get_entities_by_gids( query=query, entity_type='release', mbids=mbids, ) release_ids = [release.id for release in releases.values()] if 'release-groups' in includes: for release in releases.values(): includes_data[release.id]['release-groups'] = release.release_group if 'media' in includes: for release in releases.values(): includes_data[release.id]['media'] = release.mediums if 'url-rels' in includes: get_relationship_info( db=db, target_type='url', source_type='release', source_entity_ids=release_ids, includes_data=includes_data, ) releases = {str(mbid): serialize_releases(releases[mbid], includes_data[releases[mbid].id]) for mbid in mbids} return releases
def fetch_multiple_releases(mbids, includes=None): """Get info related to multiple releases using their MusicBrainz IDs. Args: mbids (list): List of MBIDs of releases. includes (list): List of information to be included. Returns: A dictionary containing info of multiple releases keyed by their MBID. If an MBID doesn't exist in the database, it isn't returned. If an MBID is a redirect, the dictionary key will be the MBID given as an argument, but the returned object will contain the new MBID in the 'mbid' key. """ if includes is None: includes = [] includes_data = defaultdict(dict) check_includes('release', includes) with mb_session() as db: query = db.query(models.Release) if 'release-groups' in includes: query = query.options(joinedload('release_group')) if 'artists' in includes: query = query.\ options(joinedload("artist_credit")).\ options(joinedload("artist_credit.artists")).\ options(joinedload("artist_credit.artists.artist")) if 'media' in includes: # Fetch media with tracks query = query.options(joinedload('mediums')).\ options(joinedload('mediums.tracks')).\ options(joinedload('mediums.format')).\ options(joinedload('mediums.tracks.recording')).\ options(joinedload('mediums.tracks.recording.artist_credit')).\ options(joinedload('mediums.tracks.recording.artist_credit.artists')).\ options(joinedload('mediums.tracks.recording.artist_credit.artists.artist')) releases = get_entities_by_gids( query=query, entity_type='release', mbids=mbids, ) release_ids = [release.id for release in releases.values()] if 'release-groups' in includes: for release in releases.values(): includes_data[ release.id]['release-groups'] = release.release_group if 'artists' in includes: for release in releases.values(): artist_credit_names = release.artist_credit.artists includes_data[ release.id]['artist-credit-names'] = artist_credit_names includes_data[release.id][ 'artist-credit-phrase'] = release.artist_credit.name if 'media' in includes: for release in releases.values(): includes_data[release.id]['media'] = release.mediums if 'url-rels' in includes: get_relationship_info( db=db, target_type='url', source_type='release', source_entity_ids=release_ids, includes_data=includes_data, ) releases = { str(mbid): serialize_releases(release, includes_data[release.id]) for mbid, release in releases.items() } return releases