-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webRequest.filterResponseData instead of monkey patching #7
Comments
FWIW, I've tried the following, but what happens is that the Ad starts playing and after 1-2 seconds it stops and only shows the buffering circle. browser.webRequest.onBeforeRequest.addListener(details => {
const filter = browser.webRequest.filterResponseData(details.requestId);
const decoder = new TextDecoder('utf-8');
const encoder = new TextEncoder();
filter.ondata = event => {
let str = decoder.decode(event.data, {stream: true});
if (str.includes('#EXT-X-SCTE35-OUT')) {
str = str.replace(/#EXT-X-SCTE35-OUT(.|\s)*#EXT-X-SCTE35-IN/gmi, '');
str = str.replace(/#EXT-X-SCTE35-OUT(.|\s)*/gmi, '');
str = str.replace(/#EXT-X-DISCONTINUITY/gi, '');
str = str.replace(/#EXT-X-DATERANGE:ID="stitched-ad.*/gi, '');
}
filter.write(encoder.encode(str));
filter.disconnect();
};
}, {urls: ['https://*.hls.ttvnw.net/*.m3u8'], types: ['xmlhttprequest']}, ['blocking']); |
Very exciting stuff, I like this idea a lot. At least for Firefox it would make the code much cleaner. Especially if Chrome ever adds this functionality this would simplify things a lot, so I think this is a good general idea to which direction this extension should evolve to. Regarding your code snippet, I think fixing the media sequence is still mandatory. I'll look at this a bit more closely when I get the time (or actually get some preroll ads again), or of course welcome any PR. |
Glad you like it.
Could you elaborate on how fixing the sequence should work? Currently what happens, as I see it in the code (and limited tests with console.log):
So, is it expected to start at 1 again after an Ad, even for Midrolls? If that's the case, I guess it wouldn't work for multiple Ads since |
Honestly, I'm not sure anymore, especially with midroll ads. I am sure that sequence numbers are important however. Subtract too much, you get constant buffering, add too much, the stream starts glitching heavily. When ads appear and we leave the sequence number as is afterwards, we get a lot of buffering. Btw, the code didn't work for midroll ads, only for preroll ads, it was buggy. I reworked it today (linked above). |
This idea seems like a generally good technique that could apply to other sites using EDIT: Adblock apparently added a similar related feature in change #6592. Not sure how to use this, as it's not well documented yet. It looks like it's not actually rewriting or modifying an |
Thanks for your work on THA!
I was wondering, would it maybe be possible to use webRequest.filterResponseData on the m3u8 playlist urls and filter out the SCTE-35 flags from the response that way, instead of monkey patching? (Would of course only be an option for Firefox since Chrome can't modify response bodys yet) Sorry if that's an ignorant question and I'm missing the parts of what THA does besides filtering the flags.
The text was updated successfully, but these errors were encountered: