diff --git a/pymusixmatch/musixmatch.py b/pymusixmatch/musixmatch.py index a9f626c..962b318 100644 --- a/pymusixmatch/musixmatch.py +++ b/pymusixmatch/musixmatch.py @@ -37,7 +37,7 @@ def _apikey(self) -> str: """ return self.__api_key - def _request(self, url: str) -> dict: + def _request(self, url: str, format: Format = Format.JSON) -> dict: """Get the request. Args: @@ -47,6 +47,8 @@ def _request(self, url: str) -> dict: dict: The request. """ request = requests.get(url) + if format == Format.XML: + return request.text return request.json() def _set_page_size(self, page_size: int) -> int: @@ -366,7 +368,7 @@ def matcher_lyrics_get( return data def matcher_track_get( - self, q_track: str, q_artist: str, q_album: Optional[str] = None + self, q_track: str, q_artist: str, q_album: Optional[str] = "" ) -> dict: """Match your song against our database. @@ -401,12 +403,11 @@ def matcher_track_get( def matcher_subtitle_get( self, - q_track, - q_artist, - f_subtitle_length, - f_subtitle_length_max_deviation, - track_isrc=None, - _format="json", + q_track: str, + q_artist: str, + f_subtitle_length: int, + f_subtitle_length_max_deviation: int, + track_isrc: Optional[str] = "", ): """Get the subtitles for a song given his title,artist and duration. @@ -415,14 +416,13 @@ def matcher_subtitle_get( Parameters: - q_track - The song title. - q_artist - The song artist. - f_subtitle_length - Filter by subtitle length in seconds. - f_subtitle_length_max_deviation - Max deviation for a subtitle + q_track (str): The song title. + q_artist (str): The song artist. + f_subtitle_length (int): Filter by subtitle length in seconds. + f_subtitle_length_max_deviation (int): Max deviation for a subtitle length in seconds. - track_isrc - If you have an available isrc id in your catalogue + track_isrc (str): If you have an available isrc id in your catalogue you can query using this id only (optional). - format - Decide the output type json or xml (default json). Note: This method requires a commercial plan. """ @@ -431,15 +431,15 @@ def matcher_subtitle_get( "matcher.subtitle.get?q_track={}" "&q_artist={}&f_subtitle_length={}" "&f_subtitle_length_max_deviation={}" - "&track_isrc={}&format={}".format( + "&track_isrc={}".format( q_track, q_artist, f_subtitle_length, f_subtitle_length_max_deviation, track_isrc, - _format, ), ), + format=Format.XML, ) return data diff --git a/tests/conftest.py b/tests/conftest.py index dd74970..6011d42 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -188,3 +188,33 @@ def matcher_track_get() -> dict: "body": {"track": "track'"}, } } + + +@pytest.fixture +def matcher_subtitle_get() -> str: + return """ + + +
+ 200 + 0.064241886138916 +
+ + + 28141 + 0 + [0:16.12] When I walk on by, girls be looking like damn he fly + [0:19.69] I pay to the beat, walking on the street with in my new lafreak, yeah + [0:23.48] This is how I roll, animal print, pants out control, + ... + 199 + en + http://tracking.musixmatch.com/t1.0/5RIyfxxrQ==/ + http://tracking.musixmatch.com/t1.0/5RIyxx=/ + + + 2012-04-01T21:53:11Z + + +
+ """ diff --git a/tests/test_musixmatch.py b/tests/test_musixmatch.py index c066934..f4881c3 100644 --- a/tests/test_musixmatch.py +++ b/tests/test_musixmatch.py @@ -181,14 +181,15 @@ def test_matcher_track_get(self, requests_mock, matcher_track_get: dict) -> None 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): - self.assertEqual( - self.musixmatch.matcher_subtitle_get("Sexy and I know it", "LMFAO", 200, 3)[ - "message" - ]["body"], - "", + def test_matcher_subtitle_get( + self, requests_mock, matcher_subtitle_get: str + ) -> None: + url = "https://api.musixmatch.com/ws/1.1/matcher.subtitle.get?q_artist=justinbieber&q_track=Let%20Me%20Love%20You&" + requests_mock.get(url=url, text=matcher_subtitle_get) + request = self.musixmatch.matcher_subtitle_get( + "Let Me Love You", "justinbieber", 10, 10 ) + assert matcher_subtitle_get == request @pytest.mark.skip("Refactor test") def test_artist_get(self):