feat: implemented fetching of artworks on compile
This commit is contained in:
parent
b1a306f3f3
commit
274f1bce90
@ -107,7 +107,7 @@ def write_metadata_to_target(metadata: Metadata, target: Target, song: Song):
|
||||
mime="image/jpeg",
|
||||
type=3,
|
||||
desc=u"Cover",
|
||||
data=converted_target.read_bytes(),
|
||||
data=converted_target.raw_content,
|
||||
)
|
||||
)
|
||||
id3_object.frames.delall("USLT")
|
||||
|
@ -1,12 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import inspect
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from typing import List, Dict, Optional, Set
|
||||
from urllib.parse import urlparse, urlunsplit, ParseResult
|
||||
import copy
|
||||
import inspect
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional, Set
|
||||
from urllib.parse import ParseResult, urlparse, urlunsplit
|
||||
|
||||
import requests
|
||||
import responses
|
||||
@ -14,12 +14,15 @@ from tqdm import tqdm
|
||||
|
||||
from .cache import Cache
|
||||
from .rotating import RotatingProxy
|
||||
from ..objects import Target
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..objects import Target
|
||||
|
||||
from ..utils import request_trace
|
||||
from ..utils.string_processing import shorten_display_url
|
||||
from ..utils.config import main_settings
|
||||
from ..utils.support_classes.download_result import DownloadResult
|
||||
from ..utils.hacking import merge_args
|
||||
from ..utils.string_processing import shorten_display_url
|
||||
from ..utils.support_classes.download_result import DownloadResult
|
||||
|
||||
|
||||
class Connection:
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user