Fix video-swap-new error 1000 on midrolls #228 #259

This commit is contained in:
pixeltris 2024-06-15 10:12:43 +01:00
parent 8632ee23ad
commit 644ac7a821
2 changed files with 33 additions and 13 deletions

View File

@ -172,15 +172,18 @@ twitch-videoad.js text/javascript
} }
} }
} }
if (streamInfo.BackupEncodings == null) {
return '';
}
} else if (haveAdTags) { } else if (haveAdTags) {
onFoundAd(streamInfo, textStr, true); onFoundAd(streamInfo, textStr, true);
return '';
} else { } else {
postMessage({key:'UboHideAdBanner'}); postMessage({key:'UboHideAdBanner'});
} }
if (haveAdTags && streamInfo.BackupEncodings != null) {
var streamM3u8Url = streamInfo.BackupEncodings.match(/^https:.*\.m3u8$/m)[0];
var streamM3u8Response = await realFetch(streamM3u8Url);
if (streamM3u8Response.status == 200) {
textStr = await streamM3u8Response.text();
}
}
return textStr; return textStr;
} }
function hookWorkerFetch() { function hookWorkerFetch() {
@ -193,7 +196,11 @@ twitch-videoad.js text/javascript
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var processAfter = async function(response) { var processAfter = async function(response) {
var str = await processM3U8(url, await response.text(), realFetch); var str = await processM3U8(url, await response.text(), realFetch);
resolve(new Response(str)); resolve(new Response(str, {
status: response.status,
statusText: response.statusText,
headers: response.headers
}));
}; };
var send = function() { var send = function() {
return realFetch(url, options).then(function(response) { return realFetch(url, options).then(function(response) {
@ -220,7 +227,10 @@ twitch-videoad.js text/javascript
// - First m3u8 request is the m3u8 with the video encodings (360p,480p,720p,etc). // - First m3u8 request is the m3u8 with the video encodings (360p,480p,720p,etc).
// - Second m3u8 request is the m3u8 for the given encoding obtained in the first request. At this point we will know if there's ads. // - Second m3u8 request is the m3u8 for the given encoding obtained in the first request. At this point we will know if there's ads.
var streamInfo = StreamInfos[channelName]; var streamInfo = StreamInfos[channelName];
var useBackupStream = false; if (streamInfo != null && streamInfo.Encodings != null && (await realFetch(streamInfo.Encodings.match(/^https:.*\.m3u8$/m)[0])).status !== 200) {
// The cached encodings are dead (the stream probably restarted)
streamInfo = null;
}
if (streamInfo == null || streamInfo.Encodings == null || streamInfo.BackupEncodings == null) { if (streamInfo == null || streamInfo.Encodings == null || streamInfo.BackupEncodings == null) {
StreamInfos[channelName] = streamInfo = { StreamInfos[channelName] = streamInfo = {
RequestedAds: new Set(), RequestedAds: new Set(),

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions (video-swap-new) // @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.24 // @version 1.25
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js
// @description Multiple solutions for blocking Twitch ads (video-swap-new) // @description Multiple solutions for blocking Twitch ads (video-swap-new)
@ -184,15 +184,18 @@
} }
} }
} }
if (streamInfo.BackupEncodings == null) {
return '';
}
} else if (haveAdTags) { } else if (haveAdTags) {
onFoundAd(streamInfo, textStr, true); onFoundAd(streamInfo, textStr, true);
return '';
} else { } else {
postMessage({key:'UboHideAdBanner'}); postMessage({key:'UboHideAdBanner'});
} }
if (haveAdTags && streamInfo.BackupEncodings != null) {
var streamM3u8Url = streamInfo.BackupEncodings.match(/^https:.*\.m3u8$/m)[0];
var streamM3u8Response = await realFetch(streamM3u8Url);
if (streamM3u8Response.status == 200) {
textStr = await streamM3u8Response.text();
}
}
return textStr; return textStr;
} }
function hookWorkerFetch() { function hookWorkerFetch() {
@ -205,7 +208,11 @@
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var processAfter = async function(response) { var processAfter = async function(response) {
var str = await processM3U8(url, await response.text(), realFetch); var str = await processM3U8(url, await response.text(), realFetch);
resolve(new Response(str)); resolve(new Response(str, {
status: response.status,
statusText: response.statusText,
headers: response.headers
}));
}; };
var send = function() { var send = function() {
return realFetch(url, options).then(function(response) { return realFetch(url, options).then(function(response) {
@ -232,7 +239,10 @@
// - First m3u8 request is the m3u8 with the video encodings (360p,480p,720p,etc). // - First m3u8 request is the m3u8 with the video encodings (360p,480p,720p,etc).
// - Second m3u8 request is the m3u8 for the given encoding obtained in the first request. At this point we will know if there's ads. // - Second m3u8 request is the m3u8 for the given encoding obtained in the first request. At this point we will know if there's ads.
var streamInfo = StreamInfos[channelName]; var streamInfo = StreamInfos[channelName];
var useBackupStream = false; if (streamInfo != null && streamInfo.Encodings != null && (await realFetch(streamInfo.Encodings.match(/^https:.*\.m3u8$/m)[0])).status !== 200) {
// The cached encodings are dead (the stream probably restarted)
streamInfo = null;
}
if (streamInfo == null || streamInfo.Encodings == null || streamInfo.BackupEncodings == null) { if (streamInfo == null || streamInfo.Encodings == null || streamInfo.BackupEncodings == null) {
StreamInfos[channelName] = streamInfo = { StreamInfos[channelName] = streamInfo = {
RequestedAds: new Set(), RequestedAds: new Set(),