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