Skip to content

Commit

Permalink
feat(YouTube): Add patch Disable HDR video (#4347)
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios authored Jan 25, 2025
1 parent 6f2e474 commit 0528f7c
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.revanced.extension.youtube.patches;

import app.revanced.extension.youtube.settings.Settings;

@SuppressWarnings("unused")
public class DisableHdrPatch {

/**
* Injection point.
*/
public static boolean disableHDRVideo() {
return !Settings.DISABLE_HDR_VIDEO.get();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

public class Settings extends BaseSettings {
// Video
public static final BooleanSetting DISABLE_HDR_VIDEO = new BooleanSetting("revanced_disable_hdr_video", FALSE);
public static final BooleanSetting RESTORE_OLD_VIDEO_QUALITY_MENU = new BooleanSetting("revanced_restore_old_video_quality_menu", TRUE);
public static final BooleanSetting REMEMBER_VIDEO_QUALITY_LAST_SELECTED = new BooleanSetting("revanced_remember_video_quality_last_selected", FALSE);
public static final IntegerSetting VIDEO_QUALITY_DEFAULT_WIFI = new IntegerSetting("revanced_video_quality_default_wifi", -2);
Expand Down
4 changes: 4 additions & 0 deletions patches/api/patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,10 @@ public final class app/revanced/patches/youtube/video/audio/ForceOriginalAudioPa
public static final fun getForceOriginalAudioPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/video/hdr/DisableHdrPatchKt {
public static final fun getDisableHdrPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/video/information/VideoInformationPatchKt {
public static final fun getVideoInformationPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
public static final fun userSelectedPlaybackSpeedHook (Ljava/lang/String;Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ private val seekbarColorResourcePatch = resourcePatch {
"color",
"inline_time_bar_played_not_highlighted_color",
]
ytYoutubeMagentaColorId = resourceMappings[
"color",
"yt_youtube_magenta",
]
ytStaticBrandRedId = resourceMappings[
"attr",
"ytStaticBrandRed",
]

// Modify the resume playback drawable and replace the progress bar with a custom drawable.
document("res/drawable/resume_playback_progressbar_drawable.xml").use { document ->
Expand All @@ -97,6 +89,15 @@ private val seekbarColorResourcePatch = resourcePatch {
return@execute
}

ytYoutubeMagentaColorId = resourceMappings[
"color",
"yt_youtube_magenta",
]
ytStaticBrandRedId = resourceMappings[
"attr",
"ytStaticBrandRed",
]

// Add attribute and styles for splash screen custom color.
// Using a style is the only way to selectively change just the seekbar fill color.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package app.revanced.patches.youtube.video.hdr

import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/DisableHdrPatch;"

@Suppress("unused")
val disableHdrPatch = bytecodePatch(
name = "Disable HDR video",
description = "Adds an option to disable video HDR.",
) {
dependsOn(
sharedExtensionPatch,
settingsPatch,
addResourcesPatch,
)

compatibleWith(
"com.google.android.youtube"(
"18.38.44",
"18.49.37",
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
"19.45.38",
"19.46.42",
"19.47.53",
),
)

execute {
addResources("youtube", "video.hdr.disableHdrPatch")

PreferenceScreen.VIDEO.addPreferences(
SwitchPreference("revanced_disable_hdr_video")
)

hdrCapabilityFingerprint.let {
it.originalMethod.apply {
val stringIndex = it.stringMatches!!.first().index
val navigateIndex = indexOfFirstInstructionOrThrow(stringIndex) {
val reference = getReference<MethodReference>()
reference?.parameterTypes == listOf("I", "Landroid/view/Display;") &&
reference.returnType == "Z"
}

// Modify the HDR lookup method (Method is in the same class as the fingerprint).
navigate(this).to(navigateIndex).stop().addInstructionsWithLabels(
0,
"""
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->disableHDRVideo()Z
move-result v0
if-nez v0, :useHdr
return v0
:useHdr
nop
"""
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.revanced.patches.youtube.video.hdr

import app.revanced.patcher.fingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal val hdrCapabilityFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
strings(
"av1_profile_main_10_hdr_10_plus_supported",
"video/av01"
)
}
5 changes: 5 additions & 0 deletions patches/src/main/resources/addresources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,11 @@ Enabling this can unlock higher video qualities"</string>
<string name="revanced_playback_speed_default_title">Default playback speed</string>
<string name="revanced_remember_playback_speed_toast">Changed default speed to: %s</string>
</patch>
<patch id="video.hdr.disableHdrPatch">
<string name="revanced_disable_hdr_video_title">Disable HDR video</string>
<string name="revanced_disable_hdr_video_summary_on">HDR video is disabled</string>
<string name="revanced_disable_hdr_video_summary_off">HDR video is enabled</string>
</patch>
<patch id="video.videoqualitymenu.restoreOldVideoQualityMenuResourcePatch">
<string name="revanced_restore_old_video_quality_menu_title">Restore old video quality menu</string>
<string name="revanced_restore_old_video_quality_menu_summary_on">Old video quality menu is shown</string>
Expand Down

0 comments on commit 0528f7c

Please sign in to comment.