From 835115a6f7b54f41d6faffc8fd83df8f632d8bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Wed, 25 Feb 2026 21:07:26 +0000 Subject: [PATCH] Fix genius end to end lyrics test --- beetsplug/_typing.py | 9 +++++++++ beetsplug/lyrics.py | 14 +++++++++++++- test/plugins/lyrics_pages.py | 23 +++++++++++------------ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/beetsplug/_typing.py b/beetsplug/_typing.py index b772ffdd5..6c69aeed4 100644 --- a/beetsplug/_typing.py +++ b/beetsplug/_typing.py @@ -85,6 +85,15 @@ class GeniusAPI: class Search(TypedDict): response: GeniusAPI.SearchResponse + class StatusResponse(TypedDict): + status: int + message: str + + class Meta(TypedDict): + meta: GeniusAPI.StatusResponse + + Response = Search | Meta + class GoogleCustomSearchAPI: class Response(TypedDict): diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 4e732c22e..26c95c4e6 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -67,6 +67,10 @@ class CaptchaError(requests.exceptions.HTTPError): super().__init__("Captcha is required", *args, **kwargs) +class GeniusHTTPError(requests.exceptions.HTTPError): + pass + + # Utilities. @@ -564,8 +568,16 @@ class Genius(SearchBackend): def headers(self) -> dict[str, str]: return {"Authorization": f"Bearer {self.config['genius_api_key']}"} + def get_json(self, *args, **kwargs) -> GeniusAPI.Search: + response: GeniusAPI.Response = super().get_json(*args, **kwargs) + if "response" in response: + return response # type: ignore[return-value] + + meta = response["meta"] + raise GeniusHTTPError(f"{meta['message']} Status: {meta['status']}") + def search(self, artist: str, title: str) -> Iterable[SearchResult]: - search_data: GeniusAPI.Search = self.get_json( + search_data = self.get_json( self.SEARCH_URL, params={"q": f"{artist} {title}"}, headers=self.headers, diff --git a/test/plugins/lyrics_pages.py b/test/plugins/lyrics_pages.py index 047b6e443..ce2728b64 100644 --- a/test/plugins/lyrics_pages.py +++ b/test/plugins/lyrics_pages.py @@ -133,15 +133,13 @@ lyrics_pages = [ LyricsPage.make( "https://genius.com/The-beatles-lady-madonna-lyrics", """ - [Intro: Instrumental] - [Verse 1: Paul McCartney] Lady Madonna, children at your feet Wonder how you manage to make ends meet Who finds the money when you pay the rent? Did you think that money was heaven sent? - [Bridge: Paul McCartney] + [Bridge: Paul McCartney, Paul McCartney, John Lennon & George Harrison] Friday night arrives without a suitcase Sunday morning creeping like a nun Monday's child has learned to tie his bootlace @@ -150,27 +148,28 @@ lyrics_pages = [ [Verse 2: Paul McCartney] Lady Madonna, baby at your breast Wonders how you manage to feed the rest - - [Bridge: Paul McCartney, John Lennon & George Harrison] [Tenor Saxophone Solo: Ronnie Scott] + + [Bridge: John Lennon & George Harrison, Paul McCartney, John Lennon & George Harrison] + Pa-pa-pa-pa, pa-pa-pa-pa-pa + Pa-pa-pa-pa-pa, pa-pa-pa, pa-pa, pa-pa + Pa-pa-pa-pa, pa-pa-pa-pa-pa See how they run [Verse 3: Paul McCartney] Lady Madonna, lying on the bed Listen to the music playing in your head - [Bridge: Paul McCartney] - Tuesday afternoon is never ending - Wednesday morning papers didn't come - Thursday night your stockings needed mending + [Bridge: Paul McCartney, John Lennon & George Harrison, Paul McCartney, John Lennon & George Harrison] + Tuesday afternoon is never ending (Pa-pa-pa-pa, pa-pa-pa-pa-pa) + Wednesday morning, papers didn't come (Pa-pa-pa-pa-pa, pa-pa-pa, pa-pa, pa-pa) + Thursday night, your stockings needed mending (Pa-pa-pa-pa, pa-pa-pa-pa-pa) See how they run [Verse 4: Paul McCartney] Lady Madonna, children at your feet Wonder how you manage to make ends meet - - [Outro: Instrumental] - """, + """, # noqa: E501 marks=[xfail_on_ci("Genius returns 403 FORBIDDEN in CI")], ), LyricsPage.make(