rough implementation of start of cli

This commit is contained in:
Hellow2 2023-02-09 15:05:49 +01:00
parent bf5d0458ca
commit c3db4df70b
2 changed files with 17 additions and 7 deletions

View File

@ -59,7 +59,6 @@ def get_options_from_query(query: str) -> List[MusicObject]:
return options return options
def get_options_from_option(option: MusicObject) -> List[MusicObject]: def get_options_from_option(option: MusicObject) -> List[MusicObject]:
print("fetching", option)
for MetadataPage in pages.MetadataPages: for MetadataPage in pages.MetadataPages:
option = MetadataPage.fetch_details(option, flat=False) option = MetadataPage.fetch_details(option, flat=False)
return option.get_options() return option.get_options()
@ -71,7 +70,7 @@ def cli():
options = [] options = []
while True: while True:
command: str = input(">> ") command: str = input(">> ").strip()
if command.isdigit(): if command.isdigit():
option_index = int(command) option_index = int(command)

View File

@ -275,6 +275,9 @@ class EncyclopaediaMetallum(Page):
soup = BeautifulSoup(r.text, 'html.parser') 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"}) artist_source = soup.find("div", {"id": "band_links_Official"})
""" """
TODO TODO
@ -333,6 +336,8 @@ class EncyclopaediaMetallum(Page):
""" """
if "Formed in:" == title_text: if "Formed in:" == title_text:
if not data.text.isnumeric():
continue
formed_in_year = int(data.text) formed_in_year = int(data.text)
artist.formed_in = ID3Timestamp(year=formed_in_year) artist.formed_in = ID3Timestamp(year=formed_in_year)
continue continue
@ -346,7 +351,10 @@ class EncyclopaediaMetallum(Page):
continue continue
if "Current label:" == title_text: if "Current label:" == title_text:
label_name = data.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: for album in artist.main_albums:
if album.label is not None: if album.label is not None:
@ -448,16 +456,20 @@ class EncyclopaediaMetallum(Page):
track_id = track_sort_soup.find("a").get("name") track_id = track_sort_soup.find("a").get("name")
title = row_list[1].text.strip() title = row_list[1].text.strip()
length = None
duration_stamp = row_list[2].text duration_stamp = row_list[2].text
minutes, seconds = duration_stamp.split(":") if ":" in duration_stamp:
length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds 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) track: Song = album.tracklist.get_object_with_source(track_id) or album.tracklist.get_object_with_attribute("title", title)
if track is not None: if track is not None:
track.add_source(Source(cls.SOURCE_TYPE, track_id)) track.add_source(Source(cls.SOURCE_TYPE, track_id))
track.length = length if length is not None:
track.length = length
track.tracksort = track_sort track.tracksort = track_sort
continue continue
@ -472,7 +484,6 @@ class EncyclopaediaMetallum(Page):
] ]
) )
print(track)
album.tracklist.append(track) album.tracklist.append(track)
return album return album