completed new cli
This commit is contained in:
parent
308e34a91c
commit
4b4e05239f
@ -1,14 +1,15 @@
|
|||||||
import music_kraken
|
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__":
|
if __name__ == "__main__":
|
||||||
music_kraken.cli(genre="test", command_list=[
|
normally_download = [
|
||||||
# "https://musify.club/release/molchat-doma-etazhi-2018-1092949",
|
|
||||||
# "https://musify.club/release/ghost-bath-self-loather-2021-1554266",
|
|
||||||
"s: #a Ghost Bath",
|
"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)
|
||||||
|
@ -179,6 +179,8 @@ class Shell:
|
|||||||
def print_current_options(self):
|
def print_current_options(self):
|
||||||
self.page_dict = dict()
|
self.page_dict = dict()
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
page_count = 0
|
page_count = 0
|
||||||
for option in self.current_results.formated_generator(max_items_per_page=self.max_displayed_options):
|
for option in self.current_results.formated_generator(max_items_per_page=self.max_displayed_options):
|
||||||
if isinstance(option, Option):
|
if isinstance(option, Option):
|
||||||
@ -192,6 +194,8 @@ class Shell:
|
|||||||
|
|
||||||
page_count += 1
|
page_count += 1
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
def set_current_options(self, current_options: Results):
|
def set_current_options(self, current_options: Results):
|
||||||
self.current_results = current_options
|
self.current_results = current_options
|
||||||
|
|
||||||
@ -216,7 +220,8 @@ class Shell:
|
|||||||
|
|
||||||
def search(self, query: str):
|
def search(self, query: str):
|
||||||
if re.match(URL_PATTERN, query) is not None:
|
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()
|
self.print_current_options()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -290,7 +295,7 @@ class Shell:
|
|||||||
to_download: List[DatabaseObject] = []
|
to_download: List[DatabaseObject] = []
|
||||||
|
|
||||||
if re.match(URL_PATTERN, download_str) is not None:
|
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)
|
to_download.append(music_objects)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -322,7 +327,7 @@ class Shell:
|
|||||||
print(music_object.option_string)
|
print(music_object.option_string)
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
return False
|
return True
|
||||||
|
|
||||||
def process_input(self, input_str: str) -> bool:
|
def process_input(self, input_str: str) -> bool:
|
||||||
input_str = input_str.strip()
|
input_str = input_str.strip()
|
||||||
|
@ -36,6 +36,11 @@ class DatabaseObject:
|
|||||||
|
|
||||||
self.build_version = -1
|
self.build_version = -1
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
if self.dynamic:
|
||||||
|
raise TypeError("Dynamic DatabaseObjects are unhashable.")
|
||||||
|
return self.id
|
||||||
|
|
||||||
def __eq__(self, other) -> bool:
|
def __eq__(self, other) -> bool:
|
||||||
if not isinstance(other, type(self)):
|
if not isinstance(other, type(self)):
|
||||||
return False
|
return False
|
||||||
|
@ -104,7 +104,7 @@ def merge_together(old_object: DatabaseObject, new_object: DatabaseObject) -> Da
|
|||||||
return old_object
|
return old_object
|
||||||
|
|
||||||
|
|
||||||
class Page():
|
class Page:
|
||||||
"""
|
"""
|
||||||
This is an abstract class, laying out the
|
This is an abstract class, laying out the
|
||||||
functionality for every other class fetching something
|
functionality for every other class fetching something
|
||||||
@ -270,7 +270,7 @@ class Page():
|
|||||||
for collection_name in naming_music_object.UPWARDS_COLLECTION_ATTRIBUTES:
|
for collection_name in naming_music_object.UPWARDS_COLLECTION_ATTRIBUTES:
|
||||||
collection: Collection = getattr(naming_music_object, collection_name)
|
collection: Collection = getattr(naming_music_object, collection_name)
|
||||||
|
|
||||||
if collection.empty():
|
if collection.empty:
|
||||||
continue
|
continue
|
||||||
if collection.element_type in naming_objects:
|
if collection.element_type in naming_objects:
|
||||||
continue
|
continue
|
||||||
@ -280,10 +280,10 @@ class Page():
|
|||||||
|
|
||||||
fill_naming_objects(music_object)
|
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
|
# Skips all releases, that are defined in shared.ALBUM_TYPE_BLACKLIST, if download_all is False
|
||||||
if isinstance(music_object, Album):
|
if isinstance(music_object, Album):
|
||||||
if not download_all and music_object.album_type in shared.ALBUM_TYPE_BLACKLIST:
|
if not download_all and music_object.album_type in shared.ALBUM_TYPE_BLACKLIST:
|
||||||
@ -298,7 +298,7 @@ class Page():
|
|||||||
download_result: DownloadResult = DownloadResult()
|
download_result: DownloadResult = DownloadResult()
|
||||||
|
|
||||||
for collection_name in music_object.DOWNWARDS_COLLECTION_ATTRIBUTES:
|
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
|
sub_ordered_music_object: DatabaseObject
|
||||||
for sub_ordered_music_object in collection:
|
for sub_ordered_music_object in collection:
|
||||||
@ -306,10 +306,11 @@ class Page():
|
|||||||
|
|
||||||
return download_result
|
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()
|
name_attribute = DEFAULT_VALUES.copy()
|
||||||
|
|
||||||
# song
|
# song
|
||||||
|
if "genre" in naming_objects:
|
||||||
name_attribute["genre"] = naming_objects["genre"]
|
name_attribute["genre"] = naming_objects["genre"]
|
||||||
name_attribute["song"] = song.title
|
name_attribute["song"] = song.title
|
||||||
|
|
||||||
@ -344,7 +345,7 @@ class Page():
|
|||||||
file=str(random.randint(0, 999999))
|
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:
|
if not r.is_fatal_error:
|
||||||
r.merge(self._post_process_targets(song, temp_target))
|
r.merge(self._post_process_targets(song, temp_target))
|
||||||
|
@ -164,7 +164,6 @@ class Musify(Page):
|
|||||||
artist_thumbnail = image_soup.get("src")
|
artist_thumbnail = image_soup.get("src")
|
||||||
|
|
||||||
return Artist(
|
return Artist(
|
||||||
_id=_id,
|
|
||||||
name=name,
|
name=name,
|
||||||
source_list=source_list
|
source_list=source_list
|
||||||
)
|
)
|
||||||
@ -269,7 +268,6 @@ class Musify(Page):
|
|||||||
self.LOGGER.warning("got an unequal ammount than 3 small elements")
|
self.LOGGER.warning("got an unequal ammount than 3 small elements")
|
||||||
|
|
||||||
return Album(
|
return Album(
|
||||||
_id=_id,
|
|
||||||
title=title,
|
title=title,
|
||||||
source_list=source_list,
|
source_list=source_list,
|
||||||
date=ID3Timestamp(year=year),
|
date=ID3Timestamp(year=year),
|
||||||
@ -316,7 +314,6 @@ class Musify(Page):
|
|||||||
_id = href.split("-")[-1]
|
_id = href.split("-")[-1]
|
||||||
|
|
||||||
artist_list.append(Artist(
|
artist_list.append(Artist(
|
||||||
_id=_id,
|
|
||||||
name=artist_anchor.get_text(strip=True),
|
name=artist_anchor.get_text(strip=True),
|
||||||
source_list=[artist_source]
|
source_list=[artist_source]
|
||||||
))
|
))
|
||||||
@ -352,7 +349,6 @@ class Musify(Page):
|
|||||||
_id = raw_id
|
_id = raw_id
|
||||||
|
|
||||||
return Song(
|
return Song(
|
||||||
_id=_id,
|
|
||||||
title=song_title,
|
title=song_title,
|
||||||
main_artist_list=artist_list,
|
main_artist_list=artist_list,
|
||||||
source_list=source_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")
|
self.LOGGER.debug("there is not even 1 footer in the album card")
|
||||||
|
|
||||||
return Album(
|
return Album(
|
||||||
_id=_id,
|
|
||||||
title=name,
|
title=name,
|
||||||
source_list=source_list,
|
source_list=source_list,
|
||||||
date=timestamp,
|
date=timestamp,
|
||||||
@ -998,7 +993,7 @@ class Musify(Page):
|
|||||||
def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label:
|
def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label:
|
||||||
return 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/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
|
https://musify.club/track/dl/16360302/im-in-a-coffin-life-never-was-waste-of-skin.mp3
|
||||||
|
Loading…
Reference in New Issue
Block a user