feat: fetched the flat artist details
This commit is contained in:
parent
e4fd9faf12
commit
adfce16d2a
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -27,6 +27,7 @@
|
|||||||
"Gitea",
|
"Gitea",
|
||||||
"iframe",
|
"iframe",
|
||||||
"isrc",
|
"isrc",
|
||||||
|
"itemprop",
|
||||||
"levenshtein",
|
"levenshtein",
|
||||||
"metallum",
|
"metallum",
|
||||||
"MUSICBRAINZ",
|
"MUSICBRAINZ",
|
||||||
|
@ -136,13 +136,13 @@ class Cache:
|
|||||||
)
|
)
|
||||||
self._write_attribute(cache_attribute)
|
self._write_attribute(cache_attribute)
|
||||||
|
|
||||||
cache_path = fit_to_file_system(Path(module_path, name), hidden_ok=True)
|
cache_path = fit_to_file_system(Path(module_path, name.replace("/", "_")), hidden_ok=True)
|
||||||
with cache_path.open("wb") as content_file:
|
with cache_path.open("wb") as content_file:
|
||||||
self.logger.debug(f"writing cache to {cache_path}")
|
self.logger.debug(f"writing cache to {cache_path}")
|
||||||
content_file.write(content)
|
content_file.write(content)
|
||||||
|
|
||||||
def get(self, name: str) -> Optional[CacheResult]:
|
def get(self, name: str) -> Optional[CacheResult]:
|
||||||
path = fit_to_file_system(Path(self._dir, self.module, name), hidden_ok=True)
|
path = fit_to_file_system(Path(self._dir, self.module, name.replace("/", "_")), hidden_ok=True)
|
||||||
|
|
||||||
if not path.is_file():
|
if not path.is_file():
|
||||||
return None
|
return None
|
||||||
@ -165,7 +165,7 @@ class Cache:
|
|||||||
if ca.name == "":
|
if ca.name == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
file = fit_to_file_system(Path(self._dir, ca.module, ca.name), hidden_ok=True)
|
file = fit_to_file_system(Path(self._dir, ca.module, ca.name.replace("/", "_")), hidden_ok=True)
|
||||||
|
|
||||||
if not ca.is_valid:
|
if not ca.is_valid:
|
||||||
self.logger.debug(f"deleting cache {ca.id}")
|
self.logger.debug(f"deleting cache {ca.id}")
|
||||||
|
@ -59,4 +59,6 @@ class Artwork:
|
|||||||
self._variant_mapping[key] = value
|
self._variant_mapping[key] = value
|
||||||
|
|
||||||
def __eq__(self, other: Artwork) -> bool:
|
def __eq__(self, other: Artwork) -> bool:
|
||||||
|
if not isinstance(other, Artwork):
|
||||||
|
return False
|
||||||
return any(a == b for a, b in zip(self._variant_mapping.keys(), other._variant_mapping.keys()))
|
return any(a == b for a, b in zip(self._variant_mapping.keys(), other._variant_mapping.keys()))
|
||||||
|
@ -85,20 +85,38 @@ class Genius(Page):
|
|||||||
self.add_to_artwork(artwork, data.get("header_image_url"))
|
self.add_to_artwork(artwork, data.get("header_image_url"))
|
||||||
self.add_to_artwork(artwork, data.get("image_url"))
|
self.add_to_artwork(artwork, data.get("image_url"))
|
||||||
|
|
||||||
|
additional_sources: List[Source] = []
|
||||||
source: Source = Source(self.SOURCE_TYPE, data.get("url"), additional_data={
|
source: Source = Source(self.SOURCE_TYPE, data.get("url"), additional_data={
|
||||||
"id": data.get("id"),
|
"id": data.get("id"),
|
||||||
"slug": data.get("slug"),
|
"slug": data.get("slug"),
|
||||||
"api_path": data.get("api_path"),
|
"api_path": data.get("api_path"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
notes = FormattedText()
|
||||||
|
description = data.get("description", {})
|
||||||
|
if "html" in description:
|
||||||
|
notes.html = description["html"]
|
||||||
|
elif "markdown" in description:
|
||||||
|
notes.markdown = description["markdown"]
|
||||||
|
elif "description_preview" in data:
|
||||||
|
notes.plain = data["description_preview"]
|
||||||
|
|
||||||
if source.url is None:
|
if source.url is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if object_type == "artist":
|
if object_type == "artist":
|
||||||
|
if data.get("instagram_name") is not None:
|
||||||
|
additional_sources.append(Source(ALL_SOURCE_TYPES.INSTAGRAM, f"https://www.instagram.com/{data['instagram_name']}/"))
|
||||||
|
if data.get("facebook_name") is not None:
|
||||||
|
additional_sources.append(Source(ALL_SOURCE_TYPES.FACEBOOK, f"https://www.facebook.com/{data['facebook_name']}/"))
|
||||||
|
if data.get("twitter_name") is not None:
|
||||||
|
additional_sources.append(Source(ALL_SOURCE_TYPES.TWITTER, f"https://x.com/{data['twitter_name']}/"))
|
||||||
|
|
||||||
return Artist(
|
return Artist(
|
||||||
name=data.get("name"),
|
name=data.get("name"),
|
||||||
source_list=[source],
|
source_list=[source],
|
||||||
artwork=artwork,
|
artwork=artwork,
|
||||||
|
notes=notes,
|
||||||
)
|
)
|
||||||
|
|
||||||
if object_type == "album":
|
if object_type == "album":
|
||||||
@ -165,35 +183,22 @@ class Genius(Page):
|
|||||||
|
|
||||||
def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist:
|
def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist:
|
||||||
artist = Artist()
|
artist = Artist()
|
||||||
|
# https://genius.com/api/artists/24527/albums?page=1
|
||||||
|
|
||||||
r = self.connection.get(_parse_artist_url(source.url), name=f"artist_{urlparse(source.url).scheme}_{urlparse(source.url).netloc}")
|
r = self.connection.get(source.url, name=source.url)
|
||||||
if r is None:
|
if r is None:
|
||||||
return artist
|
return artist
|
||||||
|
|
||||||
soup = self.get_soup_from_response(r)
|
soup = self.get_soup_from_response(r)
|
||||||
|
|
||||||
if DEBUG:
|
# find the content attribute in the meta tag which is contained in the head
|
||||||
dump_to_file("artist_page.html", r.text, exit_after_dump=False)
|
data_container = soup.find("meta", {"itemprop": "page_data"})
|
||||||
|
if data_container is not None:
|
||||||
|
content = data_container["content"]
|
||||||
|
dump_to_file("genius_itemprop_artist.json", content, is_json=True, exit_after_dump=False)
|
||||||
|
data = json.loads(content)
|
||||||
|
|
||||||
artist = self._parse_artist_details(soup=soup.find("div", {"id": "bio-container"}))
|
artist = self.parse_api_object(data.get("artist", {}))
|
||||||
|
|
||||||
html_music_grid = soup.find("ol", {"id": "music-grid"})
|
|
||||||
if html_music_grid is not None:
|
|
||||||
for subsoup in html_music_grid.find_all("li"):
|
|
||||||
artist.album_collection.append(self._parse_album(soup=subsoup, initial_source=source))
|
|
||||||
|
|
||||||
for i, data_blob_soup in enumerate(soup.find_all("div", {"id": ["pagedata", "collectors-data"]})):
|
|
||||||
data_blob = data_blob_soup["data-blob"]
|
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
dump_to_file(f"bandcamp_artist_data_blob_{i}.json", data_blob, is_json=True, exit_after_dump=False)
|
|
||||||
|
|
||||||
if data_blob is not None:
|
|
||||||
artist.album_collection.extend(
|
|
||||||
self._parse_artist_data_blob(json.loads(data_blob), source.url)
|
|
||||||
)
|
|
||||||
|
|
||||||
artist.source_collection.append(source)
|
|
||||||
return artist
|
return artist
|
||||||
|
|
||||||
def _parse_track_element(self, track: dict, artwork: Artwork) -> Optional[Song]:
|
def _parse_track_element(self, track: dict, artwork: Artwork) -> Optional[Song]:
|
||||||
|
Loading…
Reference in New Issue
Block a user