aboutsummaryrefslogtreecommitdiff
path: root/app/ytdl.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/ytdl.py')
-rw-r--r--app/ytdl.py26
1 files changed, 3 insertions, 23 deletions
diff --git a/app/ytdl.py b/app/ytdl.py
index 0400877..63c3786 100644
--- a/app/ytdl.py
+++ b/app/ytdl.py
@@ -4,6 +4,7 @@ from collections import OrderedDict
import asyncio
import multiprocessing
import logging
+from dl_formats import get_format, get_opts
log = logging.getLogger('ytdl')
@@ -36,29 +37,8 @@ class Download:
def __init__(self, download_dir, output_template, quality, format, ytdl_opts, info):
self.download_dir = download_dir
self.output_template = output_template
- vfmt, afmt = '', ''
- if format == 'mp4':
- vfmt, afmt = '[ext=mp4]', '[ext=m4a]'
- elif format == 'mp3':
- afmt = '/best'
- ytdl_opts["writethumbnail"] = True
- ytdl_opts["postprocessors"] = [
- {"key": "FFmpegExtractAudio", "preferredcodec": "mp3"},
- {"key": "EmbedThumbnail"},
- ]
-
- if quality == 'best':
- self.format = f'bestvideo{vfmt}+bestaudio{afmt}/best{vfmt}'
- elif quality in ('1440p', '1080p', '720p', '480p'):
- res = quality[:-1]
- self.format = f'bestvideo[height<={res}]{vfmt}+bestaudio{afmt}/best[height<={res}]{vfmt}'
- elif quality == 'audio':
- self.format = f'bestaudio{afmt}'
- elif quality.startswith('custom:'):
- self.format = quality[7:]
- else:
- raise Exception(f'unknown quality {quality}')
- self.ytdl_opts = ytdl_opts
+ self.format = get_format(format, quality)
+ self.ytdl_opts = get_opts(format, quality, ytdl_opts)
self.info = info
self.canceled = False
self.tmpfilename = None
bgstack15