Skip to content

Commit

Permalink
Implement @level3tjg's 360p fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed Jun 1, 2023
1 parent e922bb7 commit 6a14447
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
13 changes: 7 additions & 6 deletions vaft/vaft-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ twitch-videoad.js text/javascript
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 = 'embed'; //Source
scope.PlayerType2 = 'autoplay'; //360p
scope.PlayerType3 = 'proxy'; //Source
scope.PlayerType4 = 'thunderdome'; //480p
scope.PlayerType4 = 'embed'; //Source
scope.CurrentChannelName = null;
scope.UsherParams = null;
scope.WasShowingAd = false;
Expand Down Expand Up @@ -163,8 +163,8 @@ twitch-videoad.js text/javascript
if (OriginalVideoPlayerQuality == null) {
OriginalVideoPlayerQuality = currentQuality;
}
if (!currentQuality.includes('480') || e.data.value != null) {
if (!OriginalVideoPlayerQuality.includes('480')) {
if (!currentQuality.includes('360') || e.data.value != null) {
if (!OriginalVideoPlayerQuality.includes('360')) {
var settingsMenu = document.querySelector('div[data-a-target="player-settings-menu"]');
if (settingsMenu == null) {
var settingsCog = document.querySelector('button[data-a-target="player-settings-button"]');
Expand All @@ -176,7 +176,7 @@ twitch-videoad.js text/javascript
}
var lowQuality = document.querySelectorAll('input[data-a-target="tw-radio"');
if (lowQuality) {
var qualityToSelect = lowQuality.length - 3;
var qualityToSelect = lowQuality.length - 2;
if (e.data.value != null) {
if (e.data.value.includes('original')) {
e.data.value = OriginalVideoPlayerQuality;
Expand Down Expand Up @@ -223,6 +223,7 @@ twitch-videoad.js text/javascript
}
var currentQualityLS = window.localStorage.getItem('video-quality');
lowQuality[qualityToSelect].click();
settingsCog.click();
window.localStorage.setItem('video-quality', currentQualityLS);
if (e.data.value != null) {
OriginalVideoPlayerQuality = null;
Expand Down Expand Up @@ -643,7 +644,7 @@ twitch-videoad.js text/javascript
}
function getAccessToken(channelName, playerType, realFetch) {
var body = null;
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "ios", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "ios", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
body = {
operationName: 'PlaybackAccessToken_Template',
query: templateQuery,
Expand Down
15 changes: 8 additions & 7 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.0
// @version 5.8.1
// @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 @@ -69,9 +69,9 @@
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 = 'embed'; //Source
scope.PlayerType2 = 'autoplay'; //360p
scope.PlayerType3 = 'proxy'; //Source
scope.PlayerType4 = 'thunderdome'; //480p
scope.PlayerType4 = 'embed'; //Source
scope.CurrentChannelName = null;
scope.UsherParams = null;
scope.WasShowingAd = false;
Expand Down Expand Up @@ -174,8 +174,8 @@
if (OriginalVideoPlayerQuality == null) {
OriginalVideoPlayerQuality = currentQuality;
}
if (!currentQuality.includes('480') || e.data.value != null) {
if (!OriginalVideoPlayerQuality.includes('480')) {
if (!currentQuality.includes('360') || e.data.value != null) {
if (!OriginalVideoPlayerQuality.includes('360')) {
var settingsMenu = document.querySelector('div[data-a-target="player-settings-menu"]');
if (settingsMenu == null) {
var settingsCog = document.querySelector('button[data-a-target="player-settings-button"]');
Expand All @@ -187,7 +187,7 @@
}
var lowQuality = document.querySelectorAll('input[data-a-target="tw-radio"');
if (lowQuality) {
var qualityToSelect = lowQuality.length - 3;
var qualityToSelect = lowQuality.length - 2;
if (e.data.value != null) {
if (e.data.value.includes('original')) {
e.data.value = OriginalVideoPlayerQuality;
Expand Down Expand Up @@ -234,6 +234,7 @@
}
var currentQualityLS = window.localStorage.getItem('video-quality');
lowQuality[qualityToSelect].click();
settingsCog.click();
window.localStorage.setItem('video-quality', currentQualityLS);
if (e.data.value != null) {
OriginalVideoPlayerQuality = null;
Expand Down Expand Up @@ -654,7 +655,7 @@
}
function getAccessToken(channelName, playerType, realFetch) {
var body = null;
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "ios", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "ios", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
body = {
operationName: 'PlaybackAccessToken_Template',
query: templateQuery,
Expand Down
17 changes: 12 additions & 5 deletions video-swap-new/video-swap-new-ublock-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ twitch-videoad.js text/javascript
scope.OPT_MODE_STRIP_AD_SEGMENTS = true;
scope.OPT_MODE_NOTIFY_ADS_WATCHED = true;
scope.OPT_MODE_NOTIFY_ADS_WATCHED_MIN_REQUESTS = false;
scope.OPT_BACKUP_PLAYER_TYPE = 'embed';
scope.OPT_BACKUP_PLAYER_TYPE = 'autoplay';
scope.OPT_BACKUP_PLATFORM = 'ios';
scope.OPT_REGULAR_PLAYER_TYPE = 'site';
scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = null;
scope.OPT_SHOW_AD_BANNER = true;
scope.AD_SIGNIFIER = 'stitched-ad';
scope.LIVE_SIGNIFIER = ',live';
scope.CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
Expand Down Expand Up @@ -73,7 +75,9 @@ twitch-videoad.js text/javascript
var adDiv = getAdDiv();
if (adDiv != null) {
adDiv.P.textContent = 'Blocking' + (e.data.isMidroll ? ' midroll' : '') + ' ads...';
//adDiv.style.display = 'block';
if (OPT_SHOW_AD_BANNER) {
adDiv.style.display = 'block';
}
}
} else if (e.data.key == 'UboHideAdBanner') {
var adDiv = getAdDiv();
Expand Down Expand Up @@ -213,7 +217,7 @@ twitch-videoad.js text/javascript
for (var i = 0; i < 2; i++) {
var encodingsUrl = url;
if (i == 1) {
var accessTokenResponse = await getAccessToken(channelName, OPT_BACKUP_PLAYER_TYPE);
var accessTokenResponse = await getAccessToken(channelName, OPT_BACKUP_PLAYER_TYPE, OPT_BACKUP_PLATFORM, realFetch);
if (accessTokenResponse != null && accessTokenResponse.status === 200) {
var accessToken = await accessTokenResponse.json();
var urlInfo = new URL('https://usher.ttvnw.net/api/channel/hls/' + channelName + '.m3u8' + (new URL(url)).search);
Expand Down Expand Up @@ -286,9 +290,12 @@ twitch-videoad.js text/javascript
},
}];
}
function getAccessToken(channelName, playerType, realFetch) {
function getAccessToken(channelName, playerType, platform, realFetch) {
if (!platform) {
platform = 'web';
}
var body = null;
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "' + platform + '", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "' + platform + '", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
body = {
operationName: 'PlaybackAccessToken_Template',
query: templateQuery,
Expand Down
19 changes: 13 additions & 6 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.17
// @version 1.18
// @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 All @@ -18,9 +18,11 @@
scope.OPT_MODE_STRIP_AD_SEGMENTS = true;
scope.OPT_MODE_NOTIFY_ADS_WATCHED = true;
scope.OPT_MODE_NOTIFY_ADS_WATCHED_MIN_REQUESTS = false;
scope.OPT_BACKUP_PLAYER_TYPE = 'embed';
scope.OPT_BACKUP_PLAYER_TYPE = 'autoplay';
scope.OPT_BACKUP_PLATFORM = 'ios';
scope.OPT_REGULAR_PLAYER_TYPE = 'site';
scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = null;
scope.OPT_SHOW_AD_BANNER = true;
scope.AD_SIGNIFIER = 'stitched-ad';
scope.LIVE_SIGNIFIER = ',live';
scope.CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
Expand Down Expand Up @@ -84,7 +86,9 @@
var adDiv = getAdDiv();
if (adDiv != null) {
adDiv.P.textContent = 'Blocking' + (e.data.isMidroll ? ' midroll' : '') + ' ads...';
//adDiv.style.display = 'block';
if (OPT_SHOW_AD_BANNER) {
adDiv.style.display = 'block';
}
}
} else if (e.data.key == 'UboHideAdBanner') {
var adDiv = getAdDiv();
Expand Down Expand Up @@ -224,7 +228,7 @@
for (var i = 0; i < 2; i++) {
var encodingsUrl = url;
if (i == 1) {
var accessTokenResponse = await getAccessToken(channelName, OPT_BACKUP_PLAYER_TYPE);
var accessTokenResponse = await getAccessToken(channelName, OPT_BACKUP_PLAYER_TYPE, OPT_BACKUP_PLATFORM, realFetch);
if (accessTokenResponse != null && accessTokenResponse.status === 200) {
var accessToken = await accessTokenResponse.json();
var urlInfo = new URL('https://usher.ttvnw.net/api/channel/hls/' + channelName + '.m3u8' + (new URL(url)).search);
Expand Down Expand Up @@ -297,9 +301,12 @@
},
}];
}
function getAccessToken(channelName, playerType, realFetch) {
function getAccessToken(channelName, playerType, platform, realFetch) {
if (!platform) {
platform = 'web';
}
var body = null;
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "' + platform + '", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "' + platform + '", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
body = {
operationName: 'PlaybackAccessToken_Template',
query: templateQuery,
Expand Down

0 comments on commit 6a14447

Please sign in to comment.