Reload player instead of terminating when backup stream fails

This commit is contained in:
pixeltris 2021-06-12 20:10:09 +01:00
parent 4ef55e67a2
commit bac0e8da54
5 changed files with 73 additions and 48 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions // @name TwitchAdSolutions
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.6 // @version 1.7
// @description Multiple solutions for blocking Twitch ads // @description Multiple solutions for blocking Twitch ads
// @author pixeltris // @author pixeltris
// @match *://*.twitch.tv/* // @match *://*.twitch.tv/*
@ -249,6 +249,7 @@
console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status); console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status);
} }
} }
if (streamInfo.BackupUrl != null) {
var backupM3u8 = null; var backupM3u8 = null;
var backupM3u8Response = await realFetch(streamInfo.BackupUrl); var backupM3u8Response = await realFetch(streamInfo.BackupUrl);
if (backupM3u8Response.status == 200) { if (backupM3u8Response.status == 200) {
@ -259,12 +260,16 @@
} else { } else {
console.log('Backup m3u8 failed with ' + backupM3u8Response.status); console.log('Backup m3u8 failed with ' + backupM3u8Response.status);
} }
}
} catch (err) { } catch (err) {
console.log('Fetching backup m3u8 failed'); console.log('Fetching backup m3u8 failed');
console.log(err); console.log(err);
} }
// Backups failed. Return nothing (this will likely result in spam or player error 2000?). // Backups failed. Return nothing (this will likely result in spam or player error 2000?).
console.log('Ad blocking failed. Stream might break.'); console.log('Ad blocking failed. Stream might break.');
postMessage({key:'UboReloadPlayer'});
streamInfo.BackupFailed = false;
streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds) {

View File

@ -240,6 +240,7 @@ twitch-videoad.js application/javascript
console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status); console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status);
} }
} }
if (streamInfo.BackupUrl != null) {
var backupM3u8 = null; var backupM3u8 = null;
var backupM3u8Response = await realFetch(streamInfo.BackupUrl); var backupM3u8Response = await realFetch(streamInfo.BackupUrl);
if (backupM3u8Response.status == 200) { if (backupM3u8Response.status == 200) {
@ -250,12 +251,16 @@ twitch-videoad.js application/javascript
} else { } else {
console.log('Backup m3u8 failed with ' + backupM3u8Response.status); console.log('Backup m3u8 failed with ' + backupM3u8Response.status);
} }
}
} catch (err) { } catch (err) {
console.log('Fetching backup m3u8 failed'); console.log('Fetching backup m3u8 failed');
console.log(err); console.log(err);
} }
// Backups failed. Return nothing (this will likely result in spam or player error 2000?). // Backups failed. Return nothing (this will likely result in spam or player error 2000?).
console.log('Ad blocking failed. Stream might break.'); console.log('Ad blocking failed. Stream might break.');
postMessage({key:'UboReloadPlayer'});
streamInfo.BackupFailed = false;
streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds) {

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions (notify-reload) // @name TwitchAdSolutions (notify-reload)
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.6 // @version 1.7
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js
// @description Multiple solutions for blocking Twitch ads (notify-reload) // @description Multiple solutions for blocking Twitch ads (notify-reload)
@ -251,6 +251,7 @@
console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status); console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status);
} }
} }
if (streamInfo.BackupUrl != null) {
var backupM3u8 = null; var backupM3u8 = null;
var backupM3u8Response = await realFetch(streamInfo.BackupUrl); var backupM3u8Response = await realFetch(streamInfo.BackupUrl);
if (backupM3u8Response.status == 200) { if (backupM3u8Response.status == 200) {
@ -261,12 +262,16 @@
} else { } else {
console.log('Backup m3u8 failed with ' + backupM3u8Response.status); console.log('Backup m3u8 failed with ' + backupM3u8Response.status);
} }
}
} catch (err) { } catch (err) {
console.log('Fetching backup m3u8 failed'); console.log('Fetching backup m3u8 failed');
console.log(err); console.log(err);
} }
// Backups failed. Return nothing (this will likely result in spam or player error 2000?). // Backups failed. Return nothing (this will likely result in spam or player error 2000?).
console.log('Ad blocking failed. Stream might break.'); console.log('Ad blocking failed. Stream might break.');
postMessage({key:'UboReloadPlayer'});
streamInfo.BackupFailed = false;
streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds) {

View File

@ -240,6 +240,7 @@ twitch-videoad.js application/javascript
console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status); console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status);
} }
} }
if (streamInfo.BackupUrl != null) {
var backupM3u8 = null; var backupM3u8 = null;
var backupM3u8Response = await realFetch(streamInfo.BackupUrl); var backupM3u8Response = await realFetch(streamInfo.BackupUrl);
if (backupM3u8Response.status == 200) { if (backupM3u8Response.status == 200) {
@ -250,12 +251,16 @@ twitch-videoad.js application/javascript
} else { } else {
console.log('Backup m3u8 failed with ' + backupM3u8Response.status); console.log('Backup m3u8 failed with ' + backupM3u8Response.status);
} }
}
} catch (err) { } catch (err) {
console.log('Fetching backup m3u8 failed'); console.log('Fetching backup m3u8 failed');
console.log(err); console.log(err);
} }
// Backups failed. Return nothing (this will likely result in spam or player error 2000?). // Backups failed. Return nothing (this will likely result in spam or player error 2000?).
console.log('Ad blocking failed. Stream might break.'); console.log('Ad blocking failed. Stream might break.');
postMessage({key:'UboReloadPlayer'});
streamInfo.BackupFailed = false;
streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds) {

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions (notify-strip) // @name TwitchAdSolutions (notify-strip)
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.6 // @version 1.7
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js
// @description Multiple solutions for blocking Twitch ads (notify-strip) // @description Multiple solutions for blocking Twitch ads (notify-strip)
@ -251,6 +251,7 @@
console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status); console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status);
} }
} }
if (streamInfo.BackupUrl != null) {
var backupM3u8 = null; var backupM3u8 = null;
var backupM3u8Response = await realFetch(streamInfo.BackupUrl); var backupM3u8Response = await realFetch(streamInfo.BackupUrl);
if (backupM3u8Response.status == 200) { if (backupM3u8Response.status == 200) {
@ -261,12 +262,16 @@
} else { } else {
console.log('Backup m3u8 failed with ' + backupM3u8Response.status); console.log('Backup m3u8 failed with ' + backupM3u8Response.status);
} }
}
} catch (err) { } catch (err) {
console.log('Fetching backup m3u8 failed'); console.log('Fetching backup m3u8 failed');
console.log(err); console.log(err);
} }
// Backups failed. Return nothing (this will likely result in spam or player error 2000?). // Backups failed. Return nothing (this will likely result in spam or player error 2000?).
console.log('Ad blocking failed. Stream might break.'); console.log('Ad blocking failed. Stream might break.');
postMessage({key:'UboReloadPlayer'});
streamInfo.BackupFailed = false;
streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds) {