diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-16 02:25:43 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-16 06:23:50 +0530 |
commit | f0c9fb96827ff798a48626e7e5d32a9c5de7b97e (patch) | |
tree | 440139f107fb95d967f5ff32361a194e4e5afd22 /yt_dlp/extractor/openload.py | |
parent | 560738f34de4df6eaf82290fd503def3f366f878 (diff) | |
download | hypervideo-pre-f0c9fb96827ff798a48626e7e5d32a9c5de7b97e.tar.lz hypervideo-pre-f0c9fb96827ff798a48626e7e5d32a9c5de7b97e.tar.xz hypervideo-pre-f0c9fb96827ff798a48626e7e5d32a9c5de7b97e.zip |
[utils] `Popen`: Refactor to use contextmanager
Fixes https://github.com/yt-dlp/yt-dlp/issues/3531#issuecomment-1156223597
Diffstat (limited to 'yt_dlp/extractor/openload.py')
-rw-r--r-- | yt_dlp/extractor/openload.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/yt_dlp/extractor/openload.py b/yt_dlp/extractor/openload.py index 61e3a8b86..d987cd927 100644 --- a/yt_dlp/extractor/openload.py +++ b/yt_dlp/extractor/openload.py @@ -9,7 +9,6 @@ from ..utils import ( ExtractorError, Popen, check_executable, - encodeArgument, get_exe_version, is_outdated_version, ) @@ -213,16 +212,14 @@ class PhantomJSwrapper: else: self.extractor.to_screen(f'{video_id}: {note2}') - p = Popen( + stdout, stderr, returncode = Popen.run( [self.exe, '--ssl-protocol=any', self._TMP_FILES['script'].name], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate_or_kill() - if p.returncode != 0: - raise ExtractorError( - 'Executing JS failed\n:' + encodeArgument(err)) + text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if returncode: + raise ExtractorError(f'Executing JS failed\n:{stderr}') with open(self._TMP_FILES['html'].name, 'rb') as f: html = f.read().decode('utf-8') self._load_cookies() - return (html, encodeArgument(out)) + return (html, stdout) |