[downloader:ytdl] add 'outtmpl' option (#395)
This commit is contained in:
@@ -1171,6 +1171,25 @@ Description | Route youtube-dl's output through gallery-dl's logging system.
|
|||||||
=========== =====
|
=========== =====
|
||||||
|
|
||||||
|
|
||||||
|
downloader.ytdl.outtmpl
|
||||||
|
-----------------------
|
||||||
|
=========== =====
|
||||||
|
Type ``string``
|
||||||
|
Default ``null``
|
||||||
|
Description The `Output Template <https://github.com/ytdl-org/youtube-dl#output-template>`__
|
||||||
|
used to generate filenames for files downloaded with youtube-dl.
|
||||||
|
|
||||||
|
Special values:
|
||||||
|
|
||||||
|
* ``null``: generate filenames with `extractor.*.filename`_
|
||||||
|
* ``"default"``: use youtube-dl's default, currently ``"%(title)s-%(id)s.%(ext)s"``
|
||||||
|
|
||||||
|
Note: An output template other than ``null`` might
|
||||||
|
cause unexpected results in combination with other options
|
||||||
|
(e.g. ``"skip": "enumerate"``)
|
||||||
|
=========== =====
|
||||||
|
|
||||||
|
|
||||||
downloader.ytdl.raw-options
|
downloader.ytdl.raw-options
|
||||||
---------------------------
|
---------------------------
|
||||||
=========== =====
|
=========== =====
|
||||||
|
|||||||
@@ -169,6 +169,7 @@
|
|||||||
"format": null,
|
"format": null,
|
||||||
"forward-cookies": true,
|
"forward-cookies": true,
|
||||||
"mtime": true,
|
"mtime": true,
|
||||||
|
"outtmpl": null,
|
||||||
"rate": null,
|
"rate": null,
|
||||||
"retries": 4,
|
"retries": 4,
|
||||||
"timeout": 30.0,
|
"timeout": 30.0,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
"""Downloader module for URLs requiring youtube-dl support"""
|
"""Downloader module for URLs requiring youtube-dl support"""
|
||||||
|
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL, DEFAULT_OUTTMPL
|
||||||
from .common import DownloaderBase
|
from .common import DownloaderBase
|
||||||
from .. import text
|
from .. import text
|
||||||
import os
|
import os
|
||||||
@@ -36,6 +36,9 @@ class YoutubeDLDownloader(DownloaderBase):
|
|||||||
options["logger"] = self.log
|
options["logger"] = self.log
|
||||||
self.forward_cookies = self.config("forward-cookies", True)
|
self.forward_cookies = self.config("forward-cookies", True)
|
||||||
|
|
||||||
|
outtmpl = self.config("outtmpl")
|
||||||
|
self.outtmpl = DEFAULT_OUTTMPL if outtmpl == "default" else outtmpl
|
||||||
|
|
||||||
self.ytdl = YoutubeDL(options)
|
self.ytdl = YoutubeDL(options)
|
||||||
|
|
||||||
def download(self, url, pathfmt):
|
def download(self, url, pathfmt):
|
||||||
@@ -60,7 +63,17 @@ class YoutubeDLDownloader(DownloaderBase):
|
|||||||
def _download_video(self, pathfmt, info_dict):
|
def _download_video(self, pathfmt, info_dict):
|
||||||
if "url" in info_dict:
|
if "url" in info_dict:
|
||||||
text.nameext_from_url(info_dict["url"], pathfmt.kwdict)
|
text.nameext_from_url(info_dict["url"], pathfmt.kwdict)
|
||||||
pathfmt.set_extension(info_dict["ext"])
|
|
||||||
|
if self.outtmpl:
|
||||||
|
self.ytdl.params["outtmpl"] = self.outtmpl
|
||||||
|
pathfmt.filename = filename = self.ytdl.prepare_filename(info_dict)
|
||||||
|
pathfmt.extension = info_dict["ext"]
|
||||||
|
pathfmt.path = pathfmt.directory + filename
|
||||||
|
pathfmt.realpath = pathfmt.temppath = (
|
||||||
|
pathfmt.realdirectory + filename)
|
||||||
|
else:
|
||||||
|
pathfmt.set_extension(info_dict["ext"])
|
||||||
|
|
||||||
if pathfmt.exists():
|
if pathfmt.exists():
|
||||||
pathfmt.temppath = ""
|
pathfmt.temppath = ""
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user