mirror of
https://github.com/alexta69/metube.git
synced 2025-04-04 20:57:45 +03:00
Fill in download_dir or audio_download_dir on launch
This commit is contained in:
parent
8abacc2a36
commit
ba712fc071
12 changed files with 108 additions and 256 deletions
43
app/main.py
43
app/main.py
|
@ -17,8 +17,8 @@ class Config:
|
|||
_DEFAULTS = {
|
||||
'DOWNLOAD_DIR': '.',
|
||||
'AUDIO_DOWNLOAD_DIR': '%%DOWNLOAD_DIR',
|
||||
'CUSTOM_DIR': 'true',
|
||||
'AUTO_CREATE_CUSTOM_DIR': 'false',
|
||||
'CUSTOM_DIRS': 'true',
|
||||
'CREATE_DIRS': 'false',
|
||||
'STATE_DIR': '.',
|
||||
'URL_PREFIX': '',
|
||||
'OUTPUT_TEMPLATE': '%(title)s.%(ext)s',
|
||||
|
@ -101,18 +101,39 @@ async def delete(request):
|
|||
async def connect(sid, environ):
|
||||
await sio.emit('all', serializer.encode(dqueue.get()), to=sid)
|
||||
await sio.emit('configuration', serializer.encode(config), to=sid)
|
||||
if config.CUSTOM_DIR:
|
||||
await sio.emit('custom_directories', serializer.encode(get_custom_directories()), to=sid)
|
||||
if config.CUSTOM_DIRS:
|
||||
await sio.emit('custom_dirs', serializer.encode(get_custom_dirs()), to=sid)
|
||||
|
||||
def get_custom_directories():
|
||||
path = pathlib.Path(config.DOWNLOAD_DIR)
|
||||
# Recursively lists all subdirectories, and converts PosixPath objects to string
|
||||
dirs = list(map(str, path.glob('**')))
|
||||
def get_custom_dirs():
|
||||
def recursive_dirs(base):
|
||||
path = pathlib.Path(base)
|
||||
|
||||
# Converts PosixPath object to string, and remove base/ prefix
|
||||
def convert(p):
|
||||
s = str(p)
|
||||
if s.startswith(base):
|
||||
s = s[len(base):]
|
||||
|
||||
if s.startswith('/'):
|
||||
s = s[1:]
|
||||
|
||||
return s
|
||||
|
||||
# Recursively lists all subdirectories of DOWNLOAD_DIR
|
||||
dirs = list(filter(None, map(convert, path.glob('**'))))
|
||||
|
||||
return dirs
|
||||
|
||||
if '.' in dirs:
|
||||
dirs.remove('.')
|
||||
download_dir = recursive_dirs(config.DOWNLOAD_DIR)
|
||||
|
||||
return {"directories": dirs}
|
||||
audio_download_dir = download_dir
|
||||
if config.DOWNLOAD_DIR != config.AUDIO_DOWNLOAD_DIR:
|
||||
audio_download_dir = recursive_dirs(config.AUDIO_DOWNLOAD_DIR)
|
||||
|
||||
return {
|
||||
"download_dir": download_dir,
|
||||
"audio_download_dir": audio_download_dir
|
||||
}
|
||||
|
||||
@routes.get(config.URL_PREFIX)
|
||||
def index(request):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue