mirror of https://github.com/alexta69/metube
Merge pull request #148 from 1RandomDev/download-thumbnail
Added option for thumbnail onlypull/179/head
commit
208d6f25ba
|
@ -19,6 +19,10 @@ def get_format(format: str, quality: str) -> str:
|
||||||
if format.startswith("custom:"):
|
if format.startswith("custom:"):
|
||||||
return format[7:]
|
return format[7:]
|
||||||
|
|
||||||
|
if format == "thumbnail":
|
||||||
|
# Quality is irrelevant in this case since we skip the download
|
||||||
|
return "bestaudio/best"
|
||||||
|
|
||||||
if format == "mp3":
|
if format == "mp3":
|
||||||
# Audio quality needs to be set post-download, set in opts
|
# Audio quality needs to be set post-download, set in opts
|
||||||
return "bestaudio/best"
|
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": "FFmpegMetadata"})
|
||||||
opts["postprocessors"].append({"key": "EmbedThumbnail"})
|
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
|
return opts
|
||||||
|
|
|
@ -6,6 +6,7 @@ import time
|
||||||
import asyncio
|
import asyncio
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from dl_formats import get_format, get_opts
|
from dl_formats import get_format, get_opts
|
||||||
|
|
||||||
log = logging.getLogger('ytdl')
|
log = logging.getLogger('ytdl')
|
||||||
|
@ -126,6 +127,10 @@ class Download:
|
||||||
self.tmpfilename = status.get('tmpfilename')
|
self.tmpfilename = status.get('tmpfilename')
|
||||||
if 'filename' in status:
|
if 'filename' in status:
|
||||||
self.info.filename = os.path.relpath(status.get('filename'), self.download_dir)
|
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.status = status['status']
|
||||||
self.info.msg = status.get('msg')
|
self.info.msg = status.get('msg')
|
||||||
if 'downloaded_bytes' in status:
|
if 'downloaded_bytes' in status:
|
||||||
|
|
|
@ -43,4 +43,11 @@ export const Formats: Format[] = [
|
||||||
{ id: '128', text: '128 kbps' },
|
{ id: '128', text: '128 kbps' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'thumbnail',
|
||||||
|
text: 'Thumbnail',
|
||||||
|
qualities: [
|
||||||
|
{ id: 'best', text: 'Best' }
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue