From 345962ee8383db91670f9fe4ae7d00dc6cd85e77 Mon Sep 17 00:00:00 2001 From: spameier Date: Fri, 21 Apr 2023 12:46:35 +0200 Subject: [PATCH] feat: add suport for Metadata API Reference: https://docs.acrcloud.com/reference/metadata-api --- acrclient/client.py | 14 +++++++++++++- acrclient/models.py | 13 ++++++++++++- tests/test_client.py | 7 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/acrclient/client.py b/acrclient/client.py index 143f4e8..57ff616 100644 --- a/acrclient/client.py +++ b/acrclient/client.py @@ -5,9 +5,10 @@ from requests import Session from requests.adapters import HTTPAdapter, Retry from requests.auth import AuthBase +from requests.exceptions import HTTPError from requests.models import PreparedRequest, Response -from .models import GetBmCsProjectsResultsParams +from .models import GetBmCsProjectsResultsParams, GetExternalMetadataTracksParams class _Auth(AuthBase): # pylint: disable=too-few-public-methods @@ -155,3 +156,14 @@ def get_bm_cs_projects_results( params=params, **kwargs, ).get("data") + + def get_external_metadata_tracks( + self, params: Optional[GetExternalMetadataTracksParams] = None + ) -> list: + try: + return self.json(path="/api/external-metadata/tracks", params=params).get( + "data" + ) + except HTTPError as error: + print(error) + return [] diff --git a/acrclient/models.py b/acrclient/models.py index 414d9a1..93f9b3a 100644 --- a/acrclient/models.py +++ b/acrclient/models.py @@ -1,4 +1,4 @@ -from typing import TypedDict +from typing import Literal, TypedDict class GetBmCsProjectsResultsParams(TypedDict): @@ -14,3 +14,14 @@ class GetBmCsProjectsResultsParams(TypedDict): """Return the results with played_duration <= max_duration seconds (default: 3600)""" isrc_country: str """Only return results that match the isrc country code (E.g. DE, FR, IT, US)""" + + +class GetExternalMetadataTracksParams(TypedDict): + """Parameters for getting music platforms metadata and links""" + + type: str + """ACRCloud Music ID""" + acr_id: str + """1 or 0, if you set it to 1, the response metadata will contain the contributors and works + metadata if the tracks have""" + include_works: Literal[0, 1] diff --git a/tests/test_client.py b/tests/test_client.py index 2944bca..8f79b10 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -25,3 +25,10 @@ def test_client_get_bm_cs_projects_results(): json={"data": {}}, ) client.get_bm_cs_projects_results("project-id", "stream-id") + + +def test_client_get_external_metadata_tracks(): + client = Client(_Auth("bearer-token")) + with requests_mock.Mocker() as mock: + mock.get(f"{client.base_url}/api/external-metadata/tracks", json={"data": [{}]}) + client.get_external_metadata_tracks()