forked from kenzuya/unshackle
fix(proxy): keep service traffic on --proxy and warn about requests that bypass it
--proxy now overrides HTTP(S)_PROXY and the Windows system proxy while keeping the env CA bundle. Core fallback sessions use the run's proxy, and a warn-only audit hook names service code that sends a request or opens a raw socket outside the proxy; a session with proxy_exempt = True opts out.
This commit is contained in:
@@ -41,6 +41,7 @@ from unshackle.core.session import RnetResponse, RnetSession, utf8_text
|
||||
from unshackle.core.tracks import Audio, DownloadContext, Subtitle, Tracks, Video, resume
|
||||
from unshackle.core.tracks.track import DRM_PREFERENCE_TYPES, assert_fragments_decrypted
|
||||
from unshackle.core.utilities import get_extension, is_close_match, log_event, try_ensure_utf8
|
||||
from unshackle.core.utils import run_proxy
|
||||
from unshackle.core.utils.redact import safe_display_url
|
||||
from unshackle.core.utils.subprocess import log_tool_run
|
||||
|
||||
@@ -63,7 +64,7 @@ class HLS:
|
||||
raise ValueError("Expected the M3U(8) manifest to be a Variant Playlist.")
|
||||
|
||||
self.manifest = manifest
|
||||
self.session = session or Session()
|
||||
self.session = session or run_proxy.fallback_session()
|
||||
self.url = url
|
||||
self.raw_text = raw_text
|
||||
|
||||
@@ -75,7 +76,7 @@ class HLS:
|
||||
raise TypeError(f"Expected url to be a {str}, not {url!r}")
|
||||
|
||||
if not session:
|
||||
session = Session()
|
||||
session = run_proxy.fallback_session()
|
||||
elif not isinstance(session, (Session, RnetSession)):
|
||||
raise TypeError(f"Expected session to be a {Session} or {RnetSession}, not {session!r}")
|
||||
|
||||
@@ -388,7 +389,7 @@ class HLS:
|
||||
) -> Optional[tuple[int, int, Video.Codec]]:
|
||||
"""Probe the first TS segment of a variant playlist to extract resolution and codec."""
|
||||
if not session:
|
||||
session = Session()
|
||||
session = run_proxy.fallback_session()
|
||||
|
||||
res = session.get(variant_url)
|
||||
variant = m3u8.loads(utf8_text(res), uri=variant_url)
|
||||
@@ -1372,7 +1373,7 @@ class HLS:
|
||||
value = getattr(data, "value", None)
|
||||
if not value and data.uri:
|
||||
if not session:
|
||||
session = Session()
|
||||
session = run_proxy.fallback_session()
|
||||
value = utf8_text(session.get(urljoin(manifest.base_uri or "", data.uri)))
|
||||
|
||||
if not value:
|
||||
@@ -1561,7 +1562,7 @@ class HLS:
|
||||
if not isinstance(session, (Session, RnetSession, type(None))):
|
||||
raise TypeError(f"Expected session to be a {Session} or {RnetSession}, not {type(session)}")
|
||||
if not session:
|
||||
session = Session()
|
||||
session = run_proxy.fallback_session()
|
||||
|
||||
# TODO: Add support for 'SAMPLE-AES', 'AES-CTR', 'AES-CBC', 'ClearKey'
|
||||
if key.method == "AES-128":
|
||||
@@ -1609,7 +1610,7 @@ class HLS:
|
||||
try:
|
||||
return HLS.get_drm(key, session)
|
||||
except Widevine.Exceptions.KIDNotFound:
|
||||
kid = HLS.get_track_kid_from_init(master, track, probe_session or session or Session(), init_section)
|
||||
kid = HLS.get_track_kid_from_init(master, track, probe_session or session or run_proxy.fallback_session(), init_section)
|
||||
if not kid:
|
||||
raise
|
||||
return HLS.get_drm(key, session, kid=kid)
|
||||
|
||||
Reference in New Issue
Block a user