mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
ruff
This commit is contained in:
parent
b58d59ec78
commit
f1959b8edf
3 changed files with 6 additions and 6 deletions
|
@ -263,7 +263,7 @@ select = [
|
||||||
"A002", # builtin-argument-shadowing
|
"A002", # builtin-argument-shadowing
|
||||||
"C408", # unnecessary-collection-call
|
"C408", # unnecessary-collection-call
|
||||||
]
|
]
|
||||||
"yt_dlp/jsinterp.py" = [
|
"yt_dlp/jsinterp/native.py" = [
|
||||||
"UP031", # printf-string-formatting
|
"UP031", # printf-string-formatting
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from .common import InfoExtractor, SearchInfoExtractor
|
from .common import InfoExtractor, SearchInfoExtractor
|
||||||
from ..jsinterp import PhantomJSwrapper
|
from ..jsinterp import NativeJSI, PhantomJSwrapper
|
||||||
from ..jsinterp import NativeJSI
|
|
||||||
from ..networking.exceptions import HTTPError, network_exceptions
|
from ..networking.exceptions import HTTPError, network_exceptions
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
NO_DEFAULT,
|
NO_DEFAULT,
|
||||||
|
|
|
@ -48,6 +48,7 @@ def cookie_jar_to_list(cookie_jar):
|
||||||
|
|
||||||
|
|
||||||
class TempFileWrapper:
|
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):
|
def __init__(self, content=None, text=True, encoding='utf-8', suffix=None):
|
||||||
self.encoding = None if not text else encoding
|
self.encoding = None if not text else encoding
|
||||||
self.text = text
|
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):
|
def write(self, s, seek=None, seek_whence=0):
|
||||||
with self.opened_file('w', seek=seek, seek_whence=seek_whence) as f:
|
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):
|
def append_write(self, s, seek=None, seek_whence=0):
|
||||||
with self.opened_file('a', seek=seek, seek_whence=seek_whence) as f:
|
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):
|
def read(self, n=-1, seek=None, seek_whence=0):
|
||||||
with self.opened_file('r', seek=seek, seek_whence=seek_whence) as f:
|
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
|
@classmethod
|
||||||
def _execute(cls, jscode, extractor=None, video_id=None, note='', flags=[], timeout=10000):
|
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:
|
if note and extractor:
|
||||||
extractor.to_screen(f'{format_field(video_id, None, "%s: ")}{note}')
|
extractor.to_screen(f'{format_field(video_id, None, "%s: ")}{note}')
|
||||||
cmd = [cls.exe, 'run', *flags, js_file.name]
|
cmd = [cls.exe, 'run', *flags, js_file.name]
|
||||||
|
|
Loading…
Reference in a new issue