continued download
This commit is contained in:
parent
4cf902b05b
commit
7743ff1b9e
57
documentation/shell.md
Normal file
57
documentation/shell.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Shell
|
||||||
|
|
||||||
|
## Searching
|
||||||
|
|
||||||
|
```mkshell
|
||||||
|
> s: {querry or url}
|
||||||
|
|
||||||
|
# examples
|
||||||
|
> s: https://musify.club/release/some-random-release-183028492
|
||||||
|
> s: r: #a an Artist #r some random Release
|
||||||
|
```
|
||||||
|
|
||||||
|
Searches for an url, or an query
|
||||||
|
|
||||||
|
### Query Syntax
|
||||||
|
|
||||||
|
```
|
||||||
|
#a {artist} #r {release} #t {track}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can escape stuff like `#` doing this: `\#`
|
||||||
|
|
||||||
|
## Downloading
|
||||||
|
|
||||||
|
To download something, you either need a direct link, or you need to have already searched for options
|
||||||
|
|
||||||
|
```mkshell
|
||||||
|
> d: {option ids or direct url}
|
||||||
|
|
||||||
|
# examples
|
||||||
|
> d: 0, 3, 4
|
||||||
|
> d: 1
|
||||||
|
> d: https://musify.club/release/some-random-release-183028492
|
||||||
|
```
|
||||||
|
|
||||||
|
## Misc
|
||||||
|
|
||||||
|
### Exit
|
||||||
|
|
||||||
|
```mkshell
|
||||||
|
> q
|
||||||
|
> quit
|
||||||
|
> exit
|
||||||
|
> abort
|
||||||
|
```
|
||||||
|
|
||||||
|
### Current Options
|
||||||
|
|
||||||
|
```mkshell
|
||||||
|
> .
|
||||||
|
```
|
||||||
|
|
||||||
|
### Previous Options
|
||||||
|
|
||||||
|
```
|
||||||
|
> ..
|
||||||
|
```
|
@ -5,7 +5,7 @@ import re
|
|||||||
from ...utils.shared import MUSIC_DIR, NOT_A_GENRE_REGEX
|
from ...utils.shared import MUSIC_DIR, NOT_A_GENRE_REGEX
|
||||||
from ...utils.regex import URL_PATTERN
|
from ...utils.regex import URL_PATTERN
|
||||||
from ...utils.string_processing import fit_to_file_system
|
from ...utils.string_processing import fit_to_file_system
|
||||||
from ...utils.support_classes import Query
|
from ...utils.support_classes import Query, DownloadResult
|
||||||
from ...download.results import Results, SearchResults, Option, PageResults
|
from ...download.results import Results, SearchResults, Option, PageResults
|
||||||
from ...download.page_attributes import Pages
|
from ...download.page_attributes import Pages
|
||||||
from ...pages import Page
|
from ...pages import Page
|
||||||
@ -211,8 +211,15 @@ class Shell:
|
|||||||
|
|
||||||
if artist is not None:
|
if artist is not None:
|
||||||
return Query(raw_query=query, music_object=artist)
|
return Query(raw_query=query, music_object=artist)
|
||||||
|
|
||||||
|
return Query(raw_query=query)
|
||||||
|
|
||||||
def search(self, query: str):
|
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)))
|
||||||
|
self.print_current_options()
|
||||||
|
return
|
||||||
|
|
||||||
special_characters = "#\\"
|
special_characters = "#\\"
|
||||||
query = query + " "
|
query = query + " "
|
||||||
|
|
||||||
@ -266,7 +273,7 @@ class Shell:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
page, music_object = self.current_results.get_music_object_by_index(index)
|
page, music_object = self.current_results.get_music_object_by_index(index)
|
||||||
except IndexError:
|
except KeyError:
|
||||||
print()
|
print()
|
||||||
print(f"The option {index} doesn't exist.")
|
print(f"The option {index} doesn't exist.")
|
||||||
print()
|
print()
|
||||||
@ -280,6 +287,41 @@ class Shell:
|
|||||||
|
|
||||||
|
|
||||||
def download(self, download_str: str, download_all: bool = False) -> bool:
|
def download(self, download_str: str, download_all: bool = False) -> bool:
|
||||||
|
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))
|
||||||
|
to_download.append(music_objects)
|
||||||
|
|
||||||
|
else:
|
||||||
|
index: str
|
||||||
|
for index in download_str.split(", "):
|
||||||
|
if not index.strip().isdigit():
|
||||||
|
print()
|
||||||
|
print(f"Every download thingie has to be an index, not {index}.")
|
||||||
|
print()
|
||||||
|
return False
|
||||||
|
|
||||||
|
for index in download_str.split(", "):
|
||||||
|
to_download.append(self.current_results.get_music_object_by_index(int(index))[1])
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("Downloading:")
|
||||||
|
for download_object in to_download:
|
||||||
|
print(download_object.option_string)
|
||||||
|
print()
|
||||||
|
|
||||||
|
_result_map: Dict[DatabaseObject, DownloadResult] = dict()
|
||||||
|
|
||||||
|
for database_object in to_download:
|
||||||
|
r = self.pages.download(music_object=database_object, genre=self.genre, download_all=download_all)
|
||||||
|
_result_map[database_object] = r
|
||||||
|
|
||||||
|
for music_object, result in _result_map.items():
|
||||||
|
print()
|
||||||
|
print(music_object.option_string)
|
||||||
|
print(result)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def process_input(self, input_str: str) -> bool:
|
def process_input(self, input_str: str) -> bool:
|
||||||
|
@ -131,6 +131,7 @@ class Connection:
|
|||||||
accepted_response_code=accepted_response_code,
|
accepted_response_code=accepted_response_code,
|
||||||
url=url,
|
url=url,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
headers=headers,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,11 +80,11 @@ class Pages:
|
|||||||
audio_pages = self._audio_pages_set.intersection(_page_types)
|
audio_pages = self._audio_pages_set.intersection(_page_types)
|
||||||
|
|
||||||
for download_page in audio_pages:
|
for download_page in audio_pages:
|
||||||
return self._page_instances[download_page].download(genre=genre, download_all=download_all)
|
return self._page_instances[download_page].download(music_object=music_object, genre=genre, download_all=download_all)
|
||||||
|
|
||||||
return DownloadResult(error_message=f"No audio source has been found for {music_object}.")
|
return DownloadResult(error_message=f"No audio source has been found for {music_object}.")
|
||||||
|
|
||||||
def fetch_url(self, url: str, stop_at_level: int = 2) -> DatabaseObject:
|
def fetch_url(self, url: str, stop_at_level: int = 2) -> Tuple[Type[Page], DatabaseObject]:
|
||||||
source = Source.match_url(url, SourcePages.MANUAL)
|
source = Source.match_url(url, SourcePages.MANUAL)
|
||||||
|
|
||||||
if source is None:
|
if source is None:
|
||||||
@ -92,5 +92,4 @@ class Pages:
|
|||||||
|
|
||||||
_actual_page = self._source_to_page[source.page_enum]
|
_actual_page = self._source_to_page[source.page_enum]
|
||||||
|
|
||||||
|
return _actual_page, self._page_instances[_actual_page].fetch_object_from_source(source=source, stop_at_level=stop_at_level)
|
||||||
return self._page_instances[_actual_page].fetch_object_from_source(source=source, stop_at_level=stop_at_level)
|
|
@ -268,7 +268,7 @@ class Page():
|
|||||||
nonlocal naming_objects
|
nonlocal naming_objects
|
||||||
|
|
||||||
for collection_name in naming_music_object.UPWARDS_COLLECTION_ATTRIBUTES:
|
for collection_name in naming_music_object.UPWARDS_COLLECTION_ATTRIBUTES:
|
||||||
collection: Collection = getattr(self, collection_name)
|
collection: Collection = getattr(naming_music_object, collection_name)
|
||||||
|
|
||||||
if collection.empty():
|
if collection.empty():
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user