diff options
author | Alex Shnitman <alexta69@gmail.com> | 2022-09-30 09:09:41 +0300 |
---|---|---|
committer | Alex Shnitman <alexta69@gmail.com> | 2022-09-30 09:09:41 +0300 |
commit | 68d4c89be0a661ce140dee22bb008e949796f655 (patch) | |
tree | c8d195e229a7d9b9c98ffe71881fafaf96637320 /app | |
parent | remove CI from non-master branch (diff) | |
parent | upgraded yt-dlp (diff) | |
download | metube-68d4c89be0a661ce140dee22bb008e949796f655.tar.gz metube-68d4c89be0a661ce140dee22bb008e949796f655.tar.bz2 metube-68d4c89be0a661ce140dee22bb008e949796f655.zip |
Merge branch 'master' of https://github.com/alexta69/metube into custom-download-folder
Diffstat (limited to 'app')
-rw-r--r-- | app/dl_formats.py | 9 | ||||
-rw-r--r-- | app/ytdl.py | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/app/dl_formats.py b/app/dl_formats.py index c06b93b..316d5df 100644 --- a/app/dl_formats.py +++ b/app/dl_formats.py @@ -19,6 +19,10 @@ def get_format(format: str, quality: str) -> str: if format.startswith("custom:"): return format[7:] + if format == "thumbnail": + # Quality is irrelevant in this case since we skip the download + return "bestaudio/best" + if format == "mp3": # Audio quality needs to be set post-download, set in opts return "bestaudio/best" @@ -66,4 +70,9 @@ def get_opts(format: str, quality: str, ytdl_opts: dict) -> dict: opts["postprocessors"].append({"key": "FFmpegMetadata"}) opts["postprocessors"].append({"key": "EmbedThumbnail"}) + if format == "thumbnail": + opts["skip_download"] = True + opts["writethumbnail"] = True + opts["postprocessors"].append({"key": "FFmpegThumbnailsConvertor", "format": "jpg", "when": "before_dl"}) + return opts diff --git a/app/ytdl.py b/app/ytdl.py index 97fa0a8..0bafc91 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -6,6 +6,7 @@ import time import asyncio
import multiprocessing
import logging
+import re
from dl_formats import get_format, get_opts
log = logging.getLogger('ytdl')
@@ -127,6 +128,10 @@ class Download: self.tmpfilename = status.get('tmpfilename')
if 'filename' in status:
self.info.filename = os.path.relpath(status.get('filename'), self.download_dir)
+
+ # Set correct file extension for thumbnails
+ if(self.info.format == 'thumbnail'):
+ self.info.filename = re.sub(r'\.webm$', '.jpg', self.info.filename)
self.info.status = status['status']
self.info.msg = status.get('msg')
if 'downloaded_bytes' in status:
|