feat(YouTube/Default playback speed): add Enable shorts default playback speed settings

This commit is contained in:
inotia00 2024-01-17 21:23:32 +09:00
parent a6b41eb1be
commit e613fd2d67
8 changed files with 67 additions and 8 deletions

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.utils.videoid.general.fingerprint
package app.revanced.patches.youtube.utils.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode

View File

@ -3,10 +3,13 @@ package app.revanced.patches.youtube.utils.videocpn
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.utils.fingerprints.OrganicPlaybackContextModelFingerprint
import app.revanced.patches.youtube.utils.videoid.general.VideoIdPatch
import app.revanced.util.exception
@Patch(dependencies = [VideoIdPatch::class])
object VideoCpnPatch : BytecodePatch(
setOf(OrganicPlaybackContextModelFingerprint)
) {
@ -24,7 +27,7 @@ object VideoCpnPatch : BytecodePatch(
) {
insertMethod.addInstructions(
2,
"invoke-static {p1,p2}, $methodDescriptor"
"invoke-static {p1}, $methodDescriptor"
)
}
}

View File

@ -12,11 +12,11 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.fingerprints.OrganicPlaybackContextModelFingerprint
import app.revanced.patches.youtube.utils.fingerprints.VideoEndFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH
import app.revanced.patches.youtube.utils.playerresponse.PlayerResponsePatch
import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.videoid.general.fingerprint.PlayerControllerSetTimeReferenceFingerprint
import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoEndFingerprint
import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoIdFingerprint
import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoIdParentFingerprint
import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoLengthFingerprint
@ -107,7 +107,7 @@ object VideoIdPatch : BytecodePatch(
videoTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTime")
/**
*
* Set current video is livestream
*/
OrganicPlaybackContextModelFingerprint.result?.let {
it.mutableMethod.apply {

View File

@ -112,6 +112,7 @@ object VideoQualityPatch : BytecodePatch(
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: VIDEO_SETTINGS",
"SETTINGS: VIDEO_EXPERIMENTAL_FLAGS",
"SETTINGS: DEFAULT_VIDEO_QUALITY"
)
)

View File

@ -2,20 +2,24 @@ package app.revanced.patches.youtube.video.speed
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.fingerprints.NewVideoQualityChangedFingerprint
import app.revanced.patches.youtube.utils.fingerprints.VideoEndFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH
import app.revanced.patches.youtube.utils.overridespeed.OverrideSpeedHookPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.videocpn.VideoCpnPatch
import app.revanced.patches.youtube.video.speed.fingerprints.PlaybackSpeedInitializeFingerprint
import app.revanced.patches.youtube.video.speed.fingerprints.NewPlaybackSpeedChangedFingerprint
import app.revanced.util.exception
import app.revanced.util.updatePatchStatus
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Patch(
name = "Default playback speed",
@ -54,7 +58,10 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
)
@Suppress("unused")
object PlaybackSpeedPatch : BytecodePatch(
setOf(NewVideoQualityChangedFingerprint)
setOf(
NewVideoQualityChangedFingerprint,
VideoEndFingerprint
)
) {
override fun execute(context: BytecodeContext) {
@ -79,7 +86,28 @@ object PlaybackSpeedPatch : BytecodePatch(
} ?: throw NewPlaybackSpeedChangedFingerprint.exception
} ?: throw NewVideoQualityChangedFingerprint.exception
VideoCpnPatch.injectCall("$INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;Z)V")
VideoEndFingerprint.result?.let { parentResult ->
PlaybackSpeedInitializeFingerprint.also {
it.resolve(
context,
parentResult.classDef
)
}.result?.let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
insertIndex, """
invoke-static {v$insertRegister}, $INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->getPlaybackSpeedInShorts(F)F
move-result v$insertRegister
"""
)
}
} ?: throw PlaybackSpeedInitializeFingerprint.exception
} ?: throw VideoEndFingerprint.exception
VideoCpnPatch.injectCall("$INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V")
/**
* Add settings
@ -87,6 +115,7 @@ object PlaybackSpeedPatch : BytecodePatch(
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: VIDEO_SETTINGS",
"SETTINGS: VIDEO_EXPERIMENTAL_FLAGS",
"SETTINGS: DEFAULT_PLAYBACK_SPEED"
)
)

View File

@ -0,0 +1,16 @@
package app.revanced.patches.youtube.video.speed.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object PlaybackSpeedInitializeFingerprint : MethodFingerprint(
returnType = "F",
accessFlags = AccessFlags.PRIVATE or AccessFlags.STATIC,
parameters = listOf("L"),
opcodes = listOf(
Opcode.IGET,
Opcode.RETURN
)
)

View File

@ -158,6 +158,9 @@ Note: Disabling the speed overlay restores the 'Slide to seek' behavior of the o
<string name="revanced_enable_debug_logging_summary_off">Debug logs are disabled.</string>
<string name="revanced_enable_debug_logging_summary_on">Debug logs are enabled.</string>
<string name="revanced_enable_debug_logging_title">Enable debug logging</string>
<string name="revanced_enable_default_playback_speed_shorts_summary_off">Default playback speed does not apply to Shorts.</string>
<string name="revanced_enable_default_playback_speed_shorts_summary_on">Default playback speed applies to Shorts.</string>
<string name="revanced_enable_default_playback_speed_shorts_title">Enable shorts default playback speed</string>
<string name="revanced_enable_external_browser_summary_off">External browser is disabled.</string>
<string name="revanced_enable_external_browser_summary_on">External browser is enabled.</string>
<string name="revanced_enable_external_browser_title">Enable external browser</string>

View File

@ -754,8 +754,15 @@
<SwitchPreference android:title="@string/revanced_enable_save_playback_speed_title" android:key="revanced_enable_save_playback_speed" android:defaultValue="false" android:summaryOn="@string/revanced_enable_save_playback_speed_summary_on" android:summaryOff="@string/revanced_enable_save_playback_speed_summary_off" />SETTINGS: DEFAULT_PLAYBACK_SPEED -->
<!-- SETTINGS: DEFAULT_VIDEO_QUALITY
<SwitchPreference android:title="@string/revanced_enable_save_video_quality_title" android:key="revanced_enable_save_video_quality" android:defaultValue="true" android:summaryOn="@string/revanced_enable_save_video_quality_summary_on" android:summaryOff="@string/revanced_enable_save_video_quality_summary_off" />
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />
<SwitchPreference android:title="@string/revanced_enable_save_video_quality_title" android:key="revanced_enable_save_video_quality" android:defaultValue="true" android:summaryOn="@string/revanced_enable_save_video_quality_summary_on" android:summaryOff="@string/revanced_enable_save_video_quality_summary_off" />SETTINGS: DEFAULT_VIDEO_QUALITY -->
<!-- SETTINGS: VIDEO_EXPERIMENTAL_FLAGS
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />SETTINGS: VIDEO_EXPERIMENTAL_FLAGS -->
<!-- SETTINGS: DEFAULT_PLAYBACK_SPEED
<SwitchPreference android:title="@string/revanced_enable_default_playback_speed_shorts_title" android:key="revanced_enable_default_playback_speed_shorts" android:defaultValue="false" android:summaryOn="@string/revanced_enable_default_playback_speed_shorts_summary_on" android:summaryOff="@string/revanced_enable_default_playback_speed_shorts_summary_off" />SETTINGS: DEFAULT_PLAYBACK_SPEED -->
<!-- SETTINGS: DEFAULT_VIDEO_QUALITY
<SwitchPreference android:title="@string/revanced_skip_preloaded_buffer_title" android:key="revanced_skip_preloaded_buffer" android:defaultValue="false" android:summary="@string/revanced_skip_preloaded_buffer_summary" />
<SwitchPreference android:title="@string/revanced_skip_preloaded_buffer_toast_title" android:key="revanced_skip_preloaded_buffer_toast" android:defaultValue="true" android:summaryOn="@string/revanced_skip_preloaded_buffer_toast_summary_on" android:summaryOff="@string/revanced_skip_preloaded_buffer_toast_summary_off" android:dependency="revanced_skip_preloaded_buffer" />SETTINGS: DEFAULT_VIDEO_QUALITY -->