add bitrate-default-value patch

This commit is contained in:
inotia00 2023-04-28 11:27:48 +09:00
parent 63c2145d13
commit 8f12e6ae93

View File

@ -0,0 +1,43 @@
package app.revanced.patches.music.misc.bitrate.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
@Patch
@Name("bitrate-default-value")
@Description("Set the audio quality to 'Always High' when you first install the app.")
@YouTubeMusicCompatibility
@Version("0.0.1")
class BitrateDefaultValuePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor[RESOURCE_FILE_PATH].use { editor ->
editor.file.getElementsByTagName("com.google.android.apps.youtube.music.ui.preference.PreferenceCategoryCompat").item(0).childNodes.apply {
arrayOf("BitrateAudioMobile", "BitrateAudioWiFi").forEach {
for (i in 1 until length) {
val view = item(i)
if (
view.hasAttributes() &&
view.attributes.getNamedItem("android:key").nodeValue.endsWith(it)
) {
view.attributes.getNamedItem("android:defaultValue").nodeValue = "Always High"
break
}
}
}
}
}
return PatchResultSuccess()
}
private companion object {
const val RESOURCE_FILE_PATH = "res/xml/data_saving_settings.xml"
}
}