continued download

This commit is contained in:
Hellow2 2023-06-12 17:40:54 +02:00
parent 4cf902b05b
commit 7743ff1b9e
5 changed files with 106 additions and 7 deletions

57
documentation/shell.md Normal file
View 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
```
> ..
```

View File

@ -5,7 +5,7 @@ import re
from ...utils.shared import MUSIC_DIR, NOT_A_GENRE_REGEX
from ...utils.regex import URL_PATTERN
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.page_attributes import Pages
from ...pages import Page
@ -212,7 +212,14 @@ class Shell:
if artist is not None:
return Query(raw_query=query, music_object=artist)
return Query(raw_query=query)
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 = "#\\"
query = query + " "
@ -266,7 +273,7 @@ class Shell:
try:
page, music_object = self.current_results.get_music_object_by_index(index)
except IndexError:
except KeyError:
print()
print(f"The option {index} doesn't exist.")
print()
@ -280,6 +287,41 @@ class Shell:
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
def process_input(self, input_str: str) -> bool:

View File

@ -131,6 +131,7 @@ class Connection:
accepted_response_code=accepted_response_code,
url=url,
timeout=timeout,
headers=headers,
**kwargs
)

View File

@ -80,11 +80,11 @@ class Pages:
audio_pages = self._audio_pages_set.intersection(_page_types)
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}.")
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)
if source is None:
@ -92,5 +92,4 @@ class Pages:
_actual_page = self._source_to_page[source.page_enum]
return self._page_instances[_actual_page].fetch_object_from_source(source=source, stop_at_level=stop_at_level)
return _actual_page, self._page_instances[_actual_page].fetch_object_from_source(source=source, stop_at_level=stop_at_level)

View File

@ -268,7 +268,7 @@ class Page():
nonlocal naming_objects
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():
continue