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'
This commit is contained in:
Mike Fährmann
2021-03-01 03:10:42 +01:00
parent 5f1a6ff6fa
commit 1a38fae785
3 changed files with 23 additions and 5 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -7,3 +7,5 @@ hiddenimports = [
for package in (extractor, downloader, postprocessor)
for module in package.modules
]
hiddenimports.append("youtube_dl")