From 3118140f0f2d8c52c7940982216f1f5d0bcaa027 Mon Sep 17 00:00:00 2001 From: Kur01234 Date: Wed, 5 Jun 2024 09:47:02 +0200 Subject: [PATCH] feat: fix saving img in tmp --- music_kraken/download/page_attributes.py | 3 ++- music_kraken/pages/bandcamp.py | 26 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/music_kraken/download/page_attributes.py b/music_kraken/download/page_attributes.py index eba3274..320192f 100644 --- a/music_kraken/download/page_attributes.py +++ b/music_kraken/download/page_attributes.py @@ -174,6 +174,7 @@ class Pages: name=artwork_variant["url"], ) + temp_target: Target = Target.temp() with temp_target.open("wb") as f: f.write(r.content) @@ -195,7 +196,7 @@ class Pages: if img.mode != 'RGB': img = img.convert('RGB') - img.save(converted_target.file_path, main_settings["image_format"]) + img.save(target.file_path, main_settings["image_format"]) diff --git a/music_kraken/pages/bandcamp.py b/music_kraken/pages/bandcamp.py index 0eae4ac..2125c6e 100644 --- a/music_kraken/pages/bandcamp.py +++ b/music_kraken/pages/bandcamp.py @@ -292,9 +292,15 @@ class Bandcamp(Page): artist_source_list = [] if "@id" in artist_data: artist_source_list = [Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))] + + + source_list: List[Source] = [source] + if "mainEntityOfPage" in data or "@id" in data: + source_list.append(Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]))) + album = Album( title=data["name"].strip(), - source_list=[Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]))], + source_list=source_list, date=ID3Timestamp.strptime(data["datePublished"], "%d %b %Y %H:%M:%S %Z"), artist_list=[Artist( name=artist_data["name"].strip(), @@ -366,17 +372,29 @@ class Bandcamp(Page): for key, value in other_data.get("trackinfo", [{}])[0].get("file", {"": None}).items(): mp3_url = value + source_list: List[Source] = [source] + if "mainEntityOfPage" in data or "@id" in data: + source_list.append(Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]), audio_url=mp3_url)) + + source_list_album: List[Source] = [source] + if "@id" in album_data: + source_list_album.append(Source(self.SOURCE_TYPE, album_data["@id"])) + + source_list_artist: List[Source] = [source] + if "@id" in artist_data: + source_list_artist.append(Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))) + song = Song( title=clean_song_title(data["name"], artist_name=artist_data["name"]), - source_list=[source, Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]), audio_url=mp3_url)], + source_list=source_list, album_list=[Album( title=album_data["name"].strip(), date=ID3Timestamp.strptime(data["datePublished"], "%d %b %Y %H:%M:%S %Z"), - source_list=[Source(self.SOURCE_TYPE, album_data["@id"])] + source_list=source_list_album )], artist_list=[Artist( name=artist_data["name"].strip(), - source_list=[Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))] + source_list=source_list_artist )], lyrics_list=self._fetch_lyrics(soup=soup) )