aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-08-22 06:19:06 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-08-22 06:19:06 +0530
commit992dc6b4863d0e60f2a1ce3933f67814d8a17f8d (patch)
treeb5ee32fddbc6270f2221ba4f0eaf2abc81a31dc8
parent822d66e591341f8bf082be371b4beb66d72ba080 (diff)
downloadhypervideo-pre-992dc6b4863d0e60f2a1ce3933f67814d8a17f8d.tar.lz
hypervideo-pre-992dc6b4863d0e60f2a1ce3933f67814d8a17f8d.tar.xz
hypervideo-pre-992dc6b4863d0e60f2a1ce3933f67814d8a17f8d.zip
[jsinterp] Implement timeout
Workaround for #4716
-rw-r--r--yt_dlp/extractor/openload.py10
-rw-r--r--yt_dlp/extractor/youtube.py2
-rw-r--r--yt_dlp/utils.py4
3 files changed, 10 insertions, 6 deletions
diff --git a/yt_dlp/extractor/openload.py b/yt_dlp/extractor/openload.py
index e66ed4831..4bba7bdd0 100644
--- a/yt_dlp/extractor/openload.py
+++ b/yt_dlp/extractor/openload.py
@@ -219,7 +219,7 @@ class PhantomJSwrapper:
return html, stdout
- def execute(self, jscode, video_id=None, note='Executing JS'):
+ def execute(self, jscode, video_id=None, *, note='Executing JS'):
"""Execute JS and return stdout"""
if 'phantom.exit();' not in jscode:
jscode += ';\nphantom.exit();'
@@ -231,8 +231,12 @@ class PhantomJSwrapper:
cmd = [self.exe, '--ssl-protocol=any', self._TMP_FILES['script'].name]
self.extractor.write_debug(f'PhantomJS command line: {shell_quote(cmd)}')
- stdout, stderr, returncode = Popen.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ try:
+ stdout, stderr, returncode = Popen.run(cmd, timeout=self.options['timeout'] / 1000,
+ text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ except Exception as e:
+ raise ExtractorError(f'{note} failed: Unable to run PhantomJS binary', cause=e)
if returncode:
- raise ExtractorError(f'Executing JS failed:\n{stderr.strip()}')
+ raise ExtractorError(f'{note} failed:\n{stderr.strip()}')
return stdout
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py
index 5a19b591a..e9f8adbd1 100644
--- a/yt_dlp/extractor/youtube.py
+++ b/yt_dlp/extractor/youtube.py
@@ -2630,7 +2630,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
ret = extract_nsig(jsi, func_code)(s)
except JSInterpreter.Exception as e:
try:
- jsi = PhantomJSwrapper(self)
+ jsi = PhantomJSwrapper(self, timeout=5000)
except ExtractorError:
raise e
self.report_warning(
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index 49ee22865..13768d846 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -860,9 +860,9 @@ class Popen(subprocess.Popen):
self.wait(timeout=timeout)
@classmethod
- def run(cls, *args, **kwargs):
+ def run(cls, *args, timeout=None, **kwargs):
with cls(*args, **kwargs) as proc:
- stdout, stderr = proc.communicate_or_kill()
+ stdout, stderr = proc.communicate_or_kill(timeout=timeout)
return stdout or '', stderr or '', proc.returncode