From fbb17636d8ab9f2a43ead896451804b04464527c Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Fri, 14 Apr 2023 05:50:41 +0400 Subject: [PATCH] feat(youtube): change default video speed and quality inside the settings menu (#1880) Co-authored-by: johnconner122 <107796137+johnconner122@users.noreply.github.com> Co-authored-by: oSumAtrIX --- .../settings/preference/impl/ArrayResource.kt | 1 + .../patch/RememberVideoQualityPatch.kt | 48 +++++++++++++++++++ .../custom/patch/CustomVideoSpeedPatch.kt | 2 +- ...nitializePlaybackSpeedValuesFingerprint.kt | 2 +- .../patch/RememberPlaybackSpeedPatch.kt | 26 +++++++++- 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/ArrayResource.kt b/src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/ArrayResource.kt index 608dccca4..90795e1f7 100644 --- a/src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/ArrayResource.kt +++ b/src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/ArrayResource.kt @@ -11,6 +11,7 @@ import org.w3c.dom.Element * @param name The name of the array resource. * @param items The items of the array resource. */ +// TODO: allow specifying an array resource file instead of using a list of StringResources internal data class ArrayResource( override val name: String, val items: List diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/video/quality/patch/RememberVideoQualityPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/video/quality/patch/RememberVideoQualityPatch.kt index 28b382d76..d5a03e33b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/video/quality/patch/RememberVideoQualityPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/video/quality/patch/RememberVideoQualityPatch.kt @@ -14,6 +14,8 @@ import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.shared.settings.preference.impl.ArrayResource +import app.revanced.patches.shared.settings.preference.impl.ListPreference import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch @@ -58,6 +60,52 @@ class RememberVideoQualityPatch : BytecodePatch( ) ) + // This is bloated as each value has it's own String key/value + // ideally the entries would be raw values (and not a key to a String resource) + val entries = listOf( + StringResource("revanced_default_quality_entry_1", "Automatic quality"), + StringResource("revanced_default_quality_entry_2", "2160p"), + StringResource("revanced_default_quality_entry_3", "1440p"), + StringResource("revanced_default_quality_entry_4", "1080p"), + StringResource("revanced_default_quality_entry_5", "720p"), + StringResource("revanced_default_quality_entry_6", "480p"), + StringResource("revanced_default_quality_entry_7", "360p"), + StringResource("revanced_default_quality_entry_8", "280p"), + StringResource("revanced_default_quality_entry_9", "144p"), + ) + val entryValues = listOf( + StringResource("revanced_default_quality_entry_value_1", "-2"), + StringResource("revanced_default_quality_entry_value_2", "2160"), + StringResource("revanced_default_quality_entry_value_3", "1440"), + StringResource("revanced_default_quality_entry_value_4", "1080"), + StringResource("revanced_default_quality_entry_value_5", "720"), + StringResource("revanced_default_quality_entry_value_6", "480"), + StringResource("revanced_default_quality_entry_value_7", "360"), + StringResource("revanced_default_quality_entry_value_8", "280"), + StringResource("revanced_default_quality_entry_value_9", "144"), + ) + SettingsPatch.PreferenceScreen.MISC.addPreferences( + ListPreference( + "revanced_default_video_quality_wifi", + StringResource( + "revanced_default_video_quality_wifi_title", + "Default video quality on Wi-Fi network" + ), + ArrayResource("revanced_video_quality_wifi_entry", entries), + ArrayResource("revanced_video_quality_wifi_entry_values", entryValues) + // default value and summary are set by integrations after loading + ), + ListPreference( + "revanced_default_video_quality_mobile", + StringResource( + "revanced_default_video_quality_mobile_title", + "Default video quality on mobile network" + ), + ArrayResource("revanced_video_quality_mobile_entries", entries), + ArrayResource("revanced_video_quality_mobile_entry_values", entryValues) + ) + ) + /* * The following code works by hooking the method which is called when the user selects a video quality * to remember the last selected video quality. diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/custom/patch/CustomVideoSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/custom/patch/CustomVideoSpeedPatch.kt index 1b76883b7..c038ba497 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/custom/patch/CustomVideoSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/custom/patch/CustomVideoSpeedPatch.kt @@ -9,11 +9,11 @@ import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.* import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.video.speed.custom.annotations.CustomPlaybackSpeedCompatibility import app.revanced.patches.youtube.misc.video.speed.custom.fingerprints.SpeedArrayGeneratorFingerprint import app.revanced.patches.youtube.misc.video.speed.custom.fingerprints.SpeedLimiterFingerprint import app.revanced.patches.youtube.misc.video.speed.custom.fingerprints.VideoSpeedPatchFingerprint -import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import org.jf.dexlib2.builder.instruction.BuilderArrayPayload import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/fingerprint/InitializePlaybackSpeedValuesFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/fingerprint/InitializePlaybackSpeedValuesFingerprint.kt index ead76aa8d..e244a298e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/fingerprint/InitializePlaybackSpeedValuesFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/fingerprint/InitializePlaybackSpeedValuesFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.video.speed.current.fingerprint +package app.revanced.patches.youtube.misc.video.speed.remember.fingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/patch/RememberPlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/patch/RememberPlaybackSpeedPatch.kt index 2dfd34fa0..4895e665a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/patch/RememberPlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/video/speed/remember/patch/RememberPlaybackSpeedPatch.kt @@ -11,14 +11,16 @@ import app.revanced.patcher.patch.* import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.shared.settings.preference.impl.ArrayResource +import app.revanced.patches.shared.settings.preference.impl.ListPreference import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.video.information.patch.VideoInformationPatch import app.revanced.patches.youtube.misc.video.information.patch.VideoInformationPatch.Companion.reference -import app.revanced.patches.youtube.misc.video.speed.current.fingerprint.InitializePlaybackSpeedValuesFingerprint import app.revanced.patches.youtube.misc.video.speed.remember.annotation.RememberPlaybackSpeedCompatibility +import app.revanced.patches.youtube.misc.video.speed.remember.fingerprint.InitializePlaybackSpeedValuesFingerprint import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch @Patch @@ -52,6 +54,27 @@ class RememberPlaybackSpeedPatch : BytecodePatch( ) ) + SettingsPatch.PreferenceScreen.MISC.addPreferences( + ListPreference( + "revanced_default_playback_speed", + StringResource( + "revanced_default_playback_speed_title", + "Default playback speed" + ), + // Dummy data: + // Entries and values are set by Integrations code based on the actual speeds available, + // and the values set here are ignored and do nothing. + ArrayResource( + "revanced_default_playback_speed_entries", + listOf(StringResource("revanced_default_playback_speed_entry", "1.0x")) + ), + ArrayResource( + "revanced_default_playback_speed_entry_values", + listOf(StringResource("revanced_default_playback_speed_entry_value", "1.0")) + ) + ) + ) + VideoIdPatch.injectCall("${INTEGRATIONS_CLASS_DESCRIPTOR}->newVideoLoaded(Ljava/lang/String;)V") VideoInformationPatch.userSelectedPlaybackSpeedHook( @@ -92,7 +115,6 @@ class RememberPlaybackSpeedPatch : BytecodePatch( ) } ?: return InitializePlaybackSpeedValuesFingerprint.toErrorResult() - return PatchResultSuccess() }