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",
|
mime="image/jpeg",
|
||||||
type=3,
|
type=3,
|
||||||
desc=u"Cover",
|
desc=u"Cover",
|
||||||
data=converted_target.read_bytes(),
|
data=converted_target.raw_content,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
id3_object.frames.delall("USLT")
|
id3_object.frames.delall("USLT")
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from typing import List, Dict, Optional, Set
|
from typing import TYPE_CHECKING, Dict, List, Optional, Set
|
||||||
from urllib.parse import urlparse, urlunsplit, ParseResult
|
from urllib.parse import ParseResult, urlparse, urlunsplit
|
||||||
import copy
|
|
||||||
import inspect
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import responses
|
import responses
|
||||||
@ -14,12 +14,15 @@ from tqdm import tqdm
|
|||||||
|
|
||||||
from .cache import Cache
|
from .cache import Cache
|
||||||
from .rotating import RotatingProxy
|
from .rotating import RotatingProxy
|
||||||
from ..objects import Target
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from ..objects import Target
|
||||||
|
|
||||||
from ..utils import request_trace
|
from ..utils import request_trace
|
||||||
from ..utils.string_processing import shorten_display_url
|
|
||||||
from ..utils.config import main_settings
|
from ..utils.config import main_settings
|
||||||
from ..utils.support_classes.download_result import DownloadResult
|
|
||||||
from ..utils.hacking import merge_args
|
from ..utils.hacking import merge_args
|
||||||
|
from ..utils.string_processing import shorten_display_url
|
||||||
|
from ..utils.support_classes.download_result import DownloadResult
|
||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
|
@ -2,8 +2,10 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from functools import cached_property
|
||||||
from typing import Dict, List, Optional, Set, Tuple, Type, TypedDict, Union
|
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 import create_dataclass_instance, custom_hash
|
||||||
from ..utils.config import main_settings
|
from ..utils.config import main_settings
|
||||||
from ..utils.enums import PictureType
|
from ..utils.enums import PictureType
|
||||||
@ -13,6 +15,9 @@ from .metadata import ID3Timestamp
|
|||||||
from .metadata import Mapping as id3Mapping
|
from .metadata import Mapping as id3Mapping
|
||||||
from .metadata import Metadata
|
from .metadata import Metadata
|
||||||
from .parents import OuterProxy as Base
|
from .parents import OuterProxy as Base
|
||||||
|
from .target import Target
|
||||||
|
|
||||||
|
artwork_connection: Connection = Connection(module="artwork")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -39,6 +44,19 @@ class ArtworkVariant:
|
|||||||
if getattr(self, key) is None:
|
if getattr(self, key) is None:
|
||||||
setattr(self, key, value)
|
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
|
@dataclass
|
||||||
class Artwork:
|
class Artwork:
|
||||||
variants: List[ArtworkVariant] = field(default_factory=list)
|
variants: List[ArtworkVariant] = field(default_factory=list)
|
||||||
@ -73,6 +91,10 @@ class Artwork:
|
|||||||
return None
|
return None
|
||||||
return self.variants[0].url
|
return self.variants[0].url
|
||||||
|
|
||||||
|
def fetch(self) -> None:
|
||||||
|
for variant in self.variants:
|
||||||
|
variant.fetch()
|
||||||
|
|
||||||
|
|
||||||
class ArtworkCollection:
|
class ArtworkCollection:
|
||||||
"""
|
"""
|
||||||
@ -149,12 +171,8 @@ class ArtworkCollection:
|
|||||||
"""
|
"""
|
||||||
This will make the artworks ready for download
|
This will make the artworks ready for download
|
||||||
"""
|
"""
|
||||||
from ..connection import Connection
|
|
||||||
|
|
||||||
for artwork in self._data:
|
for artwork in self._data:
|
||||||
for variants in artwork.variants:
|
artwork.fetch()
|
||||||
pass
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __merge__(self, other: ArtworkCollection, **kwargs) -> None:
|
def __merge__(self, other: ArtworkCollection, **kwargs) -> None:
|
||||||
self.parent_artworks.update(other.parent_artworks)
|
self.parent_artworks.update(other.parent_artworks)
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Tuple, TextIO, Union, Optional
|
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional, TextIO, Tuple, Union
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from .parents import OuterProxy
|
from ..utils.config import logging_settings, main_settings
|
||||||
from ..utils.shared import HIGHEST_ID
|
from ..utils.shared import HIGHEST_ID
|
||||||
from ..utils.config import main_settings, logging_settings
|
|
||||||
from ..utils.string_processing import fit_to_file_system
|
from ..utils.string_processing import fit_to_file_system
|
||||||
|
from .parents import OuterProxy
|
||||||
|
|
||||||
LOGGER = logging.getLogger("target")
|
LOGGER = logging.getLogger("target")
|
||||||
|
|
||||||
@ -117,3 +117,11 @@ class Target(OuterProxy):
|
|||||||
|
|
||||||
def read_bytes(self) -> bytes:
|
def read_bytes(self) -> bytes:
|
||||||
return self.file_path.read_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