From d9aa6a8f5bec08a9a8d0389fcbf6db5a89bd14a7 Mon Sep 17 00:00:00 2001 From: Hellow Date: Sun, 27 Nov 2022 23:39:08 +0100 Subject: [PATCH] added timeout 10 sec to musify --- src/music_kraken/__main__.py | 2 +- src/music_kraken/lyrics/genius.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/music_kraken/__main__.py b/src/music_kraken/__main__.py index 19dc143..6990647 100644 --- a/src/music_kraken/__main__.py +++ b/src/music_kraken/__main__.py @@ -2,6 +2,6 @@ import music_kraken if __name__ == "__main__": - music_kraken.cli(start_at=0, only_lyrics=False) + music_kraken.cli(start_at=2, only_lyrics=False) # Youtube.fetch_audio({'title': 'dfas', '': '', 'isrc': ''}) # Youtube.fetch_audio({'title': 'dfas', 'url': '', 'file': 'dasf', 'isrc': ''}) diff --git a/src/music_kraken/lyrics/genius.py b/src/music_kraken/lyrics/genius.py index 52a1371..0854076 100644 --- a/src/music_kraken/lyrics/genius.py +++ b/src/music_kraken/lyrics/genius.py @@ -12,6 +12,8 @@ from ..utils.shared import * from ..utils import phonetic_compares from ..utils.object_handeling import get_elem_from_obj +TIMEOUT = 10 + # search doesn't support isrc # https://genius.com/api/search/multi?q=I Prevail - Breaking Down # https://genius.com/api/songs/6192944 @@ -72,7 +74,11 @@ class LyricsSong: if not self.valid: logger.warning(f"{self.__repr__()} is invalid but the lyrics still get fetched. Something could be wrong.") - r = session.get(self.url) + try: + r = session.get(self.url, timeout=TIMEOUT) + except requests.exceptions.Timeout: + logger.warning(f"{self.url} timed out after {TIMEOUT} seconds") + return None if r.status_code != 200: logger.warning(f"{r.url} returned {r.status_code}:\n{r.content}") return None @@ -114,7 +120,11 @@ def search_song_list(artist: str, track: str) -> List[LyricsSong]: 'track': track } - r = session.get(url) + try: + r = session.get(url, timeout=TIMEOUT) + except requests.exceptions.Timeout: + logger.warning(f"{url} timed out after {TIMEOUT} seconds") + return [] if r.status_code != 200: logging.warning(f"{r.url} returned {r.status_code}:\n{r.content}") return []