feat: implemented fetching of artworks on compile
This commit is contained in:
@@ -2,8 +2,10 @@ from __future__ import annotations
|
||||
|
||||
from copy import copy
|
||||
from dataclasses import dataclass, field
|
||||
from functools import cached_property
|
||||
from typing import Dict, List, Optional, Set, Tuple, Type, TypedDict, Union
|
||||
|
||||
from ..connection import Connection
|
||||
from ..utils import create_dataclass_instance, custom_hash
|
||||
from ..utils.config import main_settings
|
||||
from ..utils.enums import PictureType
|
||||
@@ -13,6 +15,9 @@ from .metadata import ID3Timestamp
|
||||
from .metadata import Mapping as id3Mapping
|
||||
from .metadata import Metadata
|
||||
from .parents import OuterProxy as Base
|
||||
from .target import Target
|
||||
|
||||
artwork_connection: Connection = Connection(module="artwork")
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -39,6 +44,19 @@ class ArtworkVariant:
|
||||
if getattr(self, key) is None:
|
||||
setattr(self, key, value)
|
||||
|
||||
@cached_property
|
||||
def target(self) -> Target:
|
||||
return Target.temp()
|
||||
|
||||
def fetch(self) -> None:
|
||||
global artwork_connection
|
||||
|
||||
r = artwork_connection.get(self.url, name=hash_url(url))
|
||||
if r is None:
|
||||
return
|
||||
|
||||
self.target.raw_content = r.content
|
||||
|
||||
@dataclass
|
||||
class Artwork:
|
||||
variants: List[ArtworkVariant] = field(default_factory=list)
|
||||
@@ -73,6 +91,10 @@ class Artwork:
|
||||
return None
|
||||
return self.variants[0].url
|
||||
|
||||
def fetch(self) -> None:
|
||||
for variant in self.variants:
|
||||
variant.fetch()
|
||||
|
||||
|
||||
class ArtworkCollection:
|
||||
"""
|
||||
@@ -149,12 +171,8 @@ class ArtworkCollection:
|
||||
"""
|
||||
This will make the artworks ready for download
|
||||
"""
|
||||
from ..connection import Connection
|
||||
|
||||
for artwork in self._data:
|
||||
for variants in artwork.variants:
|
||||
pass
|
||||
pass
|
||||
artwork.fetch()
|
||||
|
||||
def __merge__(self, other: ArtworkCollection, **kwargs) -> None:
|
||||
self.parent_artworks.update(other.parent_artworks)
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import List, Tuple, TextIO, Union, Optional
|
||||
import logging
|
||||
import random
|
||||
from pathlib import Path
|
||||
from typing import List, Optional, TextIO, Tuple, Union
|
||||
|
||||
import requests
|
||||
from tqdm import tqdm
|
||||
|
||||
from .parents import OuterProxy
|
||||
from ..utils.config import logging_settings, main_settings
|
||||
from ..utils.shared import HIGHEST_ID
|
||||
from ..utils.config import main_settings, logging_settings
|
||||
from ..utils.string_processing import fit_to_file_system
|
||||
|
||||
from .parents import OuterProxy
|
||||
|
||||
LOGGER = logging.getLogger("target")
|
||||
|
||||
@@ -117,3 +117,11 @@ class Target(OuterProxy):
|
||||
|
||||
def read_bytes(self) -> bytes:
|
||||
return self.file_path.read_bytes()
|
||||
|
||||
@property
|
||||
def raw_content(self) -> bytes:
|
||||
return self.file_path.read_bytes()
|
||||
|
||||
@raw_content.setter
|
||||
def raw_content(self, content: bytes):
|
||||
self.file_path.write_bytes(content)
|
||||
|
||||
Reference in New Issue
Block a user