"""ows-track connector.""" from http import HTTPStatus from owsclient import OwsClient from src.exceptions import StereoTrackNotFound class OwsTrackConnector: def __init__(self, client: OwsClient): """Initialize ows-track connector.""" self.client = client def get_track_id_by_upc_and_isrc(self, upc: int, isrc: str) -> int: """Fetch the track_id for a given UPC + ISRC. Args: upc (int): UPC of the stereo release isrc (str): ISRC of the stereo track Returns: (int): track_id """ response = self.client.get("ows-track", path=f"/track/upc/{upc}/isrc/{isrc}") if response.status_code == HTTPStatus.NOT_FOUND: raise StereoTrackNotFound(f"Stereo ISRC {isrc} was not found on stereo UPC {upc}") response.raise_for_status() return int(response.json()["tuid"]) def create_track_spatial(self, track_id: int, spatial_isrc: str) -> None: """Create a track_spatial record linking a stereo track to its spatial ISRC. Args: track_id (int): stereo track_id spatial_isrc (str): ISRC of the spatial track """ response = self.client.post( "ows-track", path=f"/track/{track_id}/spatial", json={"isrc": spatial_isrc}, ) if response.status_code == HTTPStatus.CONFLICT: print(f"track_spatial record already exists for track_id={track_id}, spatial_isrc={spatial_isrc}, skipping") return response.raise_for_status()