"""ows-sound-recordings connections.""" from owsclient import OwsClient from src.common.exceptions import exceptions SERVICE_NAME = 'ows-sound-recordings' def get_sound_recordings( ows_client: OwsClient, sound_recording_ids=None, tuids=None, upcs=None, asset_ids=None, project_ids=None, ): """Get metadata about sound recordings. Args: ows_client (OwsClient): client to make requests to ows resources sound_recording_ids (list): str unique identifier for sr tuids (list): int unique identifier for track upcs (list): int identifier for product asset_ids (list): str unique identifier for orchard asset project_ids (list): int unique identifier for project Returns: list: parent metadata and assets list """ params = {} if sound_recording_ids: params['ids'] = ','.join( [ str(sr_id) for sr_id in sound_recording_ids ] ) if tuids: params['tuids'] = ','.join( [ str(tuid) for tuid in tuids ] ) if upcs: # Remove leading 0 in case of display upc provided params['upcs'] = ','.join( [ str(upc).lstrip('0') for upc in upcs ] ) if asset_ids: params['asset_ids'] = ','.join( [ str(asset_id) for asset_id in asset_ids ] ) if tuids or upcs: params['include_deleted'] = 'true' if project_ids: params['project_ids'] = ','.join( [ str(project_id) for project_id in project_ids ] ) retry_codes = [ 401, 408, 502, 503, 504 ] response = ows_client.get( SERVICE_NAME, '/sound_recordings', **{ 'params': params } ) if response.status_code in retry_codes: message_error = f'Unexpected response code from {SERVICE_NAME} HTTP:{response.status_code}' # noqa:E501 raise exceptions.RetryableException(message_error) return response.json()