[downloader:ytdl] add several options

The "default" downloader options (rate, retries, timeout, verify) are
mapped to corresponding youtube-dl options.

downloader.ytdl.logging tells the downloader to pass youtube-dl's output
to a Logger object.

downloader.ytdl.raw-options allows to pass arbitrary options to the
YoutubeDL constructor.
pull/133/head
Mike Fährmann 6 years ago
parent d3d7f01543
commit 655549df7c
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -797,8 +797,8 @@ Description Alternate location for ``.part`` files.
=========== =====
downloader.http.rate
--------------------
downloader.rate
---------------
=========== =====
Type ``string``
Default ``null``
@ -811,8 +811,8 @@ Description Maximum download rate in bytes per second.
=========== =====
downloader.http.retries
-----------------------
downloader.retries
------------------
=========== =====
Type ``integer``
Default `extractor.*.retries`_
@ -820,8 +820,8 @@ Description Number of retries during file downloads.
=========== =====
downloader.http.timeout
-----------------------
downloader.timeout
------------------
=========== =====
Type ``float`` or ``null``
Default `extractor.*.timeout`_
@ -829,8 +829,8 @@ Description Connection timeout during file downloads.
=========== =====
downloader.http.verify
----------------------
downloader.verify
-----------------
=========== =====
Type ``bool`` or ``string``
Default `extractor.*.verify`_
@ -838,6 +838,37 @@ Description Certificate validation during file downloads.
=========== =====
downloader.ytdl.logging
-----------------------
=========== =====
Type ``bool``
Default ``true``
Description | Route youtube-dl's output through gallery-dl's logging system.
| Otherwise youtube-dl will write its output directly to stdout/stderr.
Note: Set ``quiet`` and ``no_warnings`` in
`downloader.ytdl.raw-options`_ to ``true`` to suppress all output.
=========== =====
downloader.ytdl.raw-options
---------------------------
=========== =====
Type ``object``
Example .. code::
{
"quiet": true,
"writesubtitles": true,
"merge_output_format": "mkv"
}
Description | Additional options passed directly to the ``YoutubeDL`` constructor.
| All available options can be found in `youtube-dl's docstrings
<https://github.com/rg3/youtube-dl/blob/master/youtube_dl/YoutubeDL.py#L138-L318>`__.
=========== =====
Output Options
==============

@ -23,7 +23,7 @@ class DownloaderBase():
def __init__(self, extractor, output):
self.session = extractor.session
self.out = output
self.log = logging.getLogger("download")
self.log = logging.getLogger("downloader." + self.scheme)
self.downloading = False
self.part = self.config("part", True)
self.partdir = self.config("part-directory")

@ -8,9 +8,9 @@
"""Downloader module for URLs requiring youtube-dl support"""
from .common import DownloaderBase
from youtube_dl import YoutubeDL
import logging
from .common import DownloaderBase
from .. import text
import os
@ -19,9 +19,21 @@ class Downloader(DownloaderBase):
def __init__(self, extractor, output):
DownloaderBase.__init__(self, extractor, output)
self.ytdl = YoutubeDL({
"logger": logging.getLogger("ytdl"),
})
options = {
"format": self.config("format") or None,
"ratelimit": text.parse_bytes(self.config("rate"), None),
"retries": self.config("retries", extractor._retries),
"socket_timeout": self.config("timeout", extractor._timeout),
"nocheckcertificate": not self.config("verify", extractor._verify),
"nopart": not self.part,
}
options.update(self.config("raw-options") or {})
if self.config("logging", True):
options["logger"] = self.log
self.ytdl = YoutubeDL(options)
def download(self, url, pathfmt):
try:
@ -38,15 +50,16 @@ class Downloader(DownloaderBase):
if pathfmt.exists():
pathfmt.temppath = ""
return True
if self.partdir:
if self.part and self.partdir:
pathfmt.temppath = os.path.join(
self.partdir, pathfmt.filename)
self.ytdl.params["outtmpl"] = pathfmt.temppath.replace("%", "%$")
self.ytdl.params["outtmpl"] = pathfmt.temppath.replace("%", "%%")
self.out.start(pathfmt.path)
try:
self.ytdl.process_info(info_dict)
except Exception:
self.log.debug("Traceback", exc_info=True)
return False
return True

Loading…
Cancel
Save