NewPipe icon indicating copy to clipboard operation
NewPipe copied to clipboard

[YouTube] Coordinating efforts on SABR implementation

Open Stypox opened this issue 7 months ago • 9 comments

This issue is meant to coordinate efforts from contributors and gather information to implement YouTube's custom protocol for playback and downloading.

Instructions on how to approach this support for playback: https://github.com/TeamNewPipe/NewPipe/issues/12248#issuecomment-2850709293

Explanation of the currently used clients, why disabling the WebView makes NewPipe work again, and why that's not a long-term solution: https://github.com/TeamNewPipe/NewPipe/issues/12248#issuecomment-2850507305

If you want to help with the implementation and have any questions, feel free to post them here or even better on our IRC/Matrix channel!

DO NOT REPORT #12126 AGAIN HERE! Only post RELEVANT DEVELOPER-FACING INFORMATION here. Other comments will be deleted.

Stypox avatar May 04 '25 21:05 Stypox

I disabled Android System Webview and was able to get HD and 4K videos back. So, it seems like the issue is the browser integrity check introduced in v0.27.6.

kwen1000 avatar May 05 '25 01:05 kwen1000

@kwen1000 here is why disabling the WebView makes NewPipe work again, and here is why that's not a real solution:

  • If the WebView is available, NewPipe passes poTokens to NewPipeExtractor, and the extractor uses the WEB client to fetch results
  • If the WebView is not available, the extractor uses the TVHTML5 client instead, which does not (yet) require poTokens, see here
  • So, when you disable the WebView, you force the extractor to use the TVHTML5 client, and TVHTML5 currently still kind of works but:
    • it will probably start requiring poTokens too at some point, so we are just using it as a temporary fallback for when no WebView is available, but at some point this will not be possible anymore
    • YouTube is moving to SABR formats everywhere, and probably the TVHTML5 client will switch to them too at some point (the client already use them for playback)
  • The reason why the WEB client is not working well anymore is not due to the poToken generation, which still works, but due to the fact that NewPipe cannot play the SABR-encoded video formats
  • So the correct future-proof solution is to implement SABR support in the NewPipe player.

Stypox avatar May 05 '25 10:05 Stypox

Some information about the SABR format can be found here and here, as originally posted by @AudricV in https://github.com/TeamNewPipe/NewPipe/issues/12126#issuecomment-2754182010.

The extractor needs small changes to also extract SABR streams in the functions called by getItags(), and that should be quite simple.

Most of the changes need to be done on the NewPipe side, within the player folder, to implement the SABR format as a data source for the ExoPlayer. In particular, you would need to create a new data source like this one but customized for SABR.

Some more relevant information posted by @AudricV on the Matrix chat:

A custom DataSource should be enough, especially due to the workaround found to make SABR return video data only. I don't have time to enter into details, but please note we use multiple YouTube clients (WEB and TVHTML5 for users without being able to provide poTokens) and multiple SABR URLs with different audio and video variants are be available (with multiple SABR configs). For instance, MWEB (we don't use this client, this is for an example) returns audio stream 600, this is not the case on the WEB client, so trying to use stream 600 on WEB would result in a SABR error with WEB SABR config and URL (and I don't think using MWEB config on a WEB SABR URL would work)

@thefaboss I deleted your comment as to not clutter the thread for newcomers, but will reproduce it here:

I’ve just tried to disable Android System Webview, and yes, as kwen1000 sais, HD is back, even in download section \o/

Originally posted by @thefaboss in #12248

Stypox avatar May 05 '25 11:05 Stypox

Would it make sense to switch to TVHTML5 as a quick workaround until a proper solution is implemented?

Dakkaron avatar May 06 '25 09:05 Dakkaron

@Dakkaron Yes, we just released v0.27.7, with a similar reasoning (using an alternate client than WEB one) :-)

Stypox avatar May 07 '25 19:05 Stypox

The extractor needs small changes to also extract SABR streams in the functions called by getItags(), and that should be quite simple.

I've been working on implementing that, however I'm a bit confused, how that should fit into the function, as the serverABRStreamingURL element is separate from other URLs and doesn't contain the needed data to create an Itag object?

FineFindus avatar May 10 '25 11:05 FineFindus

The first step is indeed extractor changes.

However, the current extractor stream API isn't good at all, especially to implement such things.

So before any start of a SABR implementation, this API must be rewritten (and then reimplemented in the app). See TeamNewPipe/NewPipeExtractor#858. Related discussion should be done there.

AudricV avatar May 12 '25 08:05 AudricV

Hey. I would really love to contribute on this whole SABR topic because NewPipe is an app I use daily. However, I don't really know where to start 😅 It seems like @FineFindus already started, and then there's this issue from @litetex as well where he isn't assigned anymore https://github.com/TeamNewPipe/NewPipeExtractor/issues/858.

Is it possible to help somewhere somehow?

NWuensche avatar Jun 09 '25 18:06 NWuensche

@NWuensche thanks for your interest! I don't think anybody is working specifically on SABR at the moment, though @AudricV has been working on restructuring the extractor (i.e. https://github.com/TeamNewPipe/NewPipeExtractor/issues/858), so you could help on the player part. Could you join the matrix channel so we can coordinate better?

Stypox avatar Jun 10 '25 17:06 Stypox

hello. YTdlp pr; https://github.com/yt-dlp/yt-dlp/pull/13515 Other: https://github.com/etwoo/youtube-unthrottle/commit/76b48d0a2eba29b7dae21cf185d1ec279361c506

Freetube: https://github.com/FreeTubeApp/FreeTube/pull/7145

alimima avatar Aug 09 '25 15:08 alimima

This might be useful.

https://github.com/yuliskov/SmartTube/tree/master/exoplayer-amzn-2.10.6/library/sabr/src/main/java/com/google/android/exoplayer2/source/sabr

resc2008 avatar Sep 04 '25 17:09 resc2008

Found this, might be useful.

https://ieeexplore.ieee.org/document/8551520

BriellaBugs avatar Nov 04 '25 10:11 BriellaBugs