From f1959b8edfabdb08288ce4a3e61bc73d51ff49ac Mon Sep 17 00:00:00 2001 From: c-basalt <117849907+c-basalt@users.noreply.github.com> Date: Sun, 11 Aug 2024 20:05:46 -0400 Subject: [PATCH] ruff --- pyproject.toml | 2 +- yt_dlp/extractor/youtube.py | 3 +-- yt_dlp/jsinterp/external.py | 7 ++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d5480e1c6..3af462856 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -263,7 +263,7 @@ select = [ "A002", # builtin-argument-shadowing "C408", # unnecessary-collection-call ] -"yt_dlp/jsinterp.py" = [ +"yt_dlp/jsinterp/native.py" = [ "UP031", # printf-string-formatting ] diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index ac0513834..e3928b304 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -20,8 +20,7 @@ import urllib.parse from .common import InfoExtractor, SearchInfoExtractor -from ..jsinterp import PhantomJSwrapper -from ..jsinterp import NativeJSI +from ..jsinterp import NativeJSI, PhantomJSwrapper from ..networking.exceptions import HTTPError, network_exceptions from ..utils import ( NO_DEFAULT, diff --git a/yt_dlp/jsinterp/external.py b/yt_dlp/jsinterp/external.py index 3751941c8..b3cc88d6d 100644 --- a/yt_dlp/jsinterp/external.py +++ b/yt_dlp/jsinterp/external.py @@ -48,6 +48,7 @@ def cookie_jar_to_list(cookie_jar): class TempFileWrapper: + """Wrapper for NamedTemporaryFile, auto closes file after io and deletes file upon wrapper object gc""" def __init__(self, content=None, text=True, encoding='utf-8', suffix=None): self.encoding = None if not text else encoding self.text = text @@ -70,11 +71,11 @@ def opened_file(self, mode, *, seek=None, seek_whence=0): def write(self, s, seek=None, seek_whence=0): with self.opened_file('w', seek=seek, seek_whence=seek_whence) as f: - f.write(s) + return f.write(s) def append_write(self, s, seek=None, seek_whence=0): with self.opened_file('a', seek=seek, seek_whence=seek_whence) as f: - f.write(s) + return f.write(s) def read(self, n=-1, seek=None, seek_whence=0): with self.opened_file('r', seek=seek, seek_whence=seek_whence) as f: @@ -123,7 +124,7 @@ def __init__(self, extractor: InfoExtractor, required_version=None, timeout=1000 @classmethod def _execute(cls, jscode, extractor=None, video_id=None, note='', flags=[], timeout=10000): - js_file = TempFileWrapper(jscode) + js_file = TempFileWrapper(jscode, suffix='.js') if note and extractor: extractor.to_screen(f'{format_field(video_id, None, "%s: ")}{note}') cmd = [cls.exe, 'run', *flags, js_file.name]