|
|
@@ -2,6 +2,7 @@ import sites as sites
|
|
|
from helper.settings import Settings
|
|
|
from helper import console as console
|
|
|
import os.path
|
|
|
+import command
|
|
|
|
|
|
|
|
|
def main():
|
|
|
@@ -28,136 +29,23 @@ def main():
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
-def choose_site():
|
|
|
- global selected_site
|
|
|
- _index = console.option_picker('Available sites',
|
|
|
- list(map(lambda x: x.url, sites.available)),
|
|
|
- selected_site,
|
|
|
- True)
|
|
|
- if _index is not None:
|
|
|
- selected_site = _index
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
def idle():
|
|
|
_command = console.ask_input('Type command')
|
|
|
|
|
|
- for command in commands:
|
|
|
- if command[0] == _command.lower():
|
|
|
- return command[1]()
|
|
|
+ for comm in command.commands:
|
|
|
+ if comm[0] == _command.lower():
|
|
|
+ return comm[1]()
|
|
|
|
|
|
console.output('Command \'{0}\' not found. Type help to see a list of possible commands'.format(_command))
|
|
|
return True
|
|
|
|
|
|
|
|
|
-def help():
|
|
|
- console.output('Possible commands are:')
|
|
|
- for command in commands:
|
|
|
- console.output('{0}\t{1}'.format(command[0], command[2]))
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
-def search(cache=None):
|
|
|
- if cache is None:
|
|
|
- keywords = console.ask_input('Search for')
|
|
|
- _sites = []
|
|
|
- if isinstance(sites.available[selected_site], sites.DefaultSite):
|
|
|
- _sites = sites.available[1:]
|
|
|
- else:
|
|
|
- _sites = [sites.available[selected_site]]
|
|
|
-
|
|
|
- items = []
|
|
|
- for site in _sites:
|
|
|
- console.output('Searching: {0}'.format(site.url))
|
|
|
- _items = site.perform_search(keywords)
|
|
|
- console.output('\tFound {0} results'.format(len(_items)))
|
|
|
- items.extend(_items)
|
|
|
-
|
|
|
- if len(items) == 0:
|
|
|
- console.output('No results found')
|
|
|
- return True
|
|
|
-
|
|
|
- last(items)
|
|
|
- else:
|
|
|
- items = cache
|
|
|
-
|
|
|
- while True:
|
|
|
- picked_item = console.option_picker('Pick a song to download',
|
|
|
- items,
|
|
|
- # list(map(lambda x: '[{0:5}] [{1:4}] {2}'.format(x.duration, x.size, x.title), items)),
|
|
|
- quit=True,
|
|
|
- objects=[
|
|
|
- '__id__',
|
|
|
- 'x.duration',
|
|
|
- 'x.size',
|
|
|
- 'x.artist',
|
|
|
- 'x.title'
|
|
|
- ],
|
|
|
- table=[
|
|
|
- ('ID', 2),
|
|
|
- ('Time', 5),
|
|
|
- ('Size', 4),
|
|
|
- ('Artist', 50),
|
|
|
- ('Title', 100)
|
|
|
- ])
|
|
|
- if picked_item is None:
|
|
|
- break
|
|
|
- else:
|
|
|
- item = items[picked_item]
|
|
|
- console.output('Downloading {0}'.format(item.title))
|
|
|
-
|
|
|
- item.site.download(item)
|
|
|
-
|
|
|
- break
|
|
|
-
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
-def directory(dir=None):
|
|
|
- if dir is None:
|
|
|
- dir = console.ask_input('Enter new save directory')
|
|
|
- Settings.SaveDir.set(dir)
|
|
|
- os.makedirs(Settings.SaveDir.get(), exist_ok=True)
|
|
|
- console.output('New save directory: {0}'.format(Settings.SaveDir.get()), level=console.DBG_INFO)
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
-def quality(quality=None):
|
|
|
- if quality is None:
|
|
|
- quality = console.ask_input('Enter minimal quality for auto download')
|
|
|
- Settings.MinQuality.set(quality)
|
|
|
- console.output('Minimal quality for auto downloading is set to {0}'.format(Settings.MinQuality.get()), level=console.DBG_INFO)
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
-def last(items=None):
|
|
|
- global search_cache
|
|
|
- if items is not None:
|
|
|
- search_cache = items
|
|
|
- else:
|
|
|
- if search_cache is None:
|
|
|
- console.output('First search has yet te be made', console.DBG_ERROR)
|
|
|
- else:
|
|
|
- search(search_cache)
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
def quit():
|
|
|
return False
|
|
|
|
|
|
|
|
|
selected_site = 0
|
|
|
search_cache = None
|
|
|
-commands = [
|
|
|
- ('help', help, 'Display this list'),
|
|
|
- ('last', last, 'See the last search'),
|
|
|
- ('save', directory, 'Change the download directory'),
|
|
|
- ('search', search, 'Search the selected site'),
|
|
|
- ('sites', choose_site, 'Pick the site to search'),
|
|
|
- ('quality', quality, 'Set the minimal quality to download without confirmation'),
|
|
|
- ('quit', quit, 'Quit the program')
|
|
|
-]
|
|
|
-
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
main()
|