Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor method matcher_track_get #53

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions pymusixmatch/musixmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,22 +350,24 @@ def matcher_lyrics_get(

Parameters:

q_track - The song title
q_artist - The song artist
track_isrc - If you have an available isrc id in your catalogue
q_track (str): The song title
q_artist (str): The song artist
track_isrc (str): If you have an available isrc id in your catalogue
you can query using this id only (optional)
track_isrc - If you have an available musicbrainz recording id
"""
data = self._request(
self._get_url(
"matcher.lyrics.get?" "q_track={}&q_artist={}&track_isrc={}".format(
"matcher.lyrics.get?q_track={}&q_artist={}&track_isrc={}".format(
q_track, q_artist, track_isrc
),
),
)
return data

def matcher_track_get(self, q_track, q_artist, _format="json"):
def matcher_track_get(
self, q_track: str, q_artist: str, q_album: Optional[str] = None
) -> dict:
"""Match your song against our database.

In some cases you already have some informations
Expand All @@ -381,11 +383,17 @@ def matcher_track_get(self, q_track, q_artist, _format="json"):
details, and you’ll get instant benefits for your application
without changing a row in your code, while we take care of
improving the implementation behind. Cool, uh?

Parameters:

q_track (str): The song title.
q_artist (str): The song artist.
q_album (str): The song album.
"""
data = self._request(
self._get_url(
"matcher.track.get?" "q_track={}&q_artist={}" "&format={}".format(
q_track, q_artist, _format
"matcher.track.get?q_track={}&q_artist={}&q_album={}".format(
q_track, q_artist, q_album
),
),
)
Expand Down Expand Up @@ -446,7 +454,7 @@ def artist_get(self, artist_id, artist_mbid=None, _format="json"):
"""
data = self._request(
self._get_url(
"artist.get?artist_id={}" "&artist_mbid={}&format={}".format(
"artist.get?artist_id={}&artist_mbid={}&format={}".format(
artist_id, artist_mbid, _format
),
),
Expand Down Expand Up @@ -634,7 +642,7 @@ def tracking_url_get(self, domain, _format="json"):
"""
data = self._request(
self._get_url(
"tracking.url.get?" "domain={}&format={}".format(domain, _format),
"tracking.url.get?domain={}&format={}".format(domain, _format),
),
)
return data
Expand Down Expand Up @@ -669,6 +677,6 @@ def genres_get(self, _format="json"):
format - Decide the output type json or xml (default json)
"""
data = self._request(
self._get_url("music.genres.get?" "format={}".format(_format)),
self._get_url("music.genres.get?format={}".format(_format)),
)
return data
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,13 @@ def matcher_lyrics_get() -> dict:
},
}
}


@pytest.fixture
def matcher_track_get() -> dict:
return {
"message": {
"header": {"status_code": 200, "execute_time": 0.00136, "confidence": 949},
"body": {"track": "track'"},
}
}
21 changes: 6 additions & 15 deletions tests/test_musixmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setup_class(cls) -> None:
def test_get_url(self) -> None:
assert (
self.musixmatch._get_url(
"chart.artists.get?" "page=1&page_size=1&country=us" "&format=json",
"chart.artists.get?page=1&page_size=1&country=us&format=json",
)
== f"{self.url}chart.artists.get?page=1&page_size=1&country=us&format=json&apikey=test"
)
Expand Down Expand Up @@ -175,20 +175,11 @@ def test_matcher_lyrics_get(self, requests_mock, matcher_lyrics_get) -> None:
request = self.musixmatch.matcher_lyrics_get("Let Me Love You", "justinbieber")
assert matcher_lyrics_get == request

@pytest.mark.skip("Refactor test")
def test_matcher_track_get(self):
self.assertEqual(
self.musixmatch.matcher_track_get("Lose Yourself (soundtrack)", "Eminem")[
"message"
]["body"]["track"]["track_name"],
"Lose Yourself - " "Soundtrack Version" " (Explicit)",
)
self.assertEqual(
self.musixmatch.matcher_track_get("Lose Yourself (soundtrack)", "Eminem")[
"message"
]["body"]["track"]["album_name"],
"Curtain Call",
)
def test_matcher_track_get(self, requests_mock, matcher_track_get: dict) -> None:
url = "https://api.musixmatch.com/ws/1.1/matcher.track.get?q_artist=justinbieber&q_track=Let%20Me%20Love%20You&"
requests_mock.get(url=url, json=matcher_track_get)
request = self.musixmatch.matcher_track_get("Let Me Love You", "justinbieber")
assert matcher_track_get == request

@pytest.mark.skip("Refactor test")
def test_matcher_subtitle_get(self):
Expand Down
Loading