Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.20
1.8.21
27 changes: 22 additions & 5 deletions src/torchlight/FFmpegAudioPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@

SAMPLEBYTES = 2

# Extra request headers some hosts require, keyed by domain. Matched against the URI's
# hostname (exact or subdomain), so a new host means adding an entry here rather than
# another special case inside the streaming path.
DOMAIN_HEADER_PROFILES: dict[str, dict[str, str]] = {
"myinstants.com": {
"Referer": MYINSTANTS_URL,
"Sec-Fetch-Dest": "audio",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
},
}


def get_domain_headers(uri: str) -> dict[str, str]:
hostname = (urlparse(uri).hostname or "").lower()
for domain, headers in DOMAIN_HEADER_PROFILES.items():
if hostname == domain or hostname.endswith(f".{domain}"):
return headers
return {}


class FFmpegAudioPlayer:
VALID_CALLBACKS = ["Play", "Stop", "Update"]
Expand Down Expand Up @@ -120,11 +140,8 @@ async def _stream_url_to_ffmpeg(self, uri: str, ffmpeg_command: list[str], needs
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.9",
}
if needs_cf_bypass and "myinstants.com" in uri:
headers["Referer"] = MYINSTANTS_URL
headers["Sec-Fetch-Dest"] = "audio"
headers["Sec-Fetch-Mode"] = "no-cors"
headers["Sec-Fetch-Site"] = "same-origin"
if needs_cf_bypass:
headers.update(get_domain_headers(uri))

if needs_cf_bypass:
queue: asyncio.Queue[bytes | None] = asyncio.Queue(maxsize=10)
Expand Down
Loading