[cleanup] Misc

This commit is contained in:
pukkandan 2023-07-30 03:36:17 +05:30
parent 8cb7fc44db
commit 6148833f5c
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
10 changed files with 27 additions and 25 deletions

View File

@ -831,6 +831,7 @@ def expect_same_infodict(out):
test('%(id&hi {:>10} {}|)s', 'hi 1234 1234') test('%(id&hi {:>10} {}|)s', 'hi 1234 1234')
test(R'%(id&{0} {}|)s', 'NA') test(R'%(id&{0} {}|)s', 'NA')
test(R'%(id&{0.1}|)s', 'NA') test(R'%(id&{0.1}|)s', 'NA')
test('%(height&{:,d})S', '1,080')
# Laziness # Laziness
def gen(): def gen():

View File

@ -29,6 +29,7 @@
from http.cookiejar import CookieJar from http.cookiejar import CookieJar
from test.helper import FakeYDL, http_server_port from test.helper import FakeYDL, http_server_port
from yt_dlp.cookies import YoutubeDLCookieJar
from yt_dlp.dependencies import brotli from yt_dlp.dependencies import brotli
from yt_dlp.networking import ( from yt_dlp.networking import (
HEADRequest, HEADRequest,
@ -478,7 +479,7 @@ def test_request_cookie_header(self, handler):
assert 'Cookie: test=test' not in res assert 'Cookie: test=test' not in res
# Specified Cookie header should override global cookiejar for that request # Specified Cookie header should override global cookiejar for that request
cookiejar = http.cookiejar.CookieJar() cookiejar = YoutubeDLCookieJar()
cookiejar.set_cookie(http.cookiejar.Cookie( cookiejar.set_cookie(http.cookiejar.Cookie(
version=0, name='test', value='ytdlp', port=None, port_specified=False, version=0, name='test', value='ytdlp', port=None, port_specified=False,
domain='127.0.0.1', domain_specified=True, domain_initial_dot=False, path='/', domain='127.0.0.1', domain_specified=True, domain_initial_dot=False, path='/',
@ -505,7 +506,7 @@ def test_incompleteread(self, handler):
@pytest.mark.parametrize('handler', ['Urllib'], indirect=True) @pytest.mark.parametrize('handler', ['Urllib'], indirect=True)
def test_cookies(self, handler): def test_cookies(self, handler):
cookiejar = http.cookiejar.CookieJar() cookiejar = YoutubeDLCookieJar()
cookiejar.set_cookie(http.cookiejar.Cookie( cookiejar.set_cookie(http.cookiejar.Cookie(
0, 'test', 'ytdlp', None, False, '127.0.0.1', True, 0, 'test', 'ytdlp', None, False, '127.0.0.1', True,
False, '/headers', True, False, None, False, None, None, {})) False, '/headers', True, False, None, False, None, None, {}))
@ -903,7 +904,8 @@ class HTTPSupportedRH(ValidationRH):
EXTENSION_TESTS = [ EXTENSION_TESTS = [
('Urllib', [ ('Urllib', [
({'cookiejar': 'notacookiejar'}, AssertionError), ({'cookiejar': 'notacookiejar'}, AssertionError),
({'cookiejar': CookieJar()}, False), ({'cookiejar': YoutubeDLCookieJar()}, False),
({'cookiejar': CookieJar()}, AssertionError),
({'timeout': 1}, False), ({'timeout': 1}, False),
({'timeout': 'notatimeout'}, AssertionError), ({'timeout': 'notatimeout'}, AssertionError),
({'unsupported': 'value'}, UnsupportedRequest), ({'unsupported': 'value'}, UnsupportedRequest),

View File

@ -256,8 +256,6 @@ class YoutubeDL:
overwrites: Overwrite all video and metadata files if True, overwrites: Overwrite all video and metadata files if True,
overwrite only non-video files if None overwrite only non-video files if None
and don't overwrite any file if False and don't overwrite any file if False
For compatibility with youtube-dl,
"nooverwrites" may also be used instead
playlist_items: Specific indices of playlist to download. playlist_items: Specific indices of playlist to download.
playlistrandom: Download playlist items in random order. playlistrandom: Download playlist items in random order.
lazy_playlist: Process playlist entries as they are received. lazy_playlist: Process playlist entries as they are received.
@ -553,6 +551,7 @@ class YoutubeDL:
You can reduce network I/O by disabling it if you don't You can reduce network I/O by disabling it if you don't
care about HLS. (only for youtube) care about HLS. (only for youtube)
no_color: Same as `color='no_color'` no_color: Same as `color='no_color'`
no_overwrites: Same as `overwrites=False`
""" """
_NUMERIC_FIELDS = { _NUMERIC_FIELDS = {
@ -604,6 +603,7 @@ def __init__(self, params=None, auto_init=True):
self._playlist_level = 0 self._playlist_level = 0
self._playlist_urls = set() self._playlist_urls = set()
self.cache = Cache(self) self.cache = Cache(self)
self.__header_cookies = []
stdout = sys.stderr if self.params.get('logtostderr') else sys.stdout stdout = sys.stderr if self.params.get('logtostderr') else sys.stdout
self._out_files = Namespace( self._out_files = Namespace(
@ -632,7 +632,7 @@ def process_color_policy(stream):
policy = traverse_obj(self.params, ('color', (stream_name, None), {str}), get_all=False) policy = traverse_obj(self.params, ('color', (stream_name, None), {str}), get_all=False)
if policy in ('auto', None): if policy in ('auto', None):
return term_allow_color and supports_terminal_sequences(stream) return term_allow_color and supports_terminal_sequences(stream)
assert policy in ('always', 'never', 'no_color') assert policy in ('always', 'never', 'no_color'), policy
return {'always': True, 'never': False}.get(policy, policy) return {'always': True, 'never': False}.get(policy, policy)
self._allow_colors = Namespace(**{ self._allow_colors = Namespace(**{
@ -681,12 +681,10 @@ def process_color_policy(stream):
self.params['compat_opts'] = set(self.params.get('compat_opts', ())) self.params['compat_opts'] = set(self.params.get('compat_opts', ()))
self.params['http_headers'] = HTTPHeaderDict(std_headers, self.params.get('http_headers')) self.params['http_headers'] = HTTPHeaderDict(std_headers, self.params.get('http_headers'))
self.__header_cookies = []
self._load_cookies(self.params['http_headers'].get('Cookie')) # compat self._load_cookies(self.params['http_headers'].get('Cookie')) # compat
self.params['http_headers'].pop('Cookie', None) self.params['http_headers'].pop('Cookie', None)
self._request_director = self.build_request_director(_REQUEST_HANDLERS.values())
self._request_director = self.build_request_director(
sorted(_REQUEST_HANDLERS.values(), key=lambda rh: rh.RH_NAME.lower()))
if auto_init and auto_init != 'no_verbose_header': if auto_init and auto_init != 'no_verbose_header':
self.print_debug_header() self.print_debug_header()
@ -3977,7 +3975,7 @@ def get_encoding(stream):
})) or 'none')) })) or 'none'))
write_debug(f'Proxy map: {self.proxies}') write_debug(f'Proxy map: {self.proxies}')
# write_debug(f'Request Handlers: {", ".join(rh.RH_NAME for rh in self._request_director.handlers)}') # write_debug(f'Request Handlers: {", ".join(rh.RH_NAME for rh in self._request_director.handlers.values())}')
for plugin_type, plugins in {'Extractor': plugin_ies, 'Post-Processor': plugin_pps}.items(): for plugin_type, plugins in {'Extractor': plugin_ies, 'Post-Processor': plugin_pps}.items():
display_list = ['%s%s' % ( display_list = ['%s%s' % (
klass.__name__, '' if klass.__name__ == name else f' as {name}') klass.__name__, '' if klass.__name__ == name else f' as {name}')
@ -4080,7 +4078,7 @@ def urlopen(self, req):
def build_request_director(self, handlers): def build_request_director(self, handlers):
logger = _YDLLogger(self) logger = _YDLLogger(self)
headers = self.params.get('http_headers').copy() headers = self.params['http_headers'].copy()
proxies = self.proxies.copy() proxies = self.proxies.copy()
clean_headers(headers) clean_headers(headers)
clean_proxies(proxies, headers) clean_proxies(proxies, headers)

View File

@ -729,7 +729,7 @@ def extract(self, url):
except UnsupportedError: except UnsupportedError:
raise raise
except ExtractorError as e: except ExtractorError as e:
e.video_id = e.video_id or self.get_temp_id(url), e.video_id = e.video_id or self.get_temp_id(url)
e.ie = e.ie or self.IE_NAME, e.ie = e.ie or self.IE_NAME,
e.traceback = e.traceback or sys.exc_info()[2] e.traceback = e.traceback or sys.exc_info()[2]
raise raise

View File

@ -248,9 +248,9 @@ def _real_extract(self, url):
# GET request to v3 API returns original video/audio file if available # GET request to v3 API returns original video/audio file if available
direct_url = re.sub(r'/api/v\d+/', '/api/v3/', streaming_url) direct_url = re.sub(r'/api/v\d+/', '/api/v3/', streaming_url)
ext = urlhandle_detect_ext(self._request_webpage( urlh = self._request_webpage(
direct_url, display_id, 'Checking for original quality', headers=headers)) direct_url, display_id, 'Checking for original quality', headers=headers, fatal=False)
if ext != 'm3u8': if urlh and urlhandle_detect_ext(urlh) != 'm3u8':
formats.append({ formats.append({
'url': direct_url, 'url': direct_url,
'format_id': 'original', 'format_id': 'original',

View File

@ -765,7 +765,7 @@ def _extract_common_meta(self, stream_info):
class VKPlayIE(VKPlayBaseIE): class VKPlayIE(VKPlayBaseIE):
_VALID_URL = r'https?://vkplay\.live/(?P<username>[^/]+)/record/(?P<id>[a-f0-9\-]+)' _VALID_URL = r'https?://vkplay\.live/(?P<username>[^/#?]+)/record/(?P<id>[a-f0-9-]+)'
_TESTS = [{ _TESTS = [{
'url': 'https://vkplay.live/zitsmann/record/f5e6e3b5-dc52-4d14-965d-0680dd2882da', 'url': 'https://vkplay.live/zitsmann/record/f5e6e3b5-dc52-4d14-965d-0680dd2882da',
'info_dict': { 'info_dict': {
@ -802,7 +802,7 @@ def _real_extract(self, url):
class VKPlayLiveIE(VKPlayBaseIE): class VKPlayLiveIE(VKPlayBaseIE):
_VALID_URL = r'https?://vkplay\.live/(?P<id>[^/]+)/?(?:[#?]|$)' _VALID_URL = r'https?://vkplay\.live/(?P<id>[^/#?]+)/?(?:[#?]|$)'
_TESTS = [{ _TESTS = [{
'url': 'https://vkplay.live/bayda', 'url': 'https://vkplay.live/bayda',
'info_dict': { 'info_dict': {

View File

@ -6,7 +6,7 @@
class WimbledonIE(InfoExtractor): class WimbledonIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?wimbledon\.com/\w+/video/media/(?P<id>\d+).html' _VALID_URL = r'https?://(?:www\.)?wimbledon\.com/\w+/video/media/(?P<id>\d+)\.html'
_TESTS = [{ _TESTS = [{
'url': 'https://www.wimbledon.com/en_GB/video/media/6330247525112.html', 'url': 'https://www.wimbledon.com/en_GB/video/media/6330247525112.html',
'info_dict': { 'info_dict': {

View File

@ -12,7 +12,6 @@
from collections.abc import Iterable, Mapping from collections.abc import Iterable, Mapping
from email.message import Message from email.message import Message
from http import HTTPStatus from http import HTTPStatus
from http.cookiejar import CookieJar
from ._helper import make_ssl_context, wrap_request_errors from ._helper import make_ssl_context, wrap_request_errors
from .exceptions import ( from .exceptions import (
@ -22,6 +21,7 @@
UnsupportedRequest, UnsupportedRequest,
) )
from ..compat.types import NoneType from ..compat.types import NoneType
from ..cookies import YoutubeDLCookieJar
from ..utils import ( from ..utils import (
bug_reports_message, bug_reports_message,
classproperty, classproperty,
@ -194,7 +194,7 @@ def __init__(
self, *, self, *,
logger, # TODO(Grub4k): default logger logger, # TODO(Grub4k): default logger
headers: HTTPHeaderDict = None, headers: HTTPHeaderDict = None,
cookiejar: CookieJar = None, cookiejar: YoutubeDLCookieJar = None,
timeout: float | int | None = None, timeout: float | int | None = None,
proxies: dict = None, proxies: dict = None,
source_address: str = None, source_address: str = None,
@ -208,7 +208,7 @@ def __init__(
self._logger = logger self._logger = logger
self.headers = headers or {} self.headers = headers or {}
self.cookiejar = cookiejar if cookiejar is not None else CookieJar() self.cookiejar = cookiejar if cookiejar is not None else YoutubeDLCookieJar()
self.timeout = float(timeout or 20) self.timeout = float(timeout or 20)
self.proxies = proxies or {} self.proxies = proxies or {}
self.source_address = source_address self.source_address = source_address
@ -275,7 +275,7 @@ def _check_proxies(self, proxies):
def _check_extensions(self, extensions): def _check_extensions(self, extensions):
"""Check extensions for unsupported extensions. Subclasses should extend this.""" """Check extensions for unsupported extensions. Subclasses should extend this."""
assert isinstance(extensions.get('cookiejar'), (CookieJar, NoneType)) assert isinstance(extensions.get('cookiejar'), (YoutubeDLCookieJar, NoneType))
assert isinstance(extensions.get('timeout'), (float, int, NoneType)) assert isinstance(extensions.get('timeout'), (float, int, NoneType))
def _validate(self, request): def _validate(self, request):
@ -302,6 +302,7 @@ def send(self, request: Request) -> Response:
@abc.abstractmethod @abc.abstractmethod
def _send(self, request: Request): def _send(self, request: Request):
"""Handle a request from start to finish. Redefine in subclasses.""" """Handle a request from start to finish. Redefine in subclasses."""
pass
def close(self): def close(self):
pass pass