From 1a38fae7859db55fda6d92eb2e743ae55ad2e216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 1 Mar 2021 03:10:42 +0100 Subject: [PATCH] add option to use different youtube-dl modules (fixes #1330) by setting the 'downloader.ytdl.module' value. For example { "downloader": { "ytdl": { "module": "yt_dlp" } } } or '-o module=yt_dlp' --- docs/configuration.rst | 10 ++++++++++ gallery_dl/downloader/ytdl.py | 16 +++++++++++----- scripts/hook-gallery_dl.py | 2 ++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 545e8108..62cd4de9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1943,6 +1943,16 @@ Description `downloader.ytdl.raw-options`_ to ``true`` to suppress all output. +downloader.ytdl.module +---------------------- +Type + ``string`` +Default + ``"youtube_dl"`` +Description + Name of the youtube-dl Python module to import. + + downloader.ytdl.outtmpl ----------------------- Type diff --git a/gallery_dl/downloader/ytdl.py b/gallery_dl/downloader/ytdl.py index 8086b5d9..e1161885 100644 --- a/gallery_dl/downloader/ytdl.py +++ b/gallery_dl/downloader/ytdl.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2018-2020 Mike Fährmann +# Copyright 2018-2021 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -8,7 +8,6 @@ """Downloader module for URLs requiring youtube-dl support""" -from youtube_dl import YoutubeDL, DEFAULT_OUTTMPL from .common import DownloaderBase from .. import text import os @@ -16,8 +15,14 @@ import os class YoutubeDLDownloader(DownloaderBase): scheme = "ytdl" + module = None def __init__(self, job): + module = self.module + if not module: + module_name = self.config("module") or "youtube_dl" + module = YoutubeDLDownloader.module = __import__(module_name) + DownloaderBase.__init__(self, job) extractor = job.extractor @@ -42,10 +47,11 @@ class YoutubeDLDownloader(DownloaderBase): options["logger"] = self.log self.forward_cookies = self.config("forward-cookies", False) - outtmpl = self.config("outtmpl") - self.outtmpl = DEFAULT_OUTTMPL if outtmpl == "default" else outtmpl + self.outtmpl = self.config("outtmpl") + if self.outtmpl == "default": + self.outtmpl = module.DEFAULT_OUTTMPL - self.ytdl = YoutubeDL(options) + self.ytdl = module.YoutubeDL(options) def download(self, url, pathfmt): if self.forward_cookies: diff --git a/scripts/hook-gallery_dl.py b/scripts/hook-gallery_dl.py index d5490198..ba7bed66 100644 --- a/scripts/hook-gallery_dl.py +++ b/scripts/hook-gallery_dl.py @@ -7,3 +7,5 @@ hiddenimports = [ for package in (extractor, downloader, postprocessor) for module in package.modules ] + +hiddenimports.append("youtube_dl")