feat: musify ArtworkCollection simple function
This commit is contained in:
@@ -36,8 +36,6 @@ from ..connection import Connection
|
||||
|
||||
from ..pages import Page, EncyclopaediaMetallum, Musify, YouTube, YoutubeMusic, Bandcamp, Genius, INDEPENDENT_DB_OBJECTS
|
||||
|
||||
artwork_connection: Connection = Connection()
|
||||
|
||||
ALL_PAGES: Set[Type[Page]] = {
|
||||
# EncyclopaediaMetallum,
|
||||
Genius,
|
||||
@@ -167,43 +165,6 @@ class Pages:
|
||||
|
||||
return False
|
||||
|
||||
def download_artwork_variant_to_target(self, artwork_variant: ArtworkVariant, target: Target):
|
||||
|
||||
r = artwork_connection.get(
|
||||
url=artwork_variant["url"],
|
||||
name=artwork_variant["url"],
|
||||
)
|
||||
|
||||
|
||||
temp_target: Target = Target.temp()
|
||||
with temp_target.open("wb") as f:
|
||||
f.write(r.content)
|
||||
|
||||
converted_target: Target = Target.temp(file_extension=main_settings["image_format"])
|
||||
with Image.open(temp_target.file_path) as img:
|
||||
# crop the image if it isn't square in the middle with minimum data loss
|
||||
width, height = img.size
|
||||
if width != height:
|
||||
if width > height:
|
||||
img = img.crop((width // 2 - height // 2, 0, width // 2 + height // 2, height))
|
||||
else:
|
||||
img = img.crop((0, height // 2 - width // 2, width, height // 2 + width // 2))
|
||||
|
||||
# resize the image to the preferred resolution
|
||||
img.thumbnail((main_settings["preferred_artwork_resolution"], main_settings["preferred_artwork_resolution"]))
|
||||
|
||||
# https://stackoverflow.com/a/59476938/16804841
|
||||
if img.mode != 'RGB':
|
||||
img = img.convert('RGB')
|
||||
|
||||
img.save(target.file_path, main_settings["image_format"])
|
||||
|
||||
def remove_artwork_duplicates(self) -> None:
|
||||
"""
|
||||
This will eliminate duplicates within the given threshold
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
def _fetch_artist_artwork(self, artist: Artist, naming: dict):
|
||||
naming: Dict[str, List[str]] = defaultdict(list, naming)
|
||||
@@ -214,17 +175,17 @@ class Pages:
|
||||
# https://stackoverflow.com/a/17016257
|
||||
naming[key] = list(dict.fromkeys(value))
|
||||
|
||||
artwork: Artwork = artist.artwork
|
||||
artwork: ArtworkCollection = artist.artwork
|
||||
for image_number, variant in enumerate(artwork):
|
||||
naming["image_number"] = [str(image_number)]
|
||||
|
||||
url: str = variant["url"]
|
||||
url: str = variant.url
|
||||
|
||||
target = Target(
|
||||
relative_to_music_dir=True,
|
||||
file_path=Path(self._parse_path_template(main_settings["artist_artwork_path"], naming=naming))
|
||||
)
|
||||
self.download_artwork_variant_to_target(variant, target)
|
||||
artwork.compile(target)
|
||||
|
||||
def download(self, data_object: DataObject, genre: str, **kwargs) -> DownloadResult:
|
||||
# fetch the given object
|
||||
|
Reference in New Issue
Block a user