feat: fetching song details of bandcamp

This commit is contained in:
Hellow 2023-09-12 22:48:52 +02:00
parent fd9a93f555
commit a3934a384e
2 changed files with 33 additions and 2 deletions

View File

@ -30,7 +30,8 @@ if __name__ == "__main__":
youtube_music_test = [ youtube_music_test = [
"s: #a Only Smile #r Your best friend", "s: #a Only Smile #r Your best friend",
"8" "8",
"2"
] ]
music_kraken.cli.download(genre="test", command_list=youtube_music_test, process_metadata_anyway=True) music_kraken.cli.download(genre="test", command_list=youtube_music_test, process_metadata_anyway=True)

View File

@ -256,7 +256,37 @@ class Bandcamp(Page):
def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song: def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song:
print(source) print(source)
return Song()
r = self.connection.get(source.url)
if r is None:
return Song()
soup = self.get_soup_from_response(r)
data_container = soup.find("script", {"type": "application/ld+json"})
if DEBUG:
dump_to_file("bandcamp_song_data.json", data_container.text, is_json=True, exit_after_dump=False)
data = json.loads(data_container.text)
album_data = data["inAlbum"]
artist_data = data["byArtist"]
song = Song(
title=data["name"],
source_list=[Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]))],
album_list=[Album(
title=album_data["name"],
date=ID3Timestamp.strptime(data["datePublished"], "%d %b %Y %H:%M:%S %Z"),
source_list=[Source(self.SOURCE_TYPE, album_data["@id"])]
)],
main_artist_list=[Artist(
name=artist_data["name"],
source_list=[Source(self.SOURCE_TYPE, artist_data["@id"])]
)]
)
return song
def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult: def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult:
return DownloadResult() return DownloadResult()