perf(manifests): decode manifests without charset detection

Parse an MPD from bytes and read every M3U8 playlist as UTF-8 unless the server sent a charset. Fixes mojibake on text/* responses.
This commit is contained in:
imSp4rky
2026-10-13 16:11:13 -06:00
parent 4fbaf2a61a
commit e7bb825def
10 changed files with 114 additions and 48 deletions
+13 -1
View File
@@ -15,7 +15,7 @@ from typing import Any, Optional
from urllib.parse import urlencode, urlparse, urlunparse
import rnet
from requests import HTTPError, Request
from requests import HTTPError, Request, Response
from requests.structures import CaseInsensitiveDict
from unshackle.core.config import config
@@ -227,6 +227,18 @@ class RnetResponse:
pass
def utf8_text(res: Response | RnetResponse) -> str:
"""Return the response text, decoded as UTF-8 unless the server sent a charset.
With no charset, requests assumes ISO-8859-1 for a `text/*` type and runs charset detection
on the full body for any other type. Use this only for a format that is UTF-8 by
specification, such as M3U8.
"""
if isinstance(res, Response) and "charset" not in res.headers.get("content-type", "").lower():
res.encoding = "utf-8"
return res.text
class RnetSessionHeaders(CaseInsensitiveDict):
"""Dict-like headers that write to the rnet client through update()."""