From 6bc637d34a3e9986517271aa261d7d00fa48b658 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 25 Jan 2018 12:36:54 +0100 Subject: [PATCH] [openload] New --phantomjs-location option This option allows users to use a phantomjs binary that is not in PATH Closes #15146 --- youtube_dl/YoutubeDL.py | 2 +- youtube_dl/__init__.py | 1 + youtube_dl/extractor/openload.py | 13 +++++++++---- youtube_dl/options.py | 4 ++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 97bd9c526..2947d4fd0 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -2246,7 +2246,7 @@ class YoutubeDL(object): exe_versions = FFmpegPostProcessor.get_versions(self) exe_versions['rtmpdump'] = rtmpdump_version() - exe_versions['phantomjs'] = PhantomJSwrapper._version() + exe_versions['phantomjs'] = PhantomJSwrapper._version(self) exe_str = ', '.join( '%s %s' % (exe, v) for exe, v in sorted(exe_versions.items()) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index ba684a075..3e7aedc49 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -415,6 +415,7 @@ def _real_main(argv=None): 'match_filter': match_filter, 'no_color': opts.no_color, 'ffmpeg_location': opts.ffmpeg_location, + 'phantomjs_location': opts.phantomjs_location, 'hls_prefer_native': opts.hls_prefer_native, 'hls_use_mpegts': opts.hls_use_mpegts, 'external_downloader_args': external_downloader_args, diff --git a/youtube_dl/extractor/openload.py b/youtube_dl/extractor/openload.py index eaaaf8a08..69322e1e0 100644 --- a/youtube_dl/extractor/openload.py +++ b/youtube_dl/extractor/openload.py @@ -108,13 +108,18 @@ class PhantomJSwrapper(object): _TMP_FILE_NAMES = ['script', 'html', 'cookies'] @staticmethod - def _version(): - return get_exe_version('phantomjs', version_re=r'([0-9.]+)') + def _get_path(downloader): + location = downloader.params.get('phantomjs_location') or 'phantomjs' + return location + + @staticmethod + def _version(downloader): + return get_exe_version(PhantomJSwrapper._get_path(downloader), version_re=r'([0-9.]+)') def __init__(self, extractor, required_version=None, timeout=10000): self._TMP_FILES = {} - self.exe = check_executable('phantomjs', ['-v']) + self.exe = check_executable(self._get_path(extractor._downloader), ['-v']) if not self.exe: raise ExtractorError('PhantomJS executable not found in PATH, ' 'download it from http://phantomjs.org', @@ -123,7 +128,7 @@ class PhantomJSwrapper(object): self.extractor = extractor if required_version: - version = self._version() + version = self._version(self.extractor._downloader) if is_outdated_version(version, required_version): self.extractor._downloader.report_warning( 'Your copy of PhantomJS is outdated, update it to version ' diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 4c0455044..4f4e8acaa 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -516,6 +516,10 @@ def parseOpts(overrideArguments=None): '--external-downloader-args', dest='external_downloader_args', metavar='ARGS', help='Give these arguments to the external downloader') + downloader.add_option( + '--phantomjs-location', metavar='PATH', + dest='phantomjs_location', + help='Path to the phantomjs binary') workarounds = optparse.OptionGroup(parser, 'Workarounds') workarounds.add_option(