mirror of
https://github.com/younesaassila/ttv-lol-pro.git
synced 2025-05-08 10:24:29 +02:00
Improve code
This commit is contained in:
parent
c91fe0bd90
commit
cf765d8c2b
@ -407,6 +407,7 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
usherHostRegex.test(host) &&
|
usherHostRegex.test(host) &&
|
||||||
response.status < 400
|
response.status < 400
|
||||||
) {
|
) {
|
||||||
|
//#region Usher responses.
|
||||||
const isLivestream = !url.includes("/vod/");
|
const isLivestream = !url.includes("/vod/");
|
||||||
const isFrontpage = url.includes(
|
const isFrontpage = url.includes(
|
||||||
encodeURIComponent('"player_type":"frontpage"')
|
encodeURIComponent('"player_type":"frontpage"')
|
||||||
@ -446,6 +447,7 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
proxyCountry:
|
proxyCountry:
|
||||||
/USER-COUNTRY="([A-Z]+)"/i.exec(responseBody)?.[1] || undefined,
|
/USER-COUNTRY="([A-Z]+)"/i.exec(responseBody)?.[1] || undefined,
|
||||||
});
|
});
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
// Twitch Video Weaver responses.
|
// Twitch Video Weaver responses.
|
||||||
@ -454,6 +456,7 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
videoWeaverHostRegex.test(host) &&
|
videoWeaverHostRegex.test(host) &&
|
||||||
response.status < 400
|
response.status < 400
|
||||||
) {
|
) {
|
||||||
|
//#region Video Weaver responses.
|
||||||
const manifest = usherManifests.find(manifest =>
|
const manifest = usherManifests.find(manifest =>
|
||||||
[...manifest.assignedMap.values()].includes(url)
|
[...manifest.assignedMap.values()].includes(url)
|
||||||
);
|
);
|
||||||
@ -466,27 +469,23 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
|
|
||||||
// Check if response contains midroll ad.
|
// Check if response contains midroll ad.
|
||||||
responseBody ??= await readResponseBody();
|
responseBody ??= await readResponseBody();
|
||||||
|
const responseBodyLower = responseBody.toLowerCase();
|
||||||
if (
|
if (
|
||||||
responseBody.includes("stitched-ad") &&
|
responseBodyLower.includes("stitched-ad") &&
|
||||||
responseBody.toLowerCase().includes("midroll")
|
responseBodyLower.includes("midroll")
|
||||||
) {
|
) {
|
||||||
console.log("[TTV LOL PRO] Midroll ad detected.");
|
console.log("[TTV LOL PRO] Midroll ad detected.");
|
||||||
manifest.consecutiveMidrollResponses += 1;
|
manifest.consecutiveMidrollResponses += 1;
|
||||||
manifest.consecutiveMidrollCooldown = 15;
|
manifest.consecutiveMidrollCooldown = 15;
|
||||||
await waitForStore(pageState);
|
const isWhitelisted = isChannelWhitelisted(
|
||||||
const whitelistedChannelsLower =
|
manifest.channelName,
|
||||||
pageState.state?.whitelistedChannels.map(channel =>
|
pageState
|
||||||
channel.toLowerCase()
|
);
|
||||||
);
|
const shouldUpdateReplacementMap =
|
||||||
const isWhitelisted =
|
|
||||||
manifest.channelName != null &&
|
|
||||||
whitelistedChannelsLower != null &&
|
|
||||||
whitelistedChannelsLower.includes(manifest.channelName.toLowerCase());
|
|
||||||
if (
|
|
||||||
pageState.state?.optimizedProxiesEnabled === true &&
|
pageState.state?.optimizedProxiesEnabled === true &&
|
||||||
manifest.consecutiveMidrollResponses <= 2 && // Avoid infinite loop.
|
manifest.consecutiveMidrollResponses <= 2 && // Avoid infinite loop.
|
||||||
!isWhitelisted
|
!isWhitelisted;
|
||||||
) {
|
if (shouldUpdateReplacementMap) {
|
||||||
const success = await updateVideoWeaverReplacementMap(
|
const success = await updateVideoWeaverReplacementMap(
|
||||||
pageState,
|
pageState,
|
||||||
cachedUsherRequestUrl,
|
cachedUsherRequestUrl,
|
||||||
@ -504,6 +503,7 @@ export function getFetch(pageState: PageState): typeof fetch {
|
|||||||
manifest.consecutiveMidrollResponses = 0;
|
manifest.consecutiveMidrollResponses = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user