Skip to content

Commit

Permalink
[downloader:ytdl] add 'outtmpl' option (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 24, 2019
1 parent 5cc7be2 commit 7c09545
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
19 changes: 19 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------
=========== =====
Expand Down
1 change: 1 addition & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"format": null,
"forward-cookies": true,
"mtime": true,
"outtmpl": null,
"rate": null,
"retries": 4,
"timeout": 30.0,
Expand Down
17 changes: 15 additions & 2 deletions gallery_dl/downloader/ytdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""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 .. import text
import os
Expand Down Expand Up @@ -36,6 +36,9 @@ def __init__(self, extractor, output):
options["logger"] = self.log
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)

def download(self, url, pathfmt):
Expand All @@ -60,7 +63,17 @@ def download(self, url, pathfmt):
def _download_video(self, pathfmt, info_dict):
if "url" in info_dict:
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():
pathfmt.temppath = ""
return True
Expand Down

0 comments on commit 7c09545

Please sign in to comment.