forked from kenzuya/unshackle
Replace CurlSession (curl_cffi) with RnetSession powered by rnet (Rust/BoringSSL). Benchmarks show 3.5x faster segmented downloads (1.06 GB/s vs 304 MB/s) and 16% faster single-file downloads with near-zero TLS fingerprinting overhead. - Add RnetSession wrapper with requests-compatible API (headers, cookies, proxies, retry logic, prepared requests) - Add RnetResponse wrapper normalizing rnet quirks (status_code as int, text as property, bytes-to-str headers, iter_content re-chunking) - Replace CurlSession isinstance checks across manifests, tracks, DRM - Update downloader with rnet native streaming path and byte-based progress tracking for accurate Rich progress bars - Add speed display column to Rich progress bar (DASH/HLS/URL prefix) - Add rnet dependency, services use exact preset names (e.g. OkHttp4_12)
35 lines
853 B
Python
35 lines
853 B
Python
"""Utility functions for parsing M3U8 playlists."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional, Union
|
|
|
|
import m3u8
|
|
from requests import Session
|
|
|
|
from unshackle.core.manifests.hls import HLS
|
|
from unshackle.core.session import RnetSession
|
|
from unshackle.core.tracks import Tracks
|
|
|
|
|
|
def parse(
|
|
master: m3u8.M3U8,
|
|
language: str,
|
|
*,
|
|
session: Optional[Union[Session, RnetSession]] = None,
|
|
) -> Tracks:
|
|
"""Parse a variant playlist to ``Tracks`` with basic information, defer DRM loading."""
|
|
tracks = HLS(master, session=session).to_tracks(language)
|
|
|
|
bool(master.session_keys or HLS.parse_session_data_keys(master, session or Session()))
|
|
|
|
if True:
|
|
for t in tracks.videos + tracks.audio:
|
|
t.needs_drm_loading = True
|
|
t.session = session
|
|
|
|
return tracks
|
|
|
|
|
|
__all__ = ["parse"]
|