From 1a5fbdc0c25c1072e38b08f8227d2952b47a3948 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:59:04 +0200 Subject: [PATCH] feat: reversengeneered bandcamp artist html structure --- documentation/html/bandcamp/artist_page.html | 125 +++++++++++++++++++ src/actual_donwload.py | 3 +- src/music_kraken/pages/bandcamp.py | 31 ++++- 3 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 documentation/html/bandcamp/artist_page.html diff --git a/documentation/html/bandcamp/artist_page.html b/documentation/html/bandcamp/artist_page.html new file mode 100644 index 0000000..06504a2 --- /dev/null +++ b/documentation/html/bandcamp/artist_page.html @@ -0,0 +1,125 @@ + + + + + + + + Music | Only Smile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+ + + + +
+ + +
+

about

+ +

+ Only Smile + Russia +

+ + + +
+ +

+ + Contact Only Smile + +

+ + +

+ + Streaming and +
+ Download help +
+

+
+
+
+
+ + diff --git a/src/actual_donwload.py b/src/actual_donwload.py index bc587f6..59e7667 100644 --- a/src/actual_donwload.py +++ b/src/actual_donwload.py @@ -29,7 +29,8 @@ if __name__ == "__main__": ] youtube_music_test = [ - "s: #t Self Loather" + "s: #a Only Smile", + "0" ] music_kraken.cli.download(genre="test", command_list=youtube_music_test, process_metadata_anyway=True) diff --git a/src/music_kraken/pages/bandcamp.py b/src/music_kraken/pages/bandcamp.py index 8c3459b..983053f 100644 --- a/src/music_kraken/pages/bandcamp.py +++ b/src/music_kraken/pages/bandcamp.py @@ -43,6 +43,15 @@ class Bandcamp(Page): super().__init__(*args, **kwargs) def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]: + parsed_url = urlparse(source.url) + + if parsed_url.path == "": + return Artist + if parsed_url.path.startswith("/album/"): + return Album + if parsed_url.path.startswith("/track/"): + return Song + return super().get_source_type(source) def _parse_autocomplete_api_result(self, data: dict) -> DatabaseObject: @@ -135,15 +144,31 @@ class Bandcamp(Page): def song_search(self, song: Song) -> List[Song]: return self.general_search(song.title, filter_string="t") + + def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist: + artist = Artist() + + r = self.connection.get(source.url) + if r is None: + return artist + + soup = self.get_soup_from_response(r) + data_container = soup.find("div", {"id": "pagedata"}) + data = data_container["data-blob"] + + if DEBUG: + dump_to_file("artist_page.html", r.text, exit_after_dump=False) + dump_to_file("bandcamp_artis.json", data, is_json=True, exit_after_dump=False) + + return artist + def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song: + print(source) return Song() def fetch_album(self, source: Source, stop_at_level: int = 1) -> Album: return Album() - def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist: - return Artist() - def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label: return Label()