feat: added artwork fetching from musify

This commit is contained in:
Hellow 2024-04-11 20:29:05 +02:00
parent 44d1f0d7db
commit 4ee2914405
3 changed files with 14 additions and 4 deletions

View File

@ -9,7 +9,7 @@ from rich.console import Console
from .utils.shared import DEBUG, DEBUG_LOGGING
from .utils.config import logging_settings, main_settings, read_config
__version__ = "1.14.0"
__version__ = "1.15.0"
read_config()

View File

@ -33,7 +33,10 @@ class Artwork:
def _calculate_deviation(*dimensions: List[int]) -> float:
return sum(abs(d - main_settings["preferred_artwork_resolution"]) for d in dimensions) / len(dimensions)
def append(self, url: str, width: int, height: int, **kwargs) -> None:
def append(self, url: str, width: int = main_settings["preferred_artwork_resolution"], height: int = main_settings["preferred_artwork_resolution"], **kwargs) -> None:
if url is None:
return
self._variant_mapping[hash_url(url=url)] = {
"url": url,
"width": width,

View File

@ -21,7 +21,8 @@ from ..objects import (
Label,
Target,
DatabaseObject,
Lyrics
Lyrics,
Artwork
)
from ..utils.config import logging_settings
from ..utils import string_processing, shared
@ -476,7 +477,12 @@ class Musify(Page):
_parse_album_anchor(album_anchor)
track_name = list_points[4].text.strip()
# artwork
artwork: Artwork = Artwork()
album_image_element_list: List[BeautifulSoup] = soup.find_all("img", {"class": "album-img"})
for album_image_element in album_image_element_list:
artwork.append(url=album_image_element.get("data-src", album_image_element.get("src")))
# lyrics
lyrics_container: List[BeautifulSoup] = soup.find_all("div", {"id": "tabLyrics"})
@ -501,6 +507,7 @@ class Musify(Page):
lyrics_list=lyrics_list,
main_artist_list=artist_list,
album_list=album_list,
artwork=artwork,
)
def _parse_song_card(self, song_card: BeautifulSoup) -> Song: