Skip to content

Commit

Permalink
feat(YouTube): Add Watch history patch
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and anddea committed Jul 29, 2024
1 parent a7b944d commit f1fd6e6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package app.revanced.patches.youtube.misc.watchhistory

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patches.youtube.misc.watchhistory.fingerprints.TrackingUrlModelFingerprint
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction

@Suppress("unused")
object WatchHistoryPatch : BaseBytecodePatch(
name = "Watch history",
description = "Adds an option to change the domain of the watch history or check its status.",
dependencies = setOf(SettingsPatch::class),
compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(TrackingUrlModelFingerprint)
) {
override fun execute(context: BytecodeContext) {

TrackingUrlModelFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA

addInstructions(
targetIndex + 1, """
invoke-static {v$targetRegister}, $MISC_PATH/WatchHistoryPatch;->replaceTrackingUrl(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$targetRegister
"""
)
}
}

/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"SETTINGS: WATCH_HISTORY"
)
)

SettingsPatch.updatePatchStatus(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.revanced.patches.youtube.misc.watchhistory.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

internal object TrackingUrlModelFingerprint : MethodFingerprint(
returnType = "Landroid/net/Uri;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(),
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
),
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/player/TrackingUrlModel;"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import app.revanced.patches.youtube.utils.fix.client.fingerprints.NerdsStatsVide
import app.revanced.patches.youtube.utils.fix.client.fingerprints.PlayerGestureConfigSyntheticFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.SetPlayerRequestClientTypeFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.integrations.Constants.PATCH_STATUS_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.storyboard.StoryboardHookPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
Expand All @@ -30,6 +31,7 @@ import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import app.revanced.util.updatePatchStatus
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
Expand Down Expand Up @@ -360,6 +362,8 @@ object SpoofClientPatch : BaseBytecodePatch(

// endregion

context.updatePatchStatus(PATCH_STATUS_CLASS_DESCRIPTOR, "SpoofClient")

/**
* Add settings
*/
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/youtube/settings/host/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,14 @@
<item>17.41.37</item>
<item>17.33.42</item>
</string-array>
<string-array name="revanced_watch_history_type_entries">
<item>@string/revanced_watch_history_type_entry_1</item>
<item>@string/revanced_watch_history_type_entry_2</item>
<item>@string/revanced_watch_history_type_entry_3</item>
</string-array>
<string-array name="revanced_watch_history_type_entry_values">
<item>ORIGINAL</item>
<item>REPLACE</item>
<item>BLOCK</item>
</string-array>
</resources>
9 changes: 9 additions & 0 deletions src/main/resources/youtube/settings/xml/revanced_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,15 @@
<Preference android:title="@string/revanced_spoof_client_use_android_vr_title" android:key="revanced_spoof_client_use_android_vr" android:selectable="false" android:summary="@string/revanced_spoof_client_use_android_vr_summary" android:dependency="revanced_spoof_client" />
</PreferenceScreen>SETTINGS: SPOOF_CLIENT -->

<!-- SETTINGS: WATCH_HISTORY
<PreferenceScreen android:title="@string/revanced_preference_screen_watch_history_title" android:key="revanced_preference_screen_watch_history" android:summary="@string/revanced_preference_screen_watch_history_summary">
<Preference android:title="@string/revanced_watch_history_management_title" android:summary="@string/revanced_watch_history_management_summary">
<intent android:action="android.intent.action.VIEW" android:data="https://history.google.com/history/youtube/watch" />
</Preference>
<ListPreference android:entries="@array/revanced_watch_history_type_entries" android:title="@string/revanced_watch_history_type_title" android:key="revanced_watch_history_type" android:entryValues="@array/revanced_watch_history_type_entry_values" />
<app.revanced.integrations.youtube.settings.preference.WatchHistoryStatusPreference android:title="@string/revanced_watch_history_about_title" />
</PreferenceScreen>SETTINGS: WATCH_HISTORY -->

<!-- SETTINGS: DISABLE_QUIC_PROTOCOL
<SwitchPreference android:title="@string/revanced_disable_quic_protocol_title" android:key="revanced_disable_quic_protocol" android:defaultValue="false" android:summary="@string/revanced_disable_quic_protocol_summary" />SETTINGS: DISABLE_QUIC_PROTOCOL -->

Expand Down

0 comments on commit f1fd6e6

Please sign in to comment.