ajayyy / SponsorBlock

Skip YouTube video sponsors (browser extension)
https://sponsor.ajay.app
GNU General Public License v3.0
10.21k stars 323 forks source link

Add after-sponsor buffering #543

Open playsenge opened 3 years ago

playsenge commented 3 years ago

Hello! While I love SponsorBlock, there's a minor issue/suggestion. When I am watching a video with a sponsorship coming up at the beggining, when it skips after the sponsorship it hasn't buffered yet and has to load the part after the sponsorship. It's instead buffering the sponsorship (which is useless).

Hopefully this can get accepted!

Thanks, senge.

ajayyy commented 3 years ago

Sadly, I do not think this is possible

elypter commented 3 years ago

it might be possible on an alternative youtube frontend that directly integrates sponsorblock. there are currently no plans that i know of for invidious or others to implement it though.

playsenge commented 3 years ago

Well, if they don't know about this or no one requests it to them they are not going to do it :P

elypter commented 3 years ago

it would be either your or the repositorys owner to ask for upstream changes. regardless i already asked 2 weeks ago and it was beyond the maintainers scope. so realisitcly you are only going to see this change if you do it yourself.

NDevTK commented 3 years ago

@playsenge I have been trying implement this as it seems practical to do. Progress: https://gist.github.com/NDevTK/be7df78ac1b6e3dbf12ef97afa941c18

NDevTK commented 3 years ago

Sorry about the delay this issue has not been forgotten about.

NDevTK commented 2 years ago

tbh I did forget... may look into this more if I remember :)

ccuser44 commented 2 years ago

The sponsor buffering should also not load the content inside the skippable sections to save bandwith.

This could be done via directly modifying the yt loader javascriot

NDevTK commented 2 years ago

Seems like there would be compatibility issues with that. If it went that far it should modify the video source so that skipping is instant.

ajayyy commented 8 months ago

Some notes from working on waveform editor implementation that might be helpful for this:

Hijacking fetch function will be able to take over the fetch request. Requests follow a pattern, and for after-sponsor buffering, playback URLs for future chunks could be pre-fetched from the m3u8 playlist and returned instantly when YouTube itself tries to fetch it to create an instant buffer effect.

videoplayback video requests all are almost the same except for a few fields that vary

image

Ensuring the correct resolution is pulled would be important. Data should be accessible from ytInitialPlayerResponse or /player requests made through fetch. However, this data doesn't seem to have a direct url to an m3u8 right now. Will need to look into how/if yt-dlp derives one from the data that is there. Or the range somehow has to be calculated from the indexRange or initRange variables in ytInitialPlayerResponse.

Fetch function is already being hijacked by document script for other reasons, so can reuse this injection point.

NDevTK commented 8 months ago

I would prefer something that's not hijacking network requests. Maybe something like quickly changing the currentTime to end of sponsor then changing it back will make there player do the work.

ccuser44 commented 8 months ago

I would prefer something that's not hijacking network requests. Maybe something like quickly changing the currentTime to end of sponsor then changing it back will make there player do the work.

Changing the time back and forth is more hacky

NDevTK commented 8 months ago

I agree network way is "less hacky" still never ended up getting it working :/

ajayyy commented 8 months ago

I've done more research on DASH range requests and I don't see an easy way to predict what ranges for each chunk YouTube will use. It seems to vary, and there is no manifest file for non live videos

Edit: However, maybe it can fetch an arbitrary large-ish range from YouTube and then cut off the range as needed when YouTube makes it's fetches. Wouldn't be that hard to test if that works.

JxxIT commented 4 months ago

@NDevTK Hi, any progress on this? Thanks for looking into this!

NDevTK commented 4 months ago

Yeah so this is still a thing... I don't use the extension and making this change would increase the risk of YouTube playback breaking. One fix that might work would be to get a faster internet connection if this is not practical in your area you have two options.

Hope this helps, NDevTK Support.

JxxIT commented 3 months ago

I'm working on implementing this.