mirror of
https://github.com/revanced/revanced-patches
synced 2024-09-03 04:56:05 +02:00
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 <johan.melkonyan1@web.de>
This commit is contained in:
parent
bd224d90de
commit
fbb17636d8
@ -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<StringResource>
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user