start laying out downloads

This commit is contained in:
Hellow2 2023-03-30 14:39:28 +02:00
parent 1a9ec937f6
commit b2e67fbd45
4 changed files with 42 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import music_kraken import music_kraken
from music_kraken import pages from music_kraken import pages
from music_kraken.objects import Song, Target, Source, SourcePages
def search_pages(): def search_pages():
@ -27,6 +28,19 @@ def direct_download():
search.search_url("https://musify.club/artist/ghost-bath-280348") search.search_url("https://musify.club/artist/ghost-bath-280348")
print(search) print(search)
def download_audio():
song = Song(
source_list=[
Source(SourcePages.MUSIFY, "https://musify.club/track/im-in-a-coffin-life-never-was-waste-of-skin-16360302")
],
target_list=[
Target(relative_to_music_dir=True, path="example", file="waste_of_skin_1"),
Target(relative_to_music_dir=True, path="example", file="waste_of_skin_2")
]
)
pages.Musify.download_song(song)
if __name__ == "__main__": if __name__ == "__main__":
music_kraken.cli() download_audio()

View File

@ -148,3 +148,7 @@ class Collection:
returns a shallow copy of the data list returns a shallow copy of the data list
""" """
return self._data.copy() return self._data.copy()
@property
def empty(self) -> bool:
return len(self._data) == 0

View File

@ -25,16 +25,18 @@ class Target(DatabaseObject):
self, self,
file: str = None, file: str = None,
path: str = None, path: str = None,
_id: str = None,
dynamic: bool = False, dynamic: bool = False,
relative_to_music_dir: bool = False relative_to_music_dir: bool = False
) -> None: ) -> None:
super().__init__(_id=_id, dynamic=dynamic) super().__init__(dynamic=dynamic)
self._file: Path = Path(file) self._file: Path = Path(file)
self._path: Path = Path(path) if relative_to_music_dir else Path(path) self._path: Path = Path(shared.MUSIC_DIR, path) if relative_to_music_dir else Path(path)
self.is_relative_to_music_dir: bool = relative_to_music_dir self.is_relative_to_music_dir: bool = relative_to_music_dir
def __repr__(self) -> str:
return str(self.file_path)
@property @property
def file_path(self) -> Path: def file_path(self) -> Path:
return Path(self._path, self._file) return Path(self._path, self._file)

View File

@ -1,4 +1,4 @@
from typing import Optional, Union, Type, Dict from typing import Optional, Union, Type, Dict, List
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import requests import requests
import logging import logging
@ -274,6 +274,18 @@ class Page:
cls._clean_collection(song.feature_artist_collection, collections) cls._clean_collection(song.feature_artist_collection, collections)
cls._clean_collection(song.main_artist_collection, collections) cls._clean_collection(song.main_artist_collection, collections)
@classmethod
def download_song(cls, song: Song):
if song.target_collection.empty:
return
sources = song.source_collection.get_sources_from_page(cls.SOURCE_TYPE)
if len(sources) == 0:
return
cls._download_song_to_targets(source=sources[0], target_list=song.target_collection.shallow_list)
@classmethod @classmethod
def _fetch_song_from_source(cls, source: Source, stop_at_level: int = 1) -> Song: def _fetch_song_from_source(cls, source: Source, stop_at_level: int = 1) -> Song:
return Song() return Song()
@ -293,3 +305,8 @@ class Page:
@classmethod @classmethod
def _get_type_of_url(cls, url: str) -> Optional[Union[Type[Song], Type[Album], Type[Artist], Type[Label]]]: def _get_type_of_url(cls, url: str) -> Optional[Union[Type[Song], Type[Album], Type[Artist], Type[Label]]]:
return None 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}")