From a5911b670ad29265f1f60615451536260478b68b Mon Sep 17 00:00:00 2001 From: Puqns67 Date: Tue, 15 Oct 2024 19:32:23 +0800 Subject: [PATCH] fix: uncatchable exception will be thrown if `cookies.txt` not found Fixes: 097e5410036cb69f6eae8c75073c0ef14de00b48 (fix: cookie load and save errors, pure music track save error, lrc class creating error) --- src/ncmlyrics/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ncmlyrics/api.py b/src/ncmlyrics/api.py index 2485f30..4d15740 100644 --- a/src/ncmlyrics/api.py +++ b/src/ncmlyrics/api.py @@ -191,11 +191,12 @@ class NCMLyrics: class NCMApi: def __init__(self, http2: bool = True) -> None: + self._cookiePath = PLATFORM.user_config_path / "cookies.txt" self._cookieJar = MozillaCookieJar() try: - self._cookieJar.load(str(PLATFORM.user_config_path / "cookies.txt")) - except FileNotFoundError | LoadError: + self._cookieJar.load(str(self._cookiePath)) + except (FileNotFoundError, LoadError): pass self._httpClient = HttpXClient( @@ -225,7 +226,7 @@ class NCMApi: raise NCMApiRequestError def saveCookies(self) -> None: - self._cookieJar.save(str(PLATFORM.user_config_path / "cookies.txt")) + self._cookieJar.save(str(self._cookiePath)) def getDetailsForTrack(self, trackId: int) -> NCMTrack: request = self._httpClient.build_request("GET", "/v3/song/detail", params={"c": f"[{{'id':{trackId}}}]"})