refactor(ClearKey): Only use User-Agent if none set in from_m3u_key

This commit is contained in:
rlaphoenix 2024-03-08 15:45:52 +00:00
parent e0aa0e37d3
commit ccac55897c
1 changed files with 5 additions and 6 deletions

View File

@ -81,6 +81,10 @@ class ClearKey:
if not session:
session = Session()
if not session.headers.get("User-Agent"):
# commonly needed default for HLS playlists
session.headers["User-Agent"] = "smartexoplayer/1.1.0 (Linux;Android 8.0.0) ExoPlayerLib/2.13.3"
if m3u_key.uri.startswith("data:"):
media_types, data = m3u_key.uri[5:].split(",")
media_types = media_types.split(";")
@ -89,12 +93,7 @@ class ClearKey:
key = data
else:
url = urljoin(m3u_key.base_uri, m3u_key.uri)
res = session.get(
url=url,
headers={
"User-Agent": "smartexoplayer/1.1.0 (Linux;Android 8.0.0) ExoPlayerLib/2.13.3"
}
)
res = session.get(url)
res.raise_for_status()
if not res.content:
raise EOFError("Unexpected Empty Response by M3U Key URI.")