diff options
author | Alex Shnitman <alexta69@gmail.com> | 2021-08-28 10:32:24 +0300 |
---|---|---|
committer | Alex Shnitman <alexta69@gmail.com> | 2021-08-28 10:32:24 +0300 |
commit | b1f856474cda80714688bf214e5aa4ee07898b47 (patch) | |
tree | 723e68c07717199e6270e6e7b720dcca67b753e1 /app | |
parent | allow all video formats, and merge into mp4 (diff) | |
download | metube-b1f856474cda80714688bf214e5aa4ee07898b47.tar.gz metube-b1f856474cda80714688bf214e5aa4ee07898b47.tar.bz2 metube-b1f856474cda80714688bf214e5aa4ee07898b47.zip |
add support for youtube-dl options (closes #33, #34)
Diffstat (limited to 'app')
-rw-r--r-- | app/main.py | 8 | ||||
-rw-r--r-- | app/ytdl.py | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/app/main.py b/app/main.py index d94967b..000cb28 100644 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ # pylint: disable=no-member,method-hidden
import os
+import sys
from aiohttp import web
import socketio
import logging
@@ -17,6 +18,7 @@ class Config: 'AUDIO_DOWNLOAD_DIR': '%%DOWNLOAD_DIR',
'URL_PREFIX': '',
'OUTPUT_TEMPLATE': '%(title)s.%(ext)s',
+ 'YTDL_OPTIONS': '{}',
}
def __init__(self):
@@ -27,6 +29,12 @@ class Config: setattr(self, k, getattr(self, v[2:]))
if not self.URL_PREFIX.endswith('/'):
self.URL_PREFIX += '/'
+ try:
+ self.YTDL_OPTIONS = json.loads(self.YTDL_OPTIONS)
+ assert isinstance(self.YTDL_OPTIONS, dict)
+ except (json.decoder.JSONDecodeError, AssertionError):
+ log.error('YTDL_OPTIONS is invalid')
+ sys.exit(1)
config = Config()
diff --git a/app/ytdl.py b/app/ytdl.py index ef4ada0..052637d 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -32,7 +32,7 @@ class DownloadInfo: class Download:
manager = None
- def __init__(self, download_dir, output_template, quality, info):
+ def __init__(self, download_dir, output_template, quality, ytdl_opts, info):
self.download_dir = download_dir
self.output_template = output_template
if quality == 'best':
@@ -46,6 +46,7 @@ class Download: self.format = quality[7:]
else:
raise Exception(f'unknown quality {quality}')
+ self.ytdl_opts = ytdl_opts
self.info = info
self.canceled = False
self.tmpfilename = None
@@ -77,6 +78,7 @@ class Download: 'cachedir': False,
'socket_timeout': 30,
'progress_hooks': [put_status],
+ **self.ytdl_opts,
}).download([self.info.url])
self.status_queue.put({'status': 'finished' if ret == 0 else 'error'})
except yt_dlp.utils.YoutubeDLError as exc:
@@ -161,7 +163,7 @@ class DownloadQueue: if entry['id'] not in self.queue:
dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality)
dldirectory = self.config.DOWNLOAD_DIR if quality != 'audio' else self.config.AUDIO_DOWNLOAD_DIR
- self.queue[entry['id']] = Download(dldirectory, self.config.OUTPUT_TEMPLATE, quality, dl)
+ self.queue[entry['id']] = Download(dldirectory, self.config.OUTPUT_TEMPLATE, quality, self.config.YTDL_OPTIONS, dl)
self.event.set()
await self.notifier.added(dl)
return {'status': 'ok'}
|