1
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-03-09 12:50:23 -05:00
This commit is contained in:
c-basalt 2024-08-11 20:05:46 -04:00
parent b58d59ec78
commit f1959b8edf
3 changed files with 6 additions and 6 deletions

View file

@ -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
]

View file

@ -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,

View file

@ -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]