Skip to content

Commit

Permalink
Fix quality reset on video-swap-new #156
Browse files Browse the repository at this point in the history
- Change vaft priority to embed followed by 360p
- Possibly fix mute/volume reset on video-swap-new #170
  • Loading branch information
pixeltris committed Aug 9, 2023
1 parent 4452680 commit c3663da
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 46 deletions.
9 changes: 2 additions & 7 deletions vaft/vaft-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ twitch-videoad.js text/javascript
scope.ClientID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
scope.ClientVersion = 'null';
scope.ClientSession = 'null';
//scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself
scope.PlayerType2 = 'autoplay'; //360p
scope.PlayerType3 = 'embed'; //Source
//scope.PlayerType4 = 'embed'; //Source
scope.PlayerType2 = 'embed'; //Source
scope.PlayerType3 = 'autoplay'; //360p
scope.CurrentChannelName = null;
scope.UsherParams = null;
scope.WasShowingAd = false;
Expand Down Expand Up @@ -284,9 +282,6 @@ twitch-videoad.js text/javascript
if (weaverText.includes(AdSignifier)) {
weaverText = await processM3U8(url, responseText, realFetch, PlayerType3);
}
//if (weaverText.includes(AdSignifier)) {
// weaverText = await processM3U8(url, responseText, realFetch, PlayerType4);
//}
resolve(new Response(weaverText));
};
var send = function() {
Expand Down
11 changes: 3 additions & 8 deletions vaft/vaft.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (vaft)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 5.8.3
// @version 5.8.4
// @description Multiple solutions for blocking Twitch ads (vaft)
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
Expand Down Expand Up @@ -68,10 +68,8 @@
scope.ClientID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
scope.ClientVersion = 'null';
scope.ClientSession = 'null';
//scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself
scope.PlayerType2 = 'autoplay'; //360p
scope.PlayerType3 = 'embed'; //Source
//scope.PlayerType4 = 'embed'; //Source
scope.PlayerType2 = 'embed'; //Source
scope.PlayerType3 = 'autoplay'; //360p
scope.CurrentChannelName = null;
scope.UsherParams = null;
scope.WasShowingAd = false;
Expand Down Expand Up @@ -295,9 +293,6 @@
if (weaverText.includes(AdSignifier)) {
weaverText = await processM3U8(url, responseText, realFetch, PlayerType3);
}
//if (weaverText.includes(AdSignifier)) {
// weaverText = await processM3U8(url, responseText, realFetch, PlayerType4);
//}
resolve(new Response(weaverText));
};
var send = function() {
Expand Down
59 changes: 44 additions & 15 deletions video-swap-new/video-swap-new-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,32 @@ twitch-videoad.js text/javascript
return;
}
} else {
var lowResLines = encodingsM3u8.replace('\r', '').split('\n');
var lowResBestUrl = null;
for (var j = 0; j < lowResLines.length; j++) {
if (lowResLines[j].startsWith('#EXT-X-STREAM-INF')) {
var res = parseAttributes(lowResLines[j])['RESOLUTION'];
if (res && lowResLines[j + 1].endsWith('.m3u8')) {
// Assumes resolutions are correctly ordered
lowResBestUrl = lowResLines[j + 1];
break;
}
}
}
if (lowResBestUrl != null && streamInfo.Encodings != null) {
var normalEncodingsM3u8 = streamInfo.Encodings;
var normalLines = normalEncodingsM3u8.replace('\r', '').split('\n');
for (var j = 0; j < normalLines.length - 1; j++) {
if (normalLines[j].startsWith('#EXT-X-STREAM-INF')) {
var res = parseAttributes(normalLines[j])['RESOLUTION'];
if (res) {
lowResBestUrl += ' ';// The stream doesn't load unless each url line is unique
normalLines[j + 1] = lowResBestUrl;
}
}
}
encodingsM3u8 = normalLines.join('\r\n');
}
streamInfo.BackupEncodings = encodingsM3u8;
}
var lines = encodingsM3u8.replace('\r', '').split('\n');
Expand Down Expand Up @@ -511,22 +537,25 @@ twitch-videoad.js text/javascript
player.play();
return;
}
const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null);
if (sink && sink.video && sink.video._ffz_compressor) {
const video = sink.video;
const volume = video.volume ? video.volume : player.getVolume();
const muted = player.isMuted();
const newVideo = document.createElement('video');
newVideo.volume = muted ? 0 : volume;
newVideo.playsInline = true;
video.replaceWith(newVideo);
player.attachHTMLVideoElement(newVideo);
setImmediate(() => {
player.setVolume(volume);
player.setMuted(muted);
});
const lsKeyQuality = 'video-quality';
const lsKeyMuted = 'video-muted';
const lsKeyVolume = 'volume';
var currentQualityLS = localStorage.getItem(lsKeyQuality);
var currentMutedLS = localStorage.getItem(lsKeyMuted);
var currentVolumeLS = localStorage.getItem(lsKeyVolume);
if (player?.core?.state) {
localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted}));
localStorage.setItem(lsKeyVolume, player.core.state.volume);
}
if (player?.core?.state?.quality?.group) {
localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group}));
}
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });// ffz sets this false
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });
setTimeout(() => {
localStorage.setItem(lsKeyQuality, currentQualityLS);
localStorage.setItem(lsKeyMuted, currentMutedLS);
localStorage.setItem(lsKeyVolume, currentVolumeLS);
}, 3000);
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
hookFetch();
Expand Down
61 changes: 45 additions & 16 deletions video-swap-new/video-swap-new.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.20
// @version 1.21
// @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)
Expand Down Expand Up @@ -260,6 +260,32 @@
return;
}
} else {
var lowResLines = encodingsM3u8.replace('\r', '').split('\n');
var lowResBestUrl = null;
for (var j = 0; j < lowResLines.length; j++) {
if (lowResLines[j].startsWith('#EXT-X-STREAM-INF')) {
var res = parseAttributes(lowResLines[j])['RESOLUTION'];
if (res && lowResLines[j + 1].endsWith('.m3u8')) {
// Assumes resolutions are correctly ordered
lowResBestUrl = lowResLines[j + 1];
break;
}
}
}
if (lowResBestUrl != null && streamInfo.Encodings != null) {
var normalEncodingsM3u8 = streamInfo.Encodings;
var normalLines = normalEncodingsM3u8.replace('\r', '').split('\n');
for (var j = 0; j < normalLines.length - 1; j++) {
if (normalLines[j].startsWith('#EXT-X-STREAM-INF')) {
var res = parseAttributes(normalLines[j])['RESOLUTION'];
if (res) {
lowResBestUrl += ' ';// The stream doesn't load unless each url line is unique
normalLines[j + 1] = lowResBestUrl;
}
}
}
encodingsM3u8 = normalLines.join('\r\n');
}
streamInfo.BackupEncodings = encodingsM3u8;
}
var lines = encodingsM3u8.replace('\r', '').split('\n');
Expand Down Expand Up @@ -522,22 +548,25 @@
player.play();
return;
}
const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null);
if (sink && sink.video && sink.video._ffz_compressor) {
const video = sink.video;
const volume = video.volume ? video.volume : player.getVolume();
const muted = player.isMuted();
const newVideo = document.createElement('video');
newVideo.volume = muted ? 0 : volume;
newVideo.playsInline = true;
video.replaceWith(newVideo);
player.attachHTMLVideoElement(newVideo);
setImmediate(() => {
player.setVolume(volume);
player.setMuted(muted);
});
const lsKeyQuality = 'video-quality';
const lsKeyMuted = 'video-muted';
const lsKeyVolume = 'volume';
var currentQualityLS = localStorage.getItem(lsKeyQuality);
var currentMutedLS = localStorage.getItem(lsKeyMuted);
var currentVolumeLS = localStorage.getItem(lsKeyVolume);
if (player?.core?.state) {
localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted}));
localStorage.setItem(lsKeyVolume, player.core.state.volume);
}
if (player?.core?.state?.quality?.group) {
localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group}));
}
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });// ffz sets this false
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });
setTimeout(() => {
localStorage.setItem(lsKeyQuality, currentQualityLS);
localStorage.setItem(lsKeyMuted, currentMutedLS);
localStorage.setItem(lsKeyVolume, currentVolumeLS);
}, 3000);
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
hookFetch();
Expand Down

0 comments on commit c3663da

Please sign in to comment.