From f6fe7d6e17e7f9e210289d41d74534855692a072 Mon Sep 17 00:00:00 2001 From: Michael Kochell Date: Mon, 10 Sep 2018 05:20:49 -0400 Subject: [PATCH 1/2] [openload] Add option for phantomjs executable path --- youtube_dl/YoutubeDL.py | 4 +++- youtube_dl/__init__.py | 1 + youtube_dl/extractor/openload.py | 15 +++++++++------ youtube_dl/options.py | 4 ++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 38ba43a97..3f40af09e 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -2259,7 +2259,9 @@ class YoutubeDL(object): exe_versions = FFmpegPostProcessor.get_versions(self) exe_versions['rtmpdump'] = rtmpdump_version() - exe_versions['phantomjs'] = PhantomJSwrapper._version() + exe_versions['phantomjs'] = PhantomJSwrapper._version( + exe_path=self.params.get('phantomjs_location') + ) 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 ba435ea42..28d93fd04 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -421,6 +421,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 d264fe206..7bf954e62 100644 --- a/youtube_dl/extractor/openload.py +++ b/youtube_dl/extractor/openload.py @@ -107,14 +107,16 @@ class PhantomJSwrapper(object): _TMP_FILE_NAMES = ['script', 'html', 'cookies'] - @staticmethod - def _version(): - return get_exe_version('phantomjs', version_re=r'([0-9.]+)') + _DEFAULT_EXE_PATH = 'phantomjs' - def __init__(self, extractor, required_version=None, timeout=10000): + @classmethod + def _version(cls, exe_path=None): + return get_exe_version(exe_path or cls._DEFAULT_EXE_PATH, version_re=r'([0-9.]+)') + + def __init__(self, extractor, required_version=None, timeout=10000, exe_path=None): self._TMP_FILES = {} - self.exe = check_executable('phantomjs', ['-v']) + self.exe = check_executable(exe_path or self._DEFAULT_EXE_PATH, ['-v']) if not self.exe: raise ExtractorError('PhantomJS executable not found in PATH, ' 'download it from http://phantomjs.org', @@ -342,7 +344,8 @@ class OpenloadIE(InfoExtractor): raise ExtractorError('File not found', expected=True, video_id=video_id) break - phantom = PhantomJSwrapper(self, required_version='2.0') + phantomjs_location = self._downloader.params.get('phantomjs_location') + phantom = PhantomJSwrapper(self, required_version='2.0', exe_path=phantomjs_location) webpage, _ = phantom.get(page_url, html=webpage, video_id=video_id, headers=headers) decoded_id = (get_element_by_id('streamurl', webpage) or diff --git a/youtube_dl/options.py b/youtube_dl/options.py index e7d8e8910..8e01925b8 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -850,6 +850,10 @@ def parseOpts(overrideArguments=None): '--ffmpeg-location', '--avconv-location', metavar='PATH', dest='ffmpeg_location', help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.') + postproc.add_option( + '--phantomjs-location', metavar='PATH', + dest='phantomjs_location', + help='Location of the phantomjs binary; either the path to the binary or its containing directory.') postproc.add_option( '--exec', metavar='CMD', dest='exec_cmd', From 1ea3feddb6081c438f8499637421050bf7d46054 Mon Sep 17 00:00:00 2001 From: Michael Kochell Date: Mon, 10 Sep 2018 05:37:45 -0400 Subject: [PATCH 2/2] [openload] Change wording for phantomjs-location option to avoid confusion --- youtube_dl/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 8e01925b8..8c4174387 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -853,7 +853,7 @@ def parseOpts(overrideArguments=None): postproc.add_option( '--phantomjs-location', metavar='PATH', dest='phantomjs_location', - help='Location of the phantomjs binary; either the path to the binary or its containing directory.') + help='Location of the phantomjs binary.') postproc.add_option( '--exec', metavar='CMD', dest='exec_cmd',