feat: caching of artwork request

This commit is contained in:
Hazel 2024-04-26 15:56:13 +02:00
parent 6226ae4a13
commit 207ca1b6a5
2 changed files with 8 additions and 3 deletions

View File

@ -68,9 +68,11 @@ def write_metadata_to_target(metadata: Metadata, target: Target, song: Song):
LOGGER.info(str(metadata)) LOGGER.info(str(metadata))
if song.artwork.best_variant is not None: if song.artwork.best_variant is not None:
best_variant = song.artwork.best_variant
r = artwork_connection.get( r = artwork_connection.get(
url=song.artwork.best_variant["url"], url=best_variant["url"],
disable_cache=False, name=song.artwork.get_variant_name(best_variant, song.option_string),
) )
temp_target: Target = Target.temp() temp_target: Target = Target.temp()

View File

@ -8,7 +8,7 @@ from .metadata import (
ID3Timestamp, ID3Timestamp,
Metadata Metadata
) )
from ..utils.string_processing import unify, hash_url from ..utils.string_processing import unify, hash_url, hash_url
from .parents import OuterProxy as Base from .parents import OuterProxy as Base
@ -50,6 +50,9 @@ class Artwork:
return None return None
return min(self._variant_mapping.values(), key=lambda x: x["deviation"]) return min(self._variant_mapping.values(), key=lambda x: x["deviation"])
def get_variant_name(self, variant: ArtworkVariant, option_string: str) -> str:
return f"artwork_{variant['width']}x{variant['height']}_{option_string}"
def __merge__(self, other: Artwork, override: bool = False) -> None: def __merge__(self, other: Artwork, override: bool = False) -> None:
for key, value in other._variant_mapping.items(): for key, value in other._variant_mapping.items():
if key not in self._variant_mapping or override: if key not in self._variant_mapping or override: