From 5be0b3be6438e2ec3805c1e730d5f7e26d34fabd Mon Sep 17 00:00:00 2001 From: lars Date: Sun, 13 Nov 2022 23:56:43 +0100 Subject: [PATCH] dafdsaf --- src/__main__.py | 2 +- src/metadata/download.py | 20 ++++++++++++++++---- src/scraping/musify.py | 2 +- src/utils/shared.py | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 2ba65fb..66fceca 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -107,4 +107,4 @@ def cli(start_at: int = 0, only_lyrics: bool = False): if __name__ == "__main__": - cli(start_at=0, only_lyrics=True) + cli(start_at=3, only_lyrics=False) diff --git a/src/metadata/download.py b/src/metadata/download.py index 0168d46..4918cfc 100644 --- a/src/metadata/download.py +++ b/src/metadata/download.py @@ -33,7 +33,10 @@ class MetadataDownloader: self.musicbrainz_artistid = musicbrainz_artistid - result = musicbrainzngs.get_artist_by_id(self.musicbrainz_artistid, includes=["release-groups", "releases"]) + try: + result = musicbrainzngs.get_artist_by_id(self.musicbrainz_artistid, includes=["release-groups", "releases"]) + except musicbrainzngs.musicbrainz.NetworkError: + return artist_data = get_elem_from_obj(result, ['artist'], return_if_none={}) self.artist = get_elem_from_obj(artist_data, ['name']) @@ -85,8 +88,11 @@ class MetadataDownloader: self.artists = artists self.releases = [] - result = musicbrainzngs.get_release_group_by_id(musicbrainz_releasegroupid, + try: + result = musicbrainzngs.get_release_group_by_id(musicbrainz_releasegroupid, includes=["artist-credits", "releases"]) + except musicbrainzngs.musicbrainz.NetworkError: + return release_group_data = get_elem_from_obj(result, ['release-group'], return_if_none={}) artist_datas = get_elem_from_obj(release_group_data, ['artist-credit'], return_if_none={}) release_datas = get_elem_from_obj(release_group_data, ['release-list'], return_if_none={}) @@ -179,8 +185,11 @@ class MetadataDownloader: self.release_group = release_group self.tracklist = [] - result = musicbrainzngs.get_release_by_id(self.musicbrainz_albumid, + try: + result = musicbrainzngs.get_release_by_id(self.musicbrainz_albumid, includes=["recordings", "labels", "release-groups"]) + except musicbrainzngs.musicbrainz.NetworkError: + return release_data = get_elem_from_obj(result, ['release'], return_if_none={}) label_data = get_elem_from_obj(release_data, ['label-info-list'], return_if_none={}) recording_datas = get_elem_from_obj(release_data, ['medium-list', 0, 'track-list'], return_if_none=[]) @@ -251,9 +260,12 @@ class MetadataDownloader: self.track_number = track_number - result = musicbrainzngs.get_recording_by_id(self.musicbrainz_releasetrackid, + try: + result = musicbrainzngs.get_recording_by_id(self.musicbrainz_releasetrackid, includes=["artists", "releases", "recording-rels", "isrcs", "work-level-rels"]) + except musicbrainzngs.musicbrainz.NetworkError: + return recording_data = result['recording'] release_data = get_elem_from_obj(recording_data, ['release-list', -1]) if self.release is None: diff --git a/src/scraping/musify.py b/src/scraping/musify.py index b5bf136..b101c73 100644 --- a/src/scraping/musify.py +++ b/src/scraping/musify.py @@ -53,7 +53,7 @@ def download_from_musify(file, url): logging.info(f"downloading: '{url}'") try: r = session.get(url, timeout=15) - except requests.exceptions.ConnectionError: + except requests.exceptions.ConnectionError or requests.exceptions.ReadTimeout: return -1 if r.status_code != 200: if r.status_code == 404: diff --git a/src/utils/shared.py b/src/utils/shared.py index c33717a..e0b9905 100644 --- a/src/utils/shared.py +++ b/src/utils/shared.py @@ -34,7 +34,7 @@ database = Database(os.path.join(temp_dir, DATABASE_FILE), os.path.join(temp_dir, DATABASE_STRUCTURE_FILE), DATABASE_STRUCTURE_FALLBACK, DATABASE_LOGGER, - reset_anyways=True) + reset_anyways=False) TOR = False