From c3db4df70bee9f79d090a340294b45b71cb45c5b Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Thu, 9 Feb 2023 15:05:49 +0100 Subject: [PATCH] rough implementation of start of cli --- src/music_kraken/__init__.py | 3 +-- .../pages/encyclopaedia_metallum.py | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index eeaebec..4e405e1 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -59,7 +59,6 @@ def get_options_from_query(query: str) -> List[MusicObject]: return options def get_options_from_option(option: MusicObject) -> List[MusicObject]: - print("fetching", option) for MetadataPage in pages.MetadataPages: option = MetadataPage.fetch_details(option, flat=False) return option.get_options() @@ -71,7 +70,7 @@ def cli(): options = [] while True: - command: str = input(">> ") + command: str = input(">> ").strip() if command.isdigit(): option_index = int(command) diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index 357a999..7387d95 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -275,6 +275,9 @@ class EncyclopaediaMetallum(Page): soup = BeautifulSoup(r.text, 'html.parser') + if soup.find("span",{"id": "noLinks"}) is not None: + return artist + artist_source = soup.find("div", {"id": "band_links_Official"}) """ TODO @@ -333,6 +336,8 @@ class EncyclopaediaMetallum(Page): """ if "Formed in:" == title_text: + if not data.text.isnumeric(): + continue formed_in_year = int(data.text) artist.formed_in = ID3Timestamp(year=formed_in_year) continue @@ -346,7 +351,10 @@ class EncyclopaediaMetallum(Page): continue if "Current label:" == title_text: label_name = data.text - label_url = data.find("a").get("href") + label_anchor = data.find("a") + label_url = None + if label_anchor is not None: + label_url = label_anchor.get("href") for album in artist.main_albums: if album.label is not None: @@ -448,16 +456,20 @@ class EncyclopaediaMetallum(Page): track_id = track_sort_soup.find("a").get("name") title = row_list[1].text.strip() + + length = None duration_stamp = row_list[2].text - minutes, seconds = duration_stamp.split(":") - length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds + if ":" in duration_stamp: + minutes, seconds = duration_stamp.split(":") + length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds track: Song = album.tracklist.get_object_with_source(track_id) or album.tracklist.get_object_with_attribute("title", title) if track is not None: track.add_source(Source(cls.SOURCE_TYPE, track_id)) - track.length = length + if length is not None: + track.length = length track.tracksort = track_sort continue @@ -472,7 +484,6 @@ class EncyclopaediaMetallum(Page): ] ) - print(track) album.tracklist.append(track) return album