feat(YouTube - Playback speed): Add option to change 2x tap and hold speed (#4307)

This commit is contained in:
LisoUseInAIKyrios
2025-01-18 11:37:34 +02:00
committed by GitHub
parent 220e9c78c1
commit 02fb26e945
6 changed files with 68 additions and 13 deletions

View File

@ -662,6 +662,7 @@ public class app/revanced/patches/shared/misc/settings/preference/BasePreference
public final class app/revanced/patches/shared/misc/settings/preference/InputType : java/lang/Enum {
public static final field NUMBER Lapp/revanced/patches/shared/misc/settings/preference/InputType;
public static final field NUMBER_DECIMAL Lapp/revanced/patches/shared/misc/settings/preference/InputType;
public static final field TEXT Lapp/revanced/patches/shared/misc/settings/preference/InputType;
public static final field TEXT_CAP_CHARACTERS Lapp/revanced/patches/shared/misc/settings/preference/InputType;
public static final field TEXT_MULTI_LINE Lapp/revanced/patches/shared/misc/settings/preference/InputType;
@ -1447,10 +1448,6 @@ public final class app/revanced/patches/youtube/video/speed/button/PlaybackSpeed
public static final fun getPlaybackSpeedButtonPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}
public final class app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatchKt {
public static final fun getSpeedUnavailableId ()J
}
public final class app/revanced/patches/youtube/video/videoid/VideoIdPatchKt {
public static final fun getVideoIdPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
public static final fun hookBackgroundPlayVideoId (Ljava/lang/String;)V

View File

@ -5,4 +5,5 @@ enum class InputType(val type: String) {
TEXT_CAP_CHARACTERS("textCapCharacters"),
TEXT_MULTI_LINE("textMultiLine"),
NUMBER("number"),
NUMBER_DECIMAL("numberDecimal"),
}

View File

@ -17,22 +17,26 @@ import app.revanced.patches.shared.misc.mapping.resourceMappings
import app.revanced.patches.shared.misc.settings.preference.InputType
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.shared.misc.settings.preference.TextPreference
import app.revanced.patches.youtube.interaction.seekbar.disableFastForwardNoticeFingerprint
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.litho.filter.addLithoFilter
import app.revanced.patches.youtube.misc.litho.filter.lithoFilterPatch
import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.addRecyclerViewTreeHook
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.recyclerViewTreeHookPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.*
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableField
var speedUnavailableId = -1L
internal set
internal var speedUnavailableId = -1L
private set
private val customPlaybackSpeedResourcePatch = resourcePatch {
dependsOn(resourceMappingPatch)
@ -61,6 +65,7 @@ internal val customPlaybackSpeedPatch = bytecodePatch(
recyclerViewTreeHookPatch,
customPlaybackSpeedResourcePatch,
addResourcesPatch,
versionCheckPatch
)
execute {
@ -71,6 +76,12 @@ internal val customPlaybackSpeedPatch = bytecodePatch(
TextPreference("revanced_custom_playback_speeds", inputType = InputType.TEXT_MULTI_LINE),
)
if (is_19_25_or_greater) {
PreferenceScreen.VIDEO.addPreferences(
TextPreference("revanced_speed_tap_and_hold", inputType = InputType.NUMBER_DECIMAL),
)
}
// Replace the speeds float array with custom speeds.
speedArrayGeneratorFingerprint.method.apply {
val sizeCallIndex = indexOfFirstInstructionOrThrow { getReference<MethodReference>()?.name == "size" }
@ -166,5 +177,27 @@ internal val customPlaybackSpeedPatch = bytecodePatch(
addLithoFilter(FILTER_CLASS_DESCRIPTOR)
// endregion
// region Custom tap and hold 2x speed.
if (is_19_25_or_greater) {
disableFastForwardNoticeFingerprint.method.apply {
val index = indexOfFirstInstructionOrThrow {
(this as? NarrowLiteralInstruction)?.narrowLiteral == 2.0f.toRawBits()
}
val register = getInstruction<OneRegisterInstruction>(index).registerA
addInstructions(
index + 1,
"""
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->tapAndHoldSpeed()F
move-result v$register
"""
)
}
}
// endregion
}
}

View File

@ -1351,6 +1351,8 @@ Enabling this can unlock higher video qualities"</string>
<string name="revanced_custom_playback_speeds_invalid">Custom speeds must be less than %s</string>
<string name="revanced_custom_playback_speeds_parse_exception">Invalid custom playback speeds</string>
<string name="revanced_custom_playback_speeds_auto">Auto</string>
<string name="revanced_speed_tap_and_hold_title">Custom tap and hold speed</string>
<string name="revanced_speed_tap_and_hold_summary">Playback speed between 0-8</string>
</patch>
<patch id="video.speed.remember.rememberPlaybackSpeedPatch">
<string name="revanced_remember_playback_speed_last_selected_title">Remember playback speed changes</string>