From f4e3cee6ac93bd924f926b77a66a7db5bd4517e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 29 Nov 2021 04:36:43 +0100 Subject: [PATCH] use yt-dlp by default (#1850, #2028) --- .github/workflows/executables.yml | 2 +- README.rst | 3 ++- docs/configuration.rst | 10 ++++++++-- docs/gallery-dl.conf | 4 ++-- gallery_dl/downloader/ytdl.py | 2 +- gallery_dl/extractor/ytdl.py | 10 +++++----- gallery_dl/ytdl.py | 9 +++++++++ scripts/hook-gallery_dl.py | 2 +- 8 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.github/workflows/executables.yml b/.github/workflows/executables.yml index 938f4186..7a8a83ac 100644 --- a/.github/workflows/executables.yml +++ b/.github/workflows/executables.yml @@ -21,7 +21,7 @@ jobs: - name: Build executable run: | - pip install requests requests[socks] urllib3==1.25.11 youtube-dl pyinstaller + pip install requests requests[socks] urllib3==1.25.11 yt-dlp pyinstaller python scripts/pyinstaller.py - name: Upload executable diff --git a/README.rst b/README.rst index 72f7c827..29ac980d 100644 --- a/README.rst +++ b/README.rst @@ -23,7 +23,7 @@ Optional -------- - FFmpeg_: Pixiv Ugoira to WebM conversion -- youtube-dl_: Video downloads +- yt-dlp_ or youtube-dl_: Video downloads Installation @@ -328,6 +328,7 @@ To authenticate with a ``mastodon`` instance, run *gallery-dl* with .. _pip: https://pip.pypa.io/en/stable/ .. _Requests: https://requests.readthedocs.io/en/master/ .. _FFmpeg: https://www.ffmpeg.org/ +.. _yt-dlp: https://github.com/yt-dlp/yt-dlp .. _youtube-dl: https://ytdl-org.github.io/youtube-dl/ .. _pyOpenSSL: https://pyopenssl.org/ .. _Snapd: https://docs.snapcraft.io/installing-snapd diff --git a/docs/configuration.rst b/docs/configuration.rst index ef1f9da0..007c0aee 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2275,10 +2275,13 @@ extractor.ytdl.module Type ``string`` Default - ``"youtube_dl"`` + ``null`` Description Name of the youtube-dl Python module to import. + Setting this to ``null`` will try to import ``"yt_dlp"`` + followed by ``"youtube_dl"`` as fallback. + extractor.ytdl.raw-options -------------------------- @@ -2564,10 +2567,13 @@ downloader.ytdl.module Type ``string`` Default - ``"youtube_dl"`` + ``null`` Description Name of the youtube-dl Python module to import. + Setting this to ``null`` will first try to import ``"yt_dlp"`` + and use ``"youtube_dl"`` as fallback. + downloader.ytdl.outtmpl ----------------------- diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 0800ec7f..985bb1de 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -303,7 +303,7 @@ "format": null, "generic": true, "logging": true, - "module": "youtube_dl", + "module": null, "raw-options": null }, "booru": @@ -337,7 +337,7 @@ "format": null, "forward-cookies": false, "logging": true, - "module": "youtube_dl", + "module": null, "outtmpl": null, "raw-options": null } diff --git a/gallery_dl/downloader/ytdl.py b/gallery_dl/downloader/ytdl.py index 8416ca07..30f628ef 100644 --- a/gallery_dl/downloader/ytdl.py +++ b/gallery_dl/downloader/ytdl.py @@ -39,7 +39,7 @@ class YoutubeDLDownloader(DownloaderBase): if not ytdl_instance: ytdl_instance = self.ytdl_instance if not ytdl_instance: - module = __import__(self.config("module") or "youtube_dl") + module = ytdl.import_module(self.config("module")) self.ytdl_instance = ytdl_instance = ytdl.construct_YoutubeDL( module, self, self.ytdl_opts) if self.outtmpl == "default": diff --git a/gallery_dl/extractor/ytdl.py b/gallery_dl/extractor/ytdl.py index 8eb0c834..8f3ef9a4 100644 --- a/gallery_dl/extractor/ytdl.py +++ b/gallery_dl/extractor/ytdl.py @@ -23,9 +23,9 @@ class YoutubeDLExtractor(Extractor): def __init__(self, match): # import main youtube_dl module - module_name = self.ytdl_module_name = config.get( - ("extractor", "ytdl"), "module") or "youtube_dl" - module = __import__(module_name) + ytdl_module = ytdl.import_module(config.get( + ("extractor", "ytdl"), "module")) + self.ytdl_module_name = ytdl_module.__name__ # find suitable youtube_dl extractor self.ytdl_url = url = match.group(1) @@ -34,7 +34,7 @@ class YoutubeDLExtractor(Extractor): self.ytdl_ie_key = "Generic" self.force_generic_extractor = True else: - for ie in module.extractor.gen_extractor_classes(): + for ie in ytdl_module.extractor.gen_extractor_classes(): if ie.suitable(url): self.ytdl_ie_key = ie.ie_key() break @@ -48,7 +48,7 @@ class YoutubeDLExtractor(Extractor): def items(self): # import subcategory module - ytdl_module = __import__( + ytdl_module = ytdl.import_module( config.get(("extractor", "ytdl", self.subcategory), "module") or self.ytdl_module_name) self.log.debug("Using %s", ytdl_module) diff --git a/gallery_dl/ytdl.py b/gallery_dl/ytdl.py index 4266f48c..f8c7f98a 100644 --- a/gallery_dl/ytdl.py +++ b/gallery_dl/ytdl.py @@ -14,6 +14,15 @@ import itertools from . import text, util, exception +def import_module(module_name): + if module_name is None: + try: + return __import__("yt_dlp") + except ImportError: + return __import__("youtube_dl") + return __import__(module_name.replace("-", "_")) + + def construct_YoutubeDL(module, obj, user_opts, system_opts=None): opts = argv = None config = obj.config diff --git a/scripts/hook-gallery_dl.py b/scripts/hook-gallery_dl.py index ba7bed66..ae51b068 100644 --- a/scripts/hook-gallery_dl.py +++ b/scripts/hook-gallery_dl.py @@ -8,4 +8,4 @@ hiddenimports = [ for module in package.modules ] -hiddenimports.append("youtube_dl") +hiddenimports.append("yt_dlp")