diff --git a/src/actual_donwload.py b/src/actual_donwload.py index 221f778..bd73e57 100644 --- a/src/actual_donwload.py +++ b/src/actual_donwload.py @@ -1,5 +1,6 @@ import music_kraken from music_kraken import pages +from music_kraken.objects import Song, Target, Source, SourcePages def search_pages(): @@ -26,7 +27,20 @@ def direct_download(): search.search_url("https://musify.club/artist/ghost-bath-280348") 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__": - music_kraken.cli() + download_audio() diff --git a/src/music_kraken/objects/collection.py b/src/music_kraken/objects/collection.py index 98134d4..3f30908 100644 --- a/src/music_kraken/objects/collection.py +++ b/src/music_kraken/objects/collection.py @@ -148,3 +148,7 @@ class Collection: returns a shallow copy of the data list """ return self._data.copy() + + @property + def empty(self) -> bool: + return len(self._data) == 0 diff --git a/src/music_kraken/objects/target.py b/src/music_kraken/objects/target.py index 3766eb0..b076e5b 100644 --- a/src/music_kraken/objects/target.py +++ b/src/music_kraken/objects/target.py @@ -25,16 +25,18 @@ class Target(DatabaseObject): self, file: str = None, path: str = None, - _id: str = None, dynamic: bool = False, relative_to_music_dir: bool = False ) -> None: - super().__init__(_id=_id, dynamic=dynamic) + super().__init__(dynamic=dynamic) 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 + def __repr__(self) -> str: + return str(self.file_path) + @property def file_path(self) -> Path: return Path(self._path, self._file) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index 51ce217..fee2603 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -1,4 +1,4 @@ -from typing import Optional, Union, Type, Dict +from typing import Optional, Union, Type, Dict, List from bs4 import BeautifulSoup import requests import logging @@ -274,6 +274,18 @@ class Page: cls._clean_collection(song.feature_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 def _fetch_song_from_source(cls, source: Source, stop_at_level: int = 1) -> Song: return Song() @@ -293,3 +305,8 @@ class Page: @classmethod def _get_type_of_url(cls, url: str) -> Optional[Union[Type[Song], Type[Album], Type[Artist], Type[Label]]]: 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}")