-
-
Save odensc/764900d841cbdd8aa400796001e189f1 to your computer and use it in GitHub Desktop.
/// twitch-videoad.js | |
const origFetch = window.fetch; | |
window.fetch = (url, init, ...args) => { | |
if (typeof url === "string") { | |
if (url.includes("/access_token")) { | |
// url = url.replace("player_type=site", "player_type=site"); | |
} else if ( | |
url.includes("/gql") && | |
init && | |
typeof init.body === "string" && | |
init.body.includes("PlaybackAccessToken") | |
) { | |
// const newBody = JSON.parse(init.body); | |
// newBody.variables.playerType = "site"; | |
// init.body = JSON.stringify(newBody); | |
} | |
} | |
return origFetch(url, init, ...args); | |
}; |
@PureFallen that specific twitch channel shouldn't be used for those kinds of tests as they force ads to be shown.
I've noticed that embed
still works on https://twitchls.com. One interesting thing about it is that if you copy the main m3u8 url that it requests and enter that url into your browser url bar manually, you will get a response with ads. But the response they get NEVER has ads. I've been unable to find out why. I've copied every http header, and still I always get ads on my requests. Thoughts?
@pixeltris I want to apologize. I missed the opportunity to document it when i saw pre-rolls and mid-roll ads on a regular Twitch Channel and head over to Twitchmedia. Same mistake won't happen again. I gonna replace the source as soon as it happens again with the updated script & cache cleared/browser restarted.
According to some people they got ads on https://twitchls.com too... Biggest concern is for now that Amazon is rolling out fixes in waves which makes it hard to reproduce for us all at the same time.
@pixeltris Interesting. I'm seeing the same result. Let me look into this
@pixeltris So it comes down to the video-weaver.xxx.xxx.ttvnw.net
m3u8 playlist request. If the Origin
header is set to https://player.twitch.tv
, it returns a playlist with no ads. Anything else, and it has pre-rolls.
There's no way to set the origin via JS AFAIK, besides a browser extension.
Weirdly I haven't been able to reproduce the same. But I'm using standard .NET request stuff so maybe there's some weird header overwrite going on.
A browser extension probably isn't a terrible idea if Twitch is dedicated to their cause. I have a feeling the embedded scenarios will likely continue to avoid pre-roll ads as playing ads straight away doesn't bode well for trying to draw in new users to their platform.
Setting up a browser extension to change the Origin
header sounds like a better solution then setting up a whole network for Crowdsourcing. Yet in both cases, it will get hard to get the extension distributed underneath users again.
Another thing i worry about is that some privacy settings/configurations on browsers might break the Origin
header that would need to be tried out and checked for in the extension. That could also explain why some solutions seem to work for one user, while it does not for others.
For example, people have been reporting that the November 2nd Update of the "Alternative Player" Extension would have fixed ads but from i can tell, it did not work for me when clicking through some regular Twitch channels.
Doesn't greasemonkey/tampermonkey's GM_xmlhttpRequest
allow modifying the Origin
header?
So in the fetch hook do a XHR on video-weaver.xxx.xxx.ttvnw.net
m3u8 requests instead. I'm just not sure on implementation for wrapping GM_XHR and properly emulating fetch API behavior with a Response promise.
Extension/tampermonkey script (if what @Brybry said is true) will probably be needed soon. Twitch is now getting feisty and doing things like limiting to 480p to annoy people into disabling uBlock. Found another player_type but it won't last long obviously.
The recent update to reset the playertype to a "non resolution capped one" having the funny side effect of "player_type=site" apparently now being used everywhere, greeting users with up to 90 seconds of pre-rolls at the frontpage.
That the frontpage still works for non uBO users while "player_type=frontpage" as we used it a few days before got fixed by Twitch, it should be clear that there is atleast one ingredient on the formular we are missing out on. Origin
might be already a good start.
I've been using the script @pixeltris posted here a couple of days ago (https://gist.github.com/pixeltris/77c676ef65b0b76e7aa56d8a0e0b3897), without any problems like forced low resolution or ads, it's been working fine for me and when ads are played (both preroll and midroll), its replaced by the PIP feed (that is 480p though), but I have not once seen an ad since I changed to that script.
@PureFallen thanks for that note, I just completely commented it out for now. Also, they locked the frontpage player_type so it only blocks ads on streams that are actually featured on the frontpage.
@Hideman85 Having the discussion enclosed is just a temporary fix itself. The moment a new fix is distributed to the users, Twitch will be able to take care of that. It is not like the sourcecode has such a complexity that Twitch could not figure out how the workaround works. Otherwise they haven't been able to fix it in a couple of hours in the last months before.
Hiding the conversation probably makes only sense for a new solution to catch Twitch offguard with, for example gathering all developers for the crowdsource idea (or a similar endgame solution) together in an IRC, Discord, Telegram Chat etc. just to make it accessable to the public later anyway once the fix itself hits the userbase again. That is kinda the point of security using opensource, enclosing information never works in the longrun or hurts the trust towards the users.
Edit (03/11/2020)
Not sure if caused by the thunderdome revision (or if that one was supposed to fix it), but recently it seems like that the Midroll no longer shows the Mini Player, as well of staying displayed after the "supposed to be 30 second adbreak" ends. This happened now multiple times to me already, never happened before but like starting from this morning. Could it be intentional from Twitch or am i just unlucky?
Image for Reference
Edit (04/11/2020)
As already might noticed from Reddit, Twitch fixed advertisments for the thunderdome-playertype.