environment variable to customize output file names

This commit is contained in:
Alfred Toth 2021-05-18 16:15:49 +02:00
parent 155d93a14c
commit c8462012a1
2 changed files with 5 additions and 3 deletions

View File

@ -17,6 +17,7 @@ class Config:
_DEFAULTS = { _DEFAULTS = {
'DOWNLOAD_DIR': '.', 'DOWNLOAD_DIR': '.',
'URL_PREFIX': '', 'URL_PREFIX': '',
'OUTPUT_TEMPLATE': '%(title)s.%(ext)s',
} }
def __init__(self): def __init__(self):

View File

@ -32,8 +32,9 @@ class DownloadInfo:
class Download: class Download:
manager = None manager = None
def __init__(self, download_dir, quality, info): def __init__(self, download_dir, output_template, quality, info):
self.download_dir = download_dir self.download_dir = download_dir
self.output_template = output_template
if quality == 'best': if quality == 'best':
self.format = None self.format = None
elif quality in ('1440p', '1080p', '720p', '480p'): elif quality in ('1440p', '1080p', '720p', '480p'):
@ -59,7 +60,7 @@ class Download:
'quiet': True, 'quiet': True,
'no_color': True, 'no_color': True,
#'skip_download': True, #'skip_download': True,
'outtmpl': os.path.join(self.download_dir, '%(title)s.%(ext)s'), 'outtmpl': os.path.join(self.download_dir, self.output_template),
'format': self.format, 'format': self.format,
'cachedir': False, 'cachedir': False,
'socket_timeout': 30, 'socket_timeout': 30,
@ -147,7 +148,7 @@ class DownloadQueue:
elif etype == 'video' or etype.startswith('url') and 'id' in entry: elif etype == 'video' or etype.startswith('url') and 'id' in entry:
if entry['id'] not in self.queue: if entry['id'] not in self.queue:
dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url']) dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'])
self.queue[entry['id']] = Download(self.config.DOWNLOAD_DIR, quality, dl) self.queue[entry['id']] = Download(self.config.DOWNLOAD_DIR, self.config.OUTPUT_TEMPLATE, quality, dl)
self.event.set() self.event.set()
await self.notifier.added(dl) await self.notifier.added(dl)
return {'status': 'ok'} return {'status': 'ok'}