Skip to content

Commit

Permalink
feat(YouTube/Hide player flyout menu): add Hide 1080p Premium menu
Browse files Browse the repository at this point in the history
…setting
  • Loading branch information
inotia00 committed Oct 13, 2024
1 parent 40cecc6 commit 4eafb40
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package app.revanced.patches.youtube.player.flyoutmenu.hide

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.AdvancedQualityBottomSheetFingerprint
import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.CaptionsBottomSheetFingerprint
import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.PiPModeConfigFingerprint
import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.fingerprints.QualityMenuViewInflateFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
Expand All @@ -18,12 +21,14 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.injectLiteralInstructionViewCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

@Suppress("unused")
Expand All @@ -41,7 +46,8 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch(
AdvancedQualityBottomSheetFingerprint,
CaptionsBottomSheetFingerprint,
PiPModeConfigFingerprint,
QualityMenuViewInflateFingerprint
QualityMenuViewInflateFingerprint,
VideoQualityArrayFingerprint,
)
) {
private const val PANELS_FILTER_CLASS_DESCRIPTOR =
Expand Down Expand Up @@ -84,6 +90,27 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch(

// endregion

// region patch for hide '1080p Premium' label

VideoQualityArrayFingerprint.resultOrThrow().mutableMethod.apply {
val qualityLabelIndex = VideoQualityArrayFingerprint.indexOfQualityLabelInstruction(this) + 1
val qualityLabelRegister = getInstruction<OneRegisterInstruction>(qualityLabelIndex).registerA
val jumpIndex = indexOfFirstInstructionReversedOrThrow(qualityLabelIndex) {
opcode == Opcode.INVOKE_INTERFACE &&
getReference<MethodReference>()?.name == "hasNext"
}

addInstructionsWithLabels(
qualityLabelIndex + 1, """
invoke-static {v$qualityLabelRegister}, $PLAYER_CLASS_DESCRIPTOR->hidePlayerFlyoutMenuEnhancedBitrate(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$qualityLabelRegister
if-eqz v$qualityLabelRegister, :jump
""", ExternalLabel("jump", getInstruction(jumpIndex))
)
}

// endregion

LithoFilterPatch.addFilter(PANELS_FILTER_CLASS_DESCRIPTOR)

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint.ENDS_WITH_PARAMETER_LIST
import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint.STARTS_WITH_PARAMETER_LIST
import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint.indexOfQualityLabelInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.parametersEqual
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal object VideoQualityArrayFingerprint : MethodFingerprint(
returnType = "[Lcom/google/android/libraries/youtube/innertube/model/media/VideoQuality;",
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
// 18.29 and earlier parameters are:
// "Ljava/util/List;",
// "Ljava/lang/String;"
// "L"

// 18.31+ parameters are:
// "Ljava/util/List;",
// "Ljava/util/Collection;",
// "Ljava/lang/String;"
// "L"
customFingerprint = custom@{ methodDef, _ ->
val parameterTypes = methodDef.parameterTypes
val parameterSize = parameterTypes.size
if (parameterSize != 3 && parameterSize != 4) {
return@custom false
}

val startsWithMethodParameterList = parameterTypes.slice(0..0)
val endsWithMethodParameterList = parameterTypes.slice(parameterSize - 2..< parameterSize)

parametersEqual(STARTS_WITH_PARAMETER_LIST, startsWithMethodParameterList) &&
parametersEqual(ENDS_WITH_PARAMETER_LIST, endsWithMethodParameterList) &&
indexOfQualityLabelInstruction(methodDef) >= 0
}
) {
private val STARTS_WITH_PARAMETER_LIST = listOf(
"Ljava/util/List;"
)
private val ENDS_WITH_PARAMETER_LIST = listOf(
"Ljava/lang/String;",
"L"
)

fun indexOfQualityLabelInstruction(methodDef: Method) =
methodDef.indexOfFirstInstruction {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.returnType == "Ljava/lang/String;" &&
reference.parameterTypes.size == 0 &&
reference.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/FormatStreamModel;"
}
}
3 changes: 3 additions & 0 deletions src/main/resources/youtube/settings/host/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,9 @@ Settings → Autoplay → Autoplay next video"</string>
<string name="revanced_change_player_flyout_menu_toggle_title">Change toggle type</string>
<string name="revanced_change_player_flyout_menu_toggle_summary_on">Text toggles are used.</string>
<string name="revanced_change_player_flyout_menu_toggle_summary_off">Switch toggles are used.</string>
<string name="revanced_hide_player_flyout_menu_enhanced_bitrate_title">Hide 1080p Premium menu</string>
<string name="revanced_hide_player_flyout_menu_enhanced_bitrate_summary_on">1080p Premium menu is hidden.</string>
<string name="revanced_hide_player_flyout_menu_enhanced_bitrate_summary_off">1080p Premium menu is shown.</string>
<string name="revanced_hide_player_flyout_menu_audio_track_title">Hide Audio track menu</string>
<string name="revanced_hide_player_flyout_menu_audio_track_summary_on">Audio track menu is hidden.</string>
<string name="revanced_hide_player_flyout_menu_audio_track_summary_off">Audio track menu is shown.</string>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/youtube/settings/xml/revanced_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
<SwitchPreference android:title="@string/revanced_change_player_flyout_menu_toggle_title" android:key="revanced_change_player_flyout_menu_toggle" android:summaryOn="@string/revanced_change_player_flyout_menu_toggle_summary_on" android:summaryOff="@string/revanced_change_player_flyout_menu_toggle_summary_off" />SETTINGS: CHANGE_PLAYER_FLYOUT_MENU_TOGGLE -->

<!-- SETTINGS: HIDE_PLAYER_FLYOUT_MENU
<SwitchPreference android:title="@string/revanced_hide_player_flyout_menu_enhanced_bitrate_title" android:key="revanced_hide_player_flyout_menu_enhanced_bitrate" android:summaryOn="@string/revanced_hide_player_flyout_menu_enhanced_bitrate_summary_on" android:summaryOff="@string/revanced_hide_player_flyout_menu_enhanced_bitrate_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_player_flyout_menu_audio_track_title" android:key="revanced_hide_player_flyout_menu_audio_track" android:summaryOn="@string/revanced_hide_player_flyout_menu_audio_track_summary_on" android:summaryOff="@string/revanced_hide_player_flyout_menu_audio_track_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_player_flyout_menu_captions_title" android:key="revanced_hide_player_flyout_menu_captions" android:summaryOn="@string/revanced_hide_player_flyout_menu_captions_summary_on" android:summaryOff="@string/revanced_hide_player_flyout_menu_captions_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_player_flyout_menu_captions_footer_title" android:key="revanced_hide_player_flyout_menu_captions_footer" android:summaryOn="@string/revanced_hide_player_flyout_menu_captions_footer_summary_on" android:summaryOff="@string/revanced_hide_player_flyout_menu_captions_footer_summary_off" />
Expand Down

0 comments on commit 4eafb40

Please sign in to comment.