Skip to content

Commit

Permalink
change video speed to playback speed (inotia00#13)
Browse files Browse the repository at this point in the history
* feat(youtube): `video-speed` renamed to `playback-speed`

* Update revanced_prefs.xml

* update missing text

* more video speed
  • Loading branch information
kazimmt authored Jul 21, 2023
1 parent 84fd6a8 commit 6bc8701
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction35c

@Patch
@Name("Enable time stamps speed")
@Description("Add the current video speed in brackets next to the current time.")
@Description("Add the current playback speed in brackets next to the current time.")
@DependsOn(
[
OverrideSpeedHookPatch::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.revanced.patches.youtube.utils.overridespeed.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

object VideoSpeedChangedFingerprint : MethodFingerprint(
object PlaybackSpeedChangedFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.IF_EQZ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode

object VideoSpeedParentFingerprint : MethodFingerprint(
object PlaybackSpeedParentFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L", "L", "[L", "I"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags

object VideoSpeedPatchFingerprint : MethodFingerprint(
object PlaybackSpeedPatchFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("F"),
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/VideoSpeedPatch;") && methodDef.name == "overrideSpeed" }
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/PlaybackSpeedPatch;") && methodDef.name == "overrideSpeed" }
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.youtube.utils.overridespeed.fingerprints.SpeedClassFingerprint
import app.revanced.patches.youtube.utils.overridespeed.fingerprints.VideoSpeedChangedFingerprint
import app.revanced.patches.youtube.utils.overridespeed.fingerprints.VideoSpeedParentFingerprint
import app.revanced.patches.youtube.utils.overridespeed.fingerprints.VideoSpeedPatchFingerprint
import app.revanced.patches.youtube.utils.overridespeed.fingerprints.PlaybackSpeedChangedFingerprint
import app.revanced.patches.youtube.utils.overridespeed.fingerprints.PlaybackSpeedParentFingerprint
import app.revanced.patches.youtube.utils.overridespeed.fingerprints.PlaybackSpeedPatchFingerprint
import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH
import app.revanced.util.integrations.Constants.VIDEO_PATH
import org.jf.dexlib2.AccessFlags
Expand All @@ -35,18 +35,18 @@ import org.jf.dexlib2.immutable.ImmutableMethodParameter
class OverrideSpeedHookPatch : BytecodePatch(
listOf(
SpeedClassFingerprint,
VideoSpeedPatchFingerprint,
VideoSpeedParentFingerprint
PlaybackSpeedPatchFingerprint,
PlaybackSpeedParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {

VideoSpeedParentFingerprint.result?.let { parentResult ->
PlaybackSpeedParentFingerprint.result?.let { parentResult ->
val parentClassDef = parentResult.classDef

VideoSpeedChangedFingerprint.also { it.resolve(context, parentClassDef) }.result?.let {
PlaybackSpeedChangedFingerprint.also { it.resolve(context, parentClassDef) }.result?.let {
it.mutableMethod.apply {
videoSpeedChangedResult = it
playbackSpeedChangedResult = it
val startIndex = it.scanResult.patternScanResult!!.startIndex
val endIndex = it.scanResult.patternScanResult!!.endIndex

Expand Down Expand Up @@ -95,8 +95,8 @@ class OverrideSpeedHookPatch : BytecodePatch(
}
}

} ?: return VideoSpeedChangedFingerprint.toErrorResult()
} ?: return VideoSpeedParentFingerprint.toErrorResult()
} ?: return PlaybackSpeedChangedFingerprint.toErrorResult()
} ?: return PlaybackSpeedParentFingerprint.toErrorResult()


SpeedClassFingerprint.result?.let {
Expand All @@ -106,7 +106,7 @@ class OverrideSpeedHookPatch : BytecodePatch(
SPEED_CLASS = this.returnType
replaceInstruction(
index,
"sput-object v$register, $INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->speedClass:$SPEED_CLASS"
"sput-object v$register, $INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->speedClass:$SPEED_CLASS"
)
addInstruction(
index + 1,
Expand All @@ -116,7 +116,7 @@ class OverrideSpeedHookPatch : BytecodePatch(

} ?: return SpeedClassFingerprint.toErrorResult()

VideoSpeedPatchFingerprint.result?.let {
PlaybackSpeedPatchFingerprint.result?.let {
it.mutableMethod.apply {
it.mutableClass.staticFields.add(
ImmutableField(
Expand All @@ -132,25 +132,25 @@ class OverrideSpeedHookPatch : BytecodePatch(

addInstructions(
0, """
sget-object v0, $INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->speedClass:$SPEED_CLASS
sget-object v0, $INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->speedClass:$SPEED_CLASS
invoke-virtual {v0, p0}, $SPEED_CLASS->overrideSpeed(F)V
"""
)
}

} ?: return VideoSpeedPatchFingerprint.toErrorResult()
} ?: return PlaybackSpeedPatchFingerprint.toErrorResult()

return PatchResultSuccess()
}

internal companion object {
const val INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR =
"$VIDEO_PATH/VideoSpeedPatch;"
const val INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR =
"$VIDEO_PATH/PlaybackSpeedPatch;"

const val INTEGRATIONS_VIDEO_HELPER_CLASS_DESCRIPTOR =
"$INTEGRATIONS_PATH/utils/VideoHelpers;"

lateinit var videoSpeedChangedResult: MethodFingerprintResult
lateinit var playbackSpeedChangedResult: MethodFingerprintResult

private lateinit var SPEED_CLASS: String
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.iface.reference.MethodReference

@Patch
@Name("Custom video speed")
@Description("Adds more video speed options.")
@Name("Custom playback speed")
@Description("Adds more playback speed options.")
@DependsOn(
[
OldSpeedLayoutPatch::class,
Expand All @@ -38,7 +38,7 @@ import org.jf.dexlib2.iface.reference.MethodReference
)
@YouTubeCompatibility
@Version("0.0.1")
class CustomVideoSpeedPatch : BytecodePatch(
class CustomPlaybackSpeedPatch : BytecodePatch(
listOf(
SpeedArrayGeneratorFingerprint,
SpeedLimiterFallBackFingerprint,
Expand All @@ -53,7 +53,7 @@ class CustomVideoSpeedPatch : BytecodePatch(

addInstructions(
targetIndex + 1, """
invoke-static {v$targetRegister}, $VIDEO_PATH/CustomVideoSpeedPatch;->getLength(I)I
invoke-static {v$targetRegister}, $VIDEO_PATH/CustomPlaybackSpeedPatch;->getLength(I)I
move-result v$targetRegister
"""
)
Expand All @@ -70,7 +70,7 @@ class CustomVideoSpeedPatch : BytecodePatch(

addInstructions(
index + 2, """
invoke-static {v$register}, $VIDEO_PATH/CustomVideoSpeedPatch;->getSize(I)I
invoke-static {v$register}, $VIDEO_PATH/CustomPlaybackSpeedPatch;->getSize(I)I
move-result v$register
"""
)
Expand All @@ -89,7 +89,7 @@ class CustomVideoSpeedPatch : BytecodePatch(

addInstructions(
index + 1, """
invoke-static {v$register}, $VIDEO_PATH/CustomVideoSpeedPatch;->getArray([F)[F
invoke-static {v$register}, $VIDEO_PATH/CustomPlaybackSpeedPatch;->getArray([F)[F
move-result-object v$register
"""
)
Expand Down Expand Up @@ -133,11 +133,11 @@ class CustomVideoSpeedPatch : BytecodePatch(
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: VIDEO_SETTINGS",
"SETTINGS: CUSTOM_VIDEO_SPEED"
"SETTINGS: CUSTOM_PLAYBACK_SPEED"
)
)

SettingsPatch.updatePatchStatus("custom-video-speed")
SettingsPatch.updatePatchStatus("custom-playback-speed")

return PatchResultSuccess()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode

object NewVideoSpeedChangedFingerprint : MethodFingerprint(
object NewPlaybackSpeedChangedFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import app.revanced.patches.youtube.utils.fingerprints.NewFlyoutPanelOnClickList
import app.revanced.patches.youtube.utils.overridespeed.patch.OverrideSpeedHookPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.utils.videocpn.patch.VideoCpnPatch
import app.revanced.patches.youtube.video.speed.fingerprints.NewVideoSpeedChangedFingerprint
import app.revanced.patches.youtube.video.speed.fingerprints.NewPlaybackSpeedChangedFingerprint
import app.revanced.util.integrations.Constants.VIDEO_PATH
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction

@Patch
@Name("Default video speed")
@Description("Adds ability to set default video speed settings.")
@Name("Default playback speed")
@Description("Adds ability to set default playback speed settings.")
@DependsOn(
[
OverrideSpeedHookPatch::class,
Expand All @@ -33,51 +33,51 @@ import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
)
@YouTubeCompatibility
@Version("0.0.1")
class VideoSpeedPatch : BytecodePatch(
class PlaybackSpeedPatch : BytecodePatch(
listOf(NewFlyoutPanelOnClickListenerFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {

NewFlyoutPanelOnClickListenerFingerprint.result?.let { parentResult ->
NewVideoSpeedChangedFingerprint.also {
NewPlaybackSpeedChangedFingerprint.also {
it.resolve(
context,
parentResult.classDef
)
}.result?.let { result ->
arrayOf(result, OverrideSpeedHookPatch.videoSpeedChangedResult).forEach {
arrayOf(result, OverrideSpeedHookPatch.playbackSpeedChangedResult).forEach {
it.mutableMethod.apply {
val index = it.scanResult.patternScanResult!!.endIndex
val register = getInstruction<FiveRegisterInstruction>(index).registerD

addInstruction(
index,
"invoke-static {v$register}, $INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->userChangedSpeed(F)V"
"invoke-static {v$register}, $INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->userChangedSpeed(F)V"
)
}
}
} ?: return NewVideoSpeedChangedFingerprint.toErrorResult()
} ?: return NewPlaybackSpeedChangedFingerprint.toErrorResult()
} ?: return NewFlyoutPanelOnClickListenerFingerprint.toErrorResult()

VideoCpnPatch.injectCall("$INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;Z)V")
VideoCpnPatch.injectCall("$INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;Z)V")

/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: VIDEO_SETTINGS",
"SETTINGS: DEFAULT_VIDEO_SPEED"
"SETTINGS: DEFAULT_PLAYBACK_SPEED"
)
)

SettingsPatch.updatePatchStatus("default-video-speed")
SettingsPatch.updatePatchStatus("default-playback-speed")

return PatchResultSuccess()
}

private companion object {
const val INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR =
"$VIDEO_PATH/VideoSpeedPatch;"
const val INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR =
"$VIDEO_PATH/PlaybackSpeedPatch;"
}
}
Loading

0 comments on commit 6bc8701

Please sign in to comment.