mirror of
https://github.com/younesaassila/ttv-lol-pro.git
synced 2025-05-09 02:44:29 +02:00
Optimize first request to Usher manifest
This commit is contained in:
parent
586bad2889
commit
87d063ae34
@ -20,7 +20,7 @@ const NATIVE_FETCH = self.fetch;
|
|||||||
|
|
||||||
export function getFetch(pageState: PageState): typeof fetch {
|
export function getFetch(pageState: PageState): typeof fetch {
|
||||||
let usherManifests: UsherManifest[] = [];
|
let usherManifests: UsherManifest[] = [];
|
||||||
let videoWeaverUrlsProxiedCount = new Map<string, number>(); // Used to count how many times each Video Weaver URL was proxied.
|
let fallbackProxiedCount = new Map<string, number>(); // Used to count how many times each Video Weaver URL was proxied.
|
||||||
|
|
||||||
let cachedPlaybackTokenRequestHeaders: Map<string, string> | null = null; // Cached by page script.
|
let cachedPlaybackTokenRequestHeaders: Map<string, string> | null = null; // Cached by page script.
|
||||||
let cachedPlaybackTokenRequestBody: string | null = null; // Cached by page script.
|
let cachedPlaybackTokenRequestBody: string | null = null; // Cached by page script.
|
||||||
@ -293,12 +293,29 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
|
|
||||||
// TODO: Use isRequestTypeProxied().
|
// TODO: Use isRequestTypeProxied().
|
||||||
|
|
||||||
// TODO: Possible optimization: only proxy first request to weaver group (i.e. usher manifest).
|
let proxiedCount = 0;
|
||||||
// This is great for users using "Auto" quality.
|
if (manifest != null) {
|
||||||
// Flag first request to each Video Weaver URL.
|
proxiedCount =
|
||||||
const proxiedCount = videoWeaverUrlsProxiedCount.get(videoWeaverUrl) ?? 0;
|
videoWeaverUrl !== url
|
||||||
|
? manifest.replacementProxiedCount
|
||||||
|
: manifest.assignedProxiedCount;
|
||||||
|
} else {
|
||||||
|
proxiedCount = fallbackProxiedCount.get(videoWeaverUrl) ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag first request to each Usher manifest (fallback to Video Weaver URL).
|
||||||
if (proxiedCount < 1) {
|
if (proxiedCount < 1) {
|
||||||
videoWeaverUrlsProxiedCount.set(videoWeaverUrl, proxiedCount + 1);
|
if (manifest != null) {
|
||||||
|
if (videoWeaverUrl !== url) {
|
||||||
|
manifest.replacementProxiedCount += 1;
|
||||||
|
} else {
|
||||||
|
manifest.assignedProxiedCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fallbackProxiedCount.set(
|
||||||
|
videoWeaverUrl,
|
||||||
|
(fallbackProxiedCount.get(videoWeaverUrl) ?? 0) + 1
|
||||||
|
);
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#using_options
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#using_options
|
||||||
const pr = new Intl.PluralRules("en-US", { type: "ordinal" });
|
const pr = new Intl.PluralRules("en-US", { type: "ordinal" });
|
||||||
const suffixes = new Map([
|
const suffixes = new Map([
|
||||||
@ -378,6 +395,8 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
channelName,
|
channelName,
|
||||||
assignedMap: assignedMap,
|
assignedMap: assignedMap,
|
||||||
replacementMap: null,
|
replacementMap: null,
|
||||||
|
assignedProxiedCount: 0,
|
||||||
|
replacementProxiedCount: 0,
|
||||||
consecutiveMidrollResponses: 0,
|
consecutiveMidrollResponses: 0,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -385,7 +404,6 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
}
|
}
|
||||||
// Send Video Weaver URLs to content script.
|
// Send Video Weaver URLs to content script.
|
||||||
const videoWeaverUrls = [...(assignedMap?.values() ?? [])];
|
const videoWeaverUrls = [...(assignedMap?.values() ?? [])];
|
||||||
videoWeaverUrls.forEach(url => videoWeaverUrlsProxiedCount.delete(url)); // Shouldn't be necessary, but just in case.
|
|
||||||
sendMessageToContentScript({
|
sendMessageToContentScript({
|
||||||
type: MessageType.UsherResponse,
|
type: MessageType.UsherResponse,
|
||||||
channel: channelName,
|
channel: channelName,
|
||||||
|
@ -11,6 +11,8 @@ export interface UsherManifest {
|
|||||||
channelName: string | null;
|
channelName: string | null;
|
||||||
assignedMap: Map<string, string>; // E.g. "720p60" -> "https://video-weaver.fra02.hls.ttvnw.net/v1/playlist/..."
|
assignedMap: Map<string, string>; // E.g. "720p60" -> "https://video-weaver.fra02.hls.ttvnw.net/v1/playlist/..."
|
||||||
replacementMap: Map<string, string> | null; // Same as above, but with new URLs.
|
replacementMap: Map<string, string> | null; // Same as above, but with new URLs.
|
||||||
|
assignedProxiedCount: number; // Used to proxy only a certain amount of requests.
|
||||||
|
replacementProxiedCount: number; // Same as above, but with replacement URLs.
|
||||||
consecutiveMidrollResponses: number; // Used to avoid infinite loops.
|
consecutiveMidrollResponses: number; // Used to avoid infinite loops.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user