FreeTube icon indicating copy to clipboard operation
FreeTube copied to clipboard

Local API: Implement SABR for VODs

Open PikachuEXE opened this issue 3 months ago • 51 comments

Pull Request Type

  • [ ] Bugfix
  • [x] Feature Implementation
  • [ ] Documentation
  • [ ] Other

Related issue

Closes https://github.com/FreeTubeApp/FreeTube/pull/7145 https://github.com/FreeTubeApp/FreeTube/pull/7887

Description

Based on https://github.com/FreeTubeApp/FreeTube/pull/7145 (Please read that PR first Using https://github.com/LuanRT/googlevideo 4.0.4

  • Implementation updated (different from #7145) to have playback session scoped stuff like SABR context & playbackCookie (SABR details)
  • Player streaming timeout doubled (30s > 60s) to handle sometimes ~40MB response instead of ~10MB (at 2k quality, e.g. https://youtu.be/NmdXl7vXZ7g)
  • New setting for enabling SABR in experimental section

Non-SABR

  • Also updated the implementation for https://github.com/FreeTubeApp/FreeTube/pull/7887 to show pre-roll ads time in toast
  • Toast now updated to be possible to show updated messages (hard coded to refresh per 1s currently)

Screenshots

Lazy maybe add later?

Testing

A. SABR off

  • Test pre-roll ads time toast
  • Test various video playback (should be the same)

B. SABR on

  • Test various video playback (should be the same)

Find custom builds at https://github.com/PikachuEXE/FreeTube/actions/workflows/build.yml?query=branch%3Asabr-pr Find cutting edge custom builds (I only use this branch for testing fixes myself, but can be outdated once I finished testing): https://github.com/PikachuEXE/FreeTube/actions/workflows/build.yml?query=branch%3Acustom-builds%2Fsabr

Desktop

  • OS:
  • OS Version:
  • FreeTube version:

Additional context

Remaining tasks

  • [x] Add/Update labels/tooltips/toasts & make them translatable (after text confirmed)
  • [x] Handle infinite player reload - Allow max 3 player reloads for the same video before fallback to older DASH, if player loaded the reload doesn't count
  • [x] Handle player reload during playback - Reload while keeping timestamp
  • [x] Handle SABR playback delay in the middle - keep toast for now
  • [x] Handle infinite SABR playback delay - reload player after (per req) backoff requested 5 times / cumulative delay going to be larger than timeout for request
  • [x] Handle infinite next request policy received - reload player after (per req) next request policy received 100 times
  • [x] Enable SABR by default
  • [ ] Handle more edge cases if found

Post PR

  • Remove download feature (broken anyway)

PikachuEXE avatar Sep 17 '25 02:09 PikachuEXE

Didnt test yet but im very sure this will close the SABR related issues

#7119 #6683

I really hope it being an experimental setting that is disabled by default is just because you have some things left in the remaining tasks section...

absidue avatar Sep 17 '25 05:09 absidue

I don't think it should be enabled by default for the first release Otherwise there might be too many feedbacks to be handled Whether it should remain in experimental section depends on how many edge case found and not handled well (Might be moved or not before next release

PikachuEXE avatar Sep 17 '25 06:09 PikachuEXE

If we are going to keep it as a setting for the moment, it definitely should stay in the experimental settings and we should have a very clear plan for getting rid of it ASAP. The MWEB workaround is a workaround and is unlikely to keep working forever, so if it breaks while we still allow people to not use SABR we will have to keep finding new workarounds, which quite frankly I don't want to have to do when we know that SABR is the proper solution.

If we keep it a setting I would suggest enabling it by default but having the setting there as a temporary opt-out, that way we'll get more feedback but people can also disable it temporarily if they have issues, until you've decided it is stable enough.

absidue avatar Sep 17 '25 07:09 absidue

This pull request has conflicts, please resolve those before we can evaluate the pull request.

github-actions[bot] avatar Sep 21 '25 10:09 github-actions[bot]

Im not seeing the return of audio tracks -> #6683

Conflicts have been resolved. A maintainer will review the pull request shortly.

github-actions[bot] avatar Sep 22 '25 01:09 github-actions[bot]

Test fix not pushed this this PR yet: https://github.com/PikachuEXE/FreeTube/actions/runs/17907855602

PikachuEXE avatar Sep 22 '25 07:09 PikachuEXE

Seems to resolve https://github.com/FreeTubeApp/FreeTube/issues/7921 but we have to check with users after release

Test fix not pushed this this PR yet: https://github.com/PikachuEXE/FreeTube/actions/runs/17907855602

Was using this and got hit with 404 earlier for a music

https://youtu.be/8tamOu8AwFE

bundle-1758589261369.log

It was only once so far.

ArthurKun21 avatar Sep 23 '25 01:09 ArthurKun21

@efb4f5ff-1298-471a-8973-3d47447115dc Audio track seems fixed (I don't have many videos to test) https://github.com/FreeTubeApp/FreeTube/issues/7921 seems to be timeout so this PR raising the timeout for SABR responses (due to bigger response body sometimes) might or might not make it better Auto reload currently only occurs when infinite retry detected (except redirect where none encountered yet)

@ArthurKun21 Let me know if it occurs more often. But could be YT testing new player which affects dev/current release too

PikachuEXE avatar Sep 23 '25 01:09 PikachuEXE

From branch -> https://github.com/PikachuEXE/FreeTube/actions/workflows/build.yml?query=branch%3Asabr-pr

Build -> https://github.com/PikachuEXE/FreeTube/actions/runs/17933228357

https://youtu.be/ubfACjzvBOg

bundle-1758599566888.log


I go out of the window and then play the same video again. It played but like few seconds to the music it reloaded. Thought you might want the log for it

bundle-1758599733091.log

ArthurKun21 avatar Sep 23 '25 03:09 ArthurKun21

I got more reloads at the middle these few days No idea why, adding debug stuff to my custom build to find out...

Update 1: HTTP 403 Not player JS related (still using 0004de42) but no idea what causes it.. Update 2: Seems to be Failed to extract signature decipher algorithm all the time Update 3: Testing new fix for audio track with less requests but not sure if that's the cause of 403 (so I enabled some logging and toasts - https://github.com/PikachuEXE/FreeTube/actions/runs/17939377956

PikachuEXE avatar Sep 23 '25 07:09 PikachuEXE

https://github.com/PikachuEXE/FreeTube/actions/runs/17939377956

same music video -> https://youtu.be/ubfACjzvBOg

bundle-1758619603841.log

it still reloaded near the start


different music video https://youtu.be/EjlMPu5sEgw

bundle-1758619987994.log

same issue, reloaded near the start

ArthurKun21 avatar Sep 23 '25 09:09 ArthurKun21

  • Should be sorted A-Z
  • 2x Chinese is listed but i only see one on YT
VirtualBoxVM_Wbl6jvje6r

English should be listed above descriptive VirtualBoxVM_rW00ywAChm

English should be sorted above descriptive

We don't sort the audio tracks, that was the same before this PR. Lets keep this PR focused on implementing SABR, all unrelated bugs and feature requests should be left until later.

absidue avatar Sep 23 '25 16:09 absidue

Implemented fallback and tested a few days Fixes some of the issues but would still have issue (invalid poToken) sometimes (and I am not sure if YT issue or this PR issue) You can test with https://github.com/PikachuEXE/FreeTube/actions/runs/18115890405

PikachuEXE avatar Sep 30 '25 01:09 PikachuEXE

Latest build, just merged dev and with proper commits (i.e. only debug/workaround changes in a separate branch for this build, others all in this PR Will make the new setting enabled by default next week if no major issues with playback (I expect you to test now if not started yet~

Update 1: forgot to put build link - https://github.com/PikachuEXE/FreeTube/actions/runs/18298073231

PikachuEXE avatar Oct 07 '25 00:10 PikachuEXE

Before I forgot: It seems what player reload will be requested (when SABR enabled) once poToken expires I got this once I forgot to close a window and try to resume (and it starts buffering Not sure if works every time though

PikachuEXE avatar Oct 08 '25 01:10 PikachuEXE

To fix the unknown type issues for the googlevideo imports could you please add these lines to the compilerOptions in the jsconfig.json file:

"module": "esnext",
"moduleResolution": "bundler",

Additionally the SabrStreamState type is referenced on lines 54 and 170 of the SabrSchemePlugin but is only defined on line 600, so Visual Studio Code treats it as if it doesn't exist, could you please move it earlier on in the file.

absidue avatar Oct 08 '25 20:10 absidue

Updated

PikachuEXE avatar Oct 08 '25 23:10 PikachuEXE

This pull request has conflicts, please resolve those before we can evaluate the pull request.

github-actions[bot] avatar Oct 10 '25 22:10 github-actions[bot]

Conflicts have been resolved. A maintainer will review the pull request shortly.

github-actions[bot] avatar Oct 11 '25 03:10 github-actions[bot]

This pull request has conflicts, please resolve those before we can evaluate the pull request.

github-actions[bot] avatar Oct 12 '25 18:10 github-actions[bot]

Conflicts have been resolved. A maintainer will review the pull request shortly.

github-actions[bot] avatar Oct 13 '25 01:10 github-actions[bot]

New build created: https://github.com/PikachuEXE/FreeTube/actions/runs/18454142459 With fix for data import/export (https://github.com/FreeTubeApp/FreeTube/pull/8106) (So I can test on windows) And with https://github.com/FreeTubeApp/FreeTube/pull/8115 (Also removed hardcoded player ID)

PikachuEXE avatar Oct 13 '25 03:10 PikachuEXE

New build: https://github.com/PikachuEXE/FreeTube/actions/runs/18482293990 No debug, with latest dev (with all fixes so no workaround needed) SABR also now enabled by default There should only be minor changes/fixes left if any (I hope

PikachuEXE avatar Oct 14 '25 01:10 PikachuEXE

This pull request has conflicts, please resolve those before we can evaluate the pull request.

github-actions[bot] avatar Oct 15 '25 22:10 github-actions[bot]

Conflicts have been resolved. A maintainer will review the pull request shortly.

github-actions[bot] avatar Oct 16 '25 00:10 github-actions[bot]

Maybe last build - https://github.com/PikachuEXE/FreeTube/actions/runs/18607715883 Fixed issues in https://github.com/PikachuEXE/FreeTube/issues/83 (maybe OS specific no idea) Added a tweak to load less data for video/audio requests (no idea how to test if it really loads less data) taken from https://github.com/LuanRT/googlevideo/blob/googlevideo-v4.0.4/src/core/SabrStreamingAdapter.ts#L426

PikachuEXE avatar Oct 18 '25 00:10 PikachuEXE