diff --git a/video-swap-new/video-swap-new-ublock-origin.js b/video-swap-new/video-swap-new-ublock-origin.js index 529fad6..85531f0 100644 --- a/video-swap-new/video-swap-new-ublock-origin.js +++ b/video-swap-new/video-swap-new-ublock-origin.js @@ -172,15 +172,18 @@ twitch-videoad.js text/javascript } } } - if (streamInfo.BackupEncodings == null) { - return ''; - } } else if (haveAdTags) { onFoundAd(streamInfo, textStr, true); - return ''; } else { 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; } function hookWorkerFetch() { @@ -193,7 +196,11 @@ twitch-videoad.js text/javascript return new Promise(function(resolve, reject) { var processAfter = async function(response) { 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() { 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). // - 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 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) { StreamInfos[channelName] = streamInfo = { RequestedAds: new Set(), diff --git a/video-swap-new/video-swap-new.user.js b/video-swap-new/video-swap-new.user.js index f97e53f..502a0ad 100644 --- a/video-swap-new/video-swap-new.user.js +++ b/video-swap-new/video-swap-new.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TwitchAdSolutions (video-swap-new) // @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 // @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) @@ -184,15 +184,18 @@ } } } - if (streamInfo.BackupEncodings == null) { - return ''; - } } else if (haveAdTags) { onFoundAd(streamInfo, textStr, true); - return ''; } else { 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; } function hookWorkerFetch() { @@ -205,7 +208,11 @@ return new Promise(function(resolve, reject) { var processAfter = async function(response) { 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() { 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). // - 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 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) { StreamInfos[channelName] = streamInfo = { RequestedAds: new Set(),