diff --git a/src/actual_donwload.py b/src/actual_donwload.py index 1a2bcce..bb53da2 100644 --- a/src/actual_donwload.py +++ b/src/actual_donwload.py @@ -1,14 +1,15 @@ import music_kraken -from music_kraken import pages -from music_kraken.download import Search -from music_kraken.utils.enums.source import SourcePages -from music_kraken.objects import Song, Target, Source, Album if __name__ == "__main__": - music_kraken.cli(genre="test", command_list=[ - # "https://musify.club/release/molchat-doma-etazhi-2018-1092949", - # "https://musify.club/release/ghost-bath-self-loather-2021-1554266", + normally_download = [ "s: #a Ghost Bath", + "1", + "d: 1, 5" + ] - ]) + direct_download = [ + "d: https://musify.club/release/crystal-f-x-2012-795181" + ] + + music_kraken.cli(genre="test", command_list=direct_download) diff --git a/src/music_kraken/cli/download/shell.py b/src/music_kraken/cli/download/shell.py index adb7bfb..1db4e6d 100644 --- a/src/music_kraken/cli/download/shell.py +++ b/src/music_kraken/cli/download/shell.py @@ -178,7 +178,9 @@ class Shell: def print_current_options(self): self.page_dict = dict() - + + print() + page_count = 0 for option in self.current_results.formated_generator(max_items_per_page=self.max_displayed_options): if isinstance(option, Option): @@ -191,7 +193,9 @@ class Shell: self.page_dict[option.__name__] = option page_count += 1 - + + print() + def set_current_options(self, current_options: Results): self.current_results = current_options @@ -216,7 +220,8 @@ class Shell: def search(self, query: str): if re.match(URL_PATTERN, query) is not None: - self.set_current_options(*self.pages.fetch_url(re.match(URL_PATTERN, query))) + page, data_object = self.pages.fetch_url(query) + self.set_current_options(PageResults(page, data_object.options)) self.print_current_options() return @@ -290,7 +295,7 @@ class Shell: to_download: List[DatabaseObject] = [] if re.match(URL_PATTERN, download_str) is not None: - _, music_objects = self.pages.fetch_url(re.match(URL_PATTERN, download_str)) + _, music_objects = self.pages.fetch_url(download_str) to_download.append(music_objects) else: @@ -322,7 +327,7 @@ class Shell: print(music_object.option_string) print(result) - return False + return True def process_input(self, input_str: str) -> bool: input_str = input_str.strip() diff --git a/src/music_kraken/objects/parents.py b/src/music_kraken/objects/parents.py index 20c8303..9185a82 100644 --- a/src/music_kraken/objects/parents.py +++ b/src/music_kraken/objects/parents.py @@ -36,6 +36,11 @@ class DatabaseObject: self.build_version = -1 + def __hash__(self): + if self.dynamic: + raise TypeError("Dynamic DatabaseObjects are unhashable.") + return self.id + def __eq__(self, other) -> bool: if not isinstance(other, type(self)): return False diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index d2c72b5..cbeb46a 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -104,7 +104,7 @@ def merge_together(old_object: DatabaseObject, new_object: DatabaseObject) -> Da return old_object -class Page(): +class Page: """ This is an abstract class, laying out the functionality for every other class fetching something @@ -270,7 +270,7 @@ class Page(): for collection_name in naming_music_object.UPWARDS_COLLECTION_ATTRIBUTES: collection: Collection = getattr(naming_music_object, collection_name) - if collection.empty(): + if collection.empty: continue if collection.element_type in naming_objects: continue @@ -280,10 +280,10 @@ class Page(): fill_naming_objects(music_object) - return self._download(music_object, {}, genre, download_all) + return self._download(music_object, naming_objects, download_all) - def _download(self, music_object: DatabaseObject, naming_objects: Dict[Type[DatabaseObject], DatabaseObject], download_all: bool = False) -> list: + def _download(self, music_object: DatabaseObject, naming_objects: Dict[Union[Type[DatabaseObject], str], DatabaseObject], download_all: bool = False) -> DownloadResult: # Skips all releases, that are defined in shared.ALBUM_TYPE_BLACKLIST, if download_all is False if isinstance(music_object, Album): if not download_all and music_object.album_type in shared.ALBUM_TYPE_BLACKLIST: @@ -298,7 +298,7 @@ class Page(): download_result: DownloadResult = DownloadResult() for collection_name in music_object.DOWNWARDS_COLLECTION_ATTRIBUTES: - collection: Collection = getattr(self, collection_name) + collection: Collection = getattr(music_object, collection_name) sub_ordered_music_object: DatabaseObject for sub_ordered_music_object in collection: @@ -306,11 +306,12 @@ class Page(): return download_result - def _download_song(self, song: Song, naming_objects: Dict[Type[DatabaseObject], DatabaseObject]): + def _download_song(self, song: Song, naming_objects: Dict[Type[DatabaseObject], Union[DatabaseObject, str]]): name_attribute = DEFAULT_VALUES.copy() # song - name_attribute["genre"] = naming_objects["genre"] + if "genre" in naming_objects: + name_attribute["genre"] = naming_objects["genre"] name_attribute["song"] = song.title if Album in naming_objects: @@ -344,7 +345,7 @@ class Page(): file=str(random.randint(0, 999999)) ) - r = self._download_song_to_targets(source=sources[0], target=temp_target, desc=song.title) + r = self.download_song_to_target(source=sources[0], target=temp_target, desc=song.title) if not r.is_fatal_error: r.merge(self._post_process_targets(song, temp_target)) diff --git a/src/music_kraken/pages/musify.py b/src/music_kraken/pages/musify.py index 34c9fe6..46c8429 100644 --- a/src/music_kraken/pages/musify.py +++ b/src/music_kraken/pages/musify.py @@ -164,7 +164,6 @@ class Musify(Page): artist_thumbnail = image_soup.get("src") return Artist( - _id=_id, name=name, source_list=source_list ) @@ -269,7 +268,6 @@ class Musify(Page): self.LOGGER.warning("got an unequal ammount than 3 small elements") return Album( - _id=_id, title=title, source_list=source_list, date=ID3Timestamp(year=year), @@ -316,7 +314,6 @@ class Musify(Page): _id = href.split("-")[-1] artist_list.append(Artist( - _id=_id, name=artist_anchor.get_text(strip=True), source_list=[artist_source] )) @@ -352,7 +349,6 @@ class Musify(Page): _id = raw_id return Song( - _id=_id, title=song_title, main_artist_list=artist_list, source_list=source_list @@ -838,7 +834,6 @@ class Musify(Page): self.LOGGER.debug("there is not even 1 footer in the album card") return Album( - _id=_id, title=name, source_list=source_list, date=timestamp, @@ -998,7 +993,7 @@ class Musify(Page): def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label: return Label() - def download_song_to_targets(self, source: Source, target: Target, desc: str = None) -> DownloadResult: + def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult: """ 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