changed the way stuff is downloaded
This commit is contained in:
parent
f8b3e57ade
commit
5067b84f48
@ -11,6 +11,7 @@ from . import (
|
||||
|
||||
DatabaseObject = parents.DatabaseObject
|
||||
|
||||
Metadata = metadata.Metadata
|
||||
ID3Mapping = metadata.Mapping
|
||||
ID3Timestamp = metadata.ID3Timestamp
|
||||
|
||||
|
@ -17,7 +17,7 @@ from ..objects import (
|
||||
Collection,
|
||||
Label
|
||||
)
|
||||
from ..tagging import write_metadata
|
||||
from ..tagging import write_metadata_to_target
|
||||
|
||||
LOGGER = logging.getLogger("this shouldn't be used")
|
||||
|
||||
@ -330,11 +330,16 @@ class Page:
|
||||
if len(sources) == 0:
|
||||
return
|
||||
|
||||
cls._download_song_to_targets(source=sources[0], target_list=song.target_collection.shallow_list)
|
||||
temp_target = cls._download_song_to_targets(source=sources[0], target_list=song.target_collection.shallow_list)
|
||||
cls._post_process_targets(song, temp_target)
|
||||
|
||||
@classmethod
|
||||
def _post_process_targets(cls, song: Song):
|
||||
write_metadata(song)
|
||||
def _post_process_targets(cls, song: Song, temp_target: Target):
|
||||
write_metadata_to_target(song.metadata, temp_target)
|
||||
|
||||
target: Target
|
||||
for target in song.target_collection:
|
||||
temp_target.copy_content(target)
|
||||
|
||||
|
||||
@classmethod
|
||||
@ -358,6 +363,5 @@ class Page:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _download_song_to_targets(cls, source: Source, target_list: List[Target]):
|
||||
for target in target_list:
|
||||
print(f"downloading {source} to {target}")
|
||||
def _download_song_to_targets(cls, source: Source) -> Target:
|
||||
return Target()
|
||||
|
@ -6,9 +6,12 @@ import pycountry
|
||||
from urllib.parse import urlparse
|
||||
from enum import Enum
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
import random
|
||||
|
||||
from ..utils.shared import (
|
||||
ENCYCLOPAEDIA_METALLUM_LOGGER as LOGGER
|
||||
ENCYCLOPAEDIA_METALLUM_LOGGER as LOGGER,
|
||||
TEMP_FOLDER
|
||||
)
|
||||
|
||||
from .abstract import Page
|
||||
@ -894,8 +897,21 @@ class Musify(Page):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _download_song_to_targets(cls, source: Source, target_list: List[Target]):
|
||||
def _download_song_to_targets(cls, source: Source) -> Path:
|
||||
"""
|
||||
https://musify.club/track/im-in-a-coffin-life-never-was-waste-of-skin-16360302
|
||||
https://musify.club/track/dl/16360302/im-in-a-coffin-life-never-was-waste-of-skin.mp3
|
||||
"""
|
||||
pass
|
||||
url: MusifyUrl = cls.parse_url(source.url)
|
||||
if url.source_type != MusifyTypes.SONG:
|
||||
return
|
||||
|
||||
target: Target = Target(
|
||||
path=TEMP_FOLDER,
|
||||
file=str(random.randint(0, 999999))
|
||||
)
|
||||
|
||||
endpoint = f"https://musify.club/track/dl/{url.musify_id}/{url.name_without_id}.mp3"
|
||||
print(endpoint)
|
||||
|
||||
return target
|
||||
|
@ -1,9 +1,6 @@
|
||||
from .id3 import (
|
||||
AudioMetadata,
|
||||
write_many_metadata,
|
||||
write_metadata
|
||||
)
|
||||
from . import id3
|
||||
|
||||
AudioMetadata = AudioMetadata
|
||||
write_many_metadata = write_many_metadata
|
||||
write_metadata = write_metadata
|
||||
AudioMetadata = id3.AudioMetadata
|
||||
write_many_metadata = id3.write_many_metadata
|
||||
write_metadata = id3.write_metadata
|
||||
write_metadata_to_target = id3.write_metadata_to_target
|
||||
|
@ -7,7 +7,7 @@ import logging
|
||||
from ..utils.shared import (
|
||||
TAGGING_LOGGER as logger
|
||||
)
|
||||
from ..objects import Song, Target
|
||||
from ..objects import Song, Target, Metadata
|
||||
|
||||
|
||||
class AudioMetadata:
|
||||
@ -18,14 +18,18 @@ class AudioMetadata:
|
||||
|
||||
if file_location is not None:
|
||||
self.file_location = file_location
|
||||
|
||||
def add_song_metadata(self, song: Song):
|
||||
for value in song.metadata:
|
||||
|
||||
def add_metadata(self, metadata: Metadata):
|
||||
for value in metadata:
|
||||
"""
|
||||
https://www.programcreek.com/python/example/84797/mutagen.id3.ID3
|
||||
"""
|
||||
self.frames.add(value)
|
||||
|
||||
def add_song_metadata(self, song: Song):
|
||||
self.add_metadata(song.metadata)
|
||||
|
||||
|
||||
def save(self, file_location: str = None):
|
||||
print("saving")
|
||||
print(self.frames.pprint())
|
||||
@ -47,6 +51,13 @@ class AudioMetadata:
|
||||
|
||||
file_location = property(fget=lambda self: self._file_location, fset=set_file_location)
|
||||
|
||||
def write_metadata_to_target(metadata: Metadata, target: Target):
|
||||
if not target.exists:
|
||||
return
|
||||
|
||||
id3_object = AudioMetadata(file_location=target.file_path)
|
||||
id3_object.add_metadata(metadata)
|
||||
id3_object.save()
|
||||
|
||||
def write_metadata(song: Song, ignore_file_not_found: bool = True):
|
||||
target: Target
|
||||
|
Loading…
Reference in New Issue
Block a user