From af2c2b8acf3689914f6563b61dde4e1d06fc106d Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Fri, 24 Oct 2025 19:29:58 -0600 Subject: [PATCH] update chromecast to use new proxy also it was using the wrong proxy before :skull: --- src/components/player/display/chromecast.ts | 45 ++++++++++----------- src/components/player/utils/proxy.ts | 7 +++- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/components/player/display/chromecast.ts b/src/components/player/display/chromecast.ts index f405d68f..d58fb084 100644 --- a/src/components/player/display/chromecast.ts +++ b/src/components/player/display/chromecast.ts @@ -9,7 +9,11 @@ import { DisplayInterfaceEvents, DisplayMeta, } from "@/components/player/display/displayInterface"; -import { conf } from "@/setup/config"; +import { + createM3U8ProxyUrl, + createMP4ProxyUrl, + isUrlAlreadyProxied, +} from "@/components/player/utils/proxy"; import { LoadableSource } from "@/stores/player/utils/qualities"; import { processCdnLink } from "@/utils/cdn"; import { canFullscreen, canFullscreenAnyElement } from "@/utils/detectFeatures"; @@ -113,32 +117,25 @@ export function makeChromecastDisplayInterface( let contentUrl = processCdnLink(source.url); - // When casting HLS, use an enabled M3U8 proxy so the Chromecast device can fetch the manifest + // Only proxy streams if they need it: + // 1. Not already proxied AND + // 2. Has headers (either preferredHeaders or headers) + const allHeaders = { + ...source.preferredHeaders, + ...source.headers, + }; + const hasHeaders = Object.keys(allHeaders).length > 0; + + // Handle HLS streams if (source.type === "hls") { - try { - const all = conf().M3U8_PROXY_URLS; - let enabledMap: Record = {}; - const enabledRaw = localStorage.getItem("m3u8-proxy-enabled"); - if (enabledRaw) { - try { - enabledMap = JSON.parse(enabledRaw) as Record; - } catch { - enabledMap = {}; - } - } - const enabled = all.filter( - (_url, idx) => enabledMap[idx.toString()] !== false, - ); - const list = enabled.length > 0 ? enabled : all; - if (list.length > 0) { - const base = list[Math.floor(Math.random() * list.length)]; - const trimmed = base.endsWith("/") ? base.slice(0, -1) : base; - contentUrl = `${trimmed}/?destination=${encodeURIComponent(contentUrl)}`; - } - } catch { - // If anything goes wrong, fall back to direct URL + if (!isUrlAlreadyProxied(source.url) && hasHeaders) { + contentUrl = createM3U8ProxyUrl(source.url, allHeaders); } } + // Handle MP4 streams with headers + else if (source.type === "mp4" && hasHeaders) { + contentUrl = createMP4ProxyUrl(source.url, source.headers || {}); + } const mediaInfo = new chrome.cast.media.MediaInfo(contentUrl, type); mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED; diff --git a/src/components/player/utils/proxy.ts b/src/components/player/utils/proxy.ts index 649a2db0..03d104fb 100644 --- a/src/components/player/utils/proxy.ts +++ b/src/components/player/utils/proxy.ts @@ -47,11 +47,16 @@ export function createMP4ProxyUrl( * @returns True if the URL is already proxied, false otherwise */ export function isUrlAlreadyProxied(url: string): boolean { - // Check if URL contains the m3u8-proxy pattern + // Check if URL contains the m3u8-proxy pattern (Airplay format) if (url.includes("/m3u8-proxy?url=")) { return true; } + // Check if URL contains the destination pattern (Chromecast format) + if (url.includes("/?destination=")) { + return true; + } + // Also check if URL starts with any of the configured proxy URLs const proxyUrls = getM3U8ProxyUrls(); return proxyUrls.some((proxyUrl) => url.startsWith(proxyUrl));