ReVanced / revanced-patches

🧩 Patches for ReVanced
https://revanced.app
GNU General Public License v3.0
2.29k stars 263 forks source link

bug(YouTube - Remember video quality): Cannot set default quality to 1080p premium enhanced bitrate #340

Open EatVanced opened 1 year ago

EatVanced commented 1 year ago

Type

Error at runtime

Bug description

1080p Premium is not remembered, with clicking 1080p premium quality or setting it up to 4k

Steps to reproduce

Click a video with 1080p premium quality open quality settings and click 1080p premium click any random video go back or check current video (if 1080p premium is available) the quality will be set to 1080p, and not to 1080p premium.

this can be checked by checking the Stats for nerds 356 vp9 is the 1080p premium 248 vp9 is the 1080p

Relevant log output

n/a

Screenshots or videos

https://media.discordapp.net/attachments/952946952348270626/1150145419012214874/Record_2023-09-10-02-06-08.mp4

Solution

No response

Additional context

Spoof app signature must be turned off to use 1080p premium

Acknowledgements

LisoUseInAIKyrios commented 1 year ago

For now, try setting ReVanced default quality to 'auto', and then change YouTube settings 'video quality preferences' to 'higher picture quality', and see if it defaults to 1080p premium.

EatVanced commented 1 year ago

That's one solution, but you need to be full screen to make it automatically to 1080p premium after some time or buffering. When in portrait 720p is the default

LisoUseInAIKyrios commented 1 year ago

Can you enable ReVanced debug logging in the settings, enable a ReVanced default video quality, open a video, then collect the debug logs using adb and a computer?

The log entries of interest are logged as RememberVideoQualityPatch

EatVanced commented 1 year ago
 D revanced: RememberVideoQualityPatch: videoQualities: [-2, 1080, 1080, 720, 480, 360, 240, 144]
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch: java.lang.Throwable
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at app.revanced.integrations.utils.LogHelper.printDebug(LogHelper.java:64)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at app.revanced.integrations.patches.playback.quality.RememberVideoQualityPatch.setVideoQuality(RememberVideoQualityPatch.java:86)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at khp.o(Unknown Source:6)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aeda.o(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aedd.j(PG:17)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aave.j(PG:3)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aebu.a(PG:8)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axpn.c(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at awwq.c(PG:11)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axas.f(PG:16)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axar.c(PG:3)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at awyt.d(PG:5)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at awyt.c(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axqr.a(PG:4)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axqr.b(PG:7)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axqs.c(PG:6)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aeuk.h(PG:4)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abrp.h(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abtj.h(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at acba.h(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abtl.h(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abtj.h(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abzi.w(PG:6)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abzi.i(PG:8)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abut.f(PG:5)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at ccd.a(PG:20)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at rk.run(PG:34)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at btm.b(PG:9)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at btm.f(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at ccr.J(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at ccr.kY(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at uk.run(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Handler.handleCallback(Handler.java:938)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Looper.loopOnce(Looper.java:233)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Looper.loop(Looper.java:344)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.app.ActivityThread.main(ActivityThread.java:8249)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at java.lang.reflect.Method.invoke(Native Method)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch: Quality changed from: 480 to: 1080
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch: java.lang.Throwable
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at app.revanced.integrations.utils.LogHelper.printDebug(LogHelper.java:64)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at app.revanced.integrations.patches.playback.quality.RememberVideoQualityPatch.setVideoQuality(RememberVideoQualityPatch.java:123)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at khp.o(Unknown Source:6)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aeda.o(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aedd.j(PG:17)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aave.j(PG:3)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aebu.a(PG:8)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axpn.c(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at awwq.c(PG:11)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axas.f(PG:16)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axar.c(PG:3)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at awyt.d(PG:5)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at awyt.c(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axqr.a(PG:4)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axqr.b(PG:7)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at axqs.c(PG:6)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at aeuk.h(PG:4)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abrp.h(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abtj.h(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at acba.h(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abtl.h(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abtj.h(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abzi.w(PG:6)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abzi.i(PG:8)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at abut.f(PG:5)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at ccd.a(PG:20)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at rk.run(PG:34)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at btm.b(PG:9)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at btm.f(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at ccr.J(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at ccr.kY(PG:2)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at uk.run(PG:1)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Handler.handleCallback(Handler.java:938)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Looper.loopOnce(Looper.java:233)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.os.Looper.loop(Looper.java:344)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at android.app.ActivityThread.main(ActivityThread.java:8249)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at java.lang.reflect.Method.invoke(Native Method)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589)
09-10 17:12:12.354 10945 10945 D revanced: RememberVideoQualityPatch:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071)

is this enough?

oSumAtrIX commented 1 year ago

Looks like the hook we have is only for resolutions not the bitrate.

LisoUseInAIKyrios commented 1 year ago

The 1080p premium shows up as one of the 1080 qualities: RememberVideoQualityPatch: videoQualities: [-2, 1080, 1080, 720, 480, 360, 240, 144] Which one is 1080p premium? It's not clear.

I'd guess it's the second 1080 that is the premium option. The reason for this is the way patch selects the best quality available, and for the OP it's picking the regular 1080p and not premium.

This might be fixable by changing https://github.com/ReVanced/revanced-integrations/blob/c034d474ff8659907f4a3632e956fe157486dfa8/app/src/main/java/app/revanced/integrations/patches/playback/quality/RememberVideoQualityPatch.java#L102 from: if (quality <= preferredQuality && qualityToUse < quality) { to if (quality <= preferredQuality && qualityToUse <= quality) { But I don't have 1080p premium, so I cannot verify if this would work.

The ReVanced settings would not show the premium option as a selection, but if this change fixes it then selecting '1080p' will cause it to select 1080 premium if available, otherwise pick regular 1080.

Edit: the "1080p enhanced" field sometimes appears before, and sometimes after regular 1080p. So both with and without this fix, sometimes enhanced is picked and sometimes it's not. So this simple fix won't work.

oSumAtrIX commented 1 year ago

The implementation is legacy code from Vanced. A proper and cleaner implementation would be to hook the method that sets the quality. This way you can capture the quality to be set, and override it the next time. I have refactored the patch to remember the speed in the same fashion. This would avoid reflection gymnastics and result in a cleaner less error prone implementation

NBruderman commented 1 year ago

Yeah, the current implementation is really broken in qualities beyond non premium 1080p, and most of the time have to be adjusted manually after opening the app, even if the default quality is set beyond 1080p (setting it to 1080p premium by default is not even currently possible)

LisoUseInAIKyrios commented 11 months ago

most of the time have to be adjusted manually after opening the app

It can take a few seconds for the ReVanced default quality to be applied. Immediately after opening a video the quality flyout menu may show whatever YouTube initially picked, but if you wait a moment and check again the flyout will show the ReVanced default quality is correctly set. Even when manually picking the quality from the flyout, the flyout will show that new quality immediately but it still takes a few seconds for the actual video quality to be applied. Turn on the "stats for nerds" overlay and you'll see it takes a few seconds for the video steam quality to change (and this happens even when using stock YouTube).

You can improve things slightly by picking "higher picture quality" in the stock YouTube "video quality preferences" menu

NBruderman commented 11 months ago

most of the time have to be adjusted manually after opening the app

It can take a few seconds for the ReVanced default quality to be applied. Immediately after opening a video the quality flyout menu may show whatever YouTube initially picked, but if you wait a moment and check again the flyout will show the ReVanced default quality is correctly set. Even when manually picking the quality from the flyout, the flyout will show that new quality immediately but it still takes a few seconds for the actual video quality to be applied. Turn on the "stats for nerds" overlay and you'll see it takes a few seconds for the video steam quality to change (and this happens even when using stock YouTube).

You can improve things slightly by picking "higher picture quality" in the stock YouTube "video quality preferences" menu

Is there a way to add to the algorithm the 1080p enhanced quality? Because regulary the quality won't recognize it, and will set it to regular 1080p, although enhanced is available