feat(YouTube - Set transcript cookies): Add "Fix transcript" setting
Close https://github.com/anddea/revanced-patches/issues/1379
This commit is contained in:
parent
06275f4cf4
commit
7c42e04238
7 changed files with 65 additions and 1 deletions
|
|
@ -4,12 +4,19 @@ import android.net.Uri;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import app.morphe.extension.shared.utils.Logger;
|
||||
import app.morphe.extension.youtube.settings.Settings;
|
||||
import app.morphe.extension.youtube.utils.ExtendedUtils;
|
||||
|
||||
@SuppressWarnings({"deprecation", "unused"})
|
||||
public final class TranscriptCookiePatch {
|
||||
|
||||
private static final boolean FIX_TRANSCRIPT =
|
||||
Settings.FIX_TRANSCRIPT.get() &&
|
||||
!ExtendedUtils.isSpoofingToLessThan("20.05.00");
|
||||
|
||||
private static final boolean SET_TRANSCRIPT_COOKIES =
|
||||
Settings.SET_TRANSCRIPT_COOKIES.get();
|
||||
|
||||
|
|
@ -69,4 +76,29 @@ public final class TranscriptCookiePatch {
|
|||
return USER_AGENT_CHROME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static byte[] fixTranscriptRequestBody(String url, byte[] requestBody) {
|
||||
if (!FIX_TRANSCRIPT || requestBody == null || !StringUtils.contains(url, "get_transcript")) {
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
try {
|
||||
String body = new String(requestBody, StandardCharsets.UTF_8);
|
||||
String updatedBody = body.replaceFirst(
|
||||
"\"clientVersion\":\"[^\"]+\"",
|
||||
"\"clientVersion\":\"20.05.46\""
|
||||
);
|
||||
|
||||
return updatedBody.equals(body)
|
||||
? requestBody
|
||||
: updatedBody.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "fixTranscriptRequestBody failure", ex);
|
||||
}
|
||||
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,6 +192,7 @@ public class Settings extends SharedYouTubeSettings {
|
|||
public static final BooleanSetting HIDE_FLOATING_MICROPHONE = new BooleanSetting("revanced_hide_floating_microphone", TRUE, true);
|
||||
public static final BooleanSetting HIDE_VISUAL_SPACER = new BooleanSetting("revanced_hide_visual_spacer", TRUE);
|
||||
public static final BooleanSetting REMOVE_VIEWER_DISCRETION_DIALOG = new BooleanSetting("revanced_remove_viewer_discretion_dialog", FALSE);
|
||||
public static final BooleanSetting FIX_TRANSCRIPT = new BooleanSetting("revanced_fix_transcript", TRUE, true);
|
||||
public static final BooleanSetting SET_TRANSCRIPT_COOKIES = new BooleanSetting("revanced_set_transcript_cookies", FALSE, true, "revanced_set_transcript_cookies_user_dialog_message");
|
||||
public static final BooleanSetting SET_TRANSCRIPT_COOKIES_ALL = new BooleanSetting("revanced_set_transcript_cookies_all", FALSE, true, parent(SET_TRANSCRIPT_COOKIES));
|
||||
public static final StringSetting TRANSCRIPT_COOKIES = new StringSetting("revanced_transcript_cookies", "", true, parent(SET_TRANSCRIPT_COOKIES));
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import app.morphe.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMuta
|
|||
import app.morphe.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
||||
import app.morphe.patches.youtube.utils.extension.Constants.GENERAL_PATH
|
||||
import app.morphe.patches.youtube.utils.patch.PatchList.SET_TRANSCRIPT_COOKIES
|
||||
import app.morphe.patches.youtube.utils.request.buildRequestPatch
|
||||
import app.morphe.patches.youtube.utils.request.hookBuildRequestBody
|
||||
import app.morphe.patches.youtube.utils.settings.ResourceUtils.addPreference
|
||||
import app.morphe.patches.youtube.utils.settings.settingsPatch
|
||||
import app.morphe.patches.youtube.utils.webview.webViewPatch
|
||||
|
|
@ -32,6 +34,7 @@ val autoCaptionsPatch = bytecodePatch(
|
|||
dependsOn(
|
||||
settingsPatch,
|
||||
webViewPatch,
|
||||
buildRequestPatch,
|
||||
)
|
||||
|
||||
execute {
|
||||
|
|
@ -102,11 +105,18 @@ val autoCaptionsPatch = bytecodePatch(
|
|||
|
||||
// endregion
|
||||
|
||||
// region patch for fix transcript
|
||||
|
||||
hookBuildRequestBody("$EXTENSION_CLASS_DESCRIPTOR->fixTranscriptRequestBody(Ljava/lang/String;[B)[B")
|
||||
|
||||
// endregion
|
||||
|
||||
// region add settings
|
||||
|
||||
addPreference(
|
||||
arrayOf(
|
||||
"PREFERENCE_SCREEN: GENERAL",
|
||||
"SETTINGS: FIX_TRANSCRIPT",
|
||||
"SETTINGS: SET_TRANSCRIPT_COOKIES"
|
||||
),
|
||||
SET_TRANSCRIPT_COOKIES
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ internal enum class PatchList(
|
|||
"Adds options to hide or change components related to the seekbar."
|
||||
),
|
||||
SET_TRANSCRIPT_COOKIES(
|
||||
"Set Transcript Cookies",
|
||||
"Set transcript cookies",
|
||||
"Adds an option to set Cookies in YouTube Transcript API requests."
|
||||
),
|
||||
SETTINGS_FOR_YOUTUBE(
|
||||
|
|
|
|||
|
|
@ -49,3 +49,18 @@ internal fun hookBuildRequestUrl(descriptor: String) {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun hookBuildRequestBody(descriptor: String) {
|
||||
buildRequestMethod.apply {
|
||||
val insertIndex = indexOfNewUrlRequestBuilderInstruction(this)
|
||||
|
||||
addInstructions(
|
||||
insertIndex, """
|
||||
move-object/from16 v$freeRegister, p2
|
||||
invoke-static { v$urlRegister, v$freeRegister }, $descriptor
|
||||
move-result-object v$freeRegister
|
||||
move-object/from16 p2, v$freeRegister
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -614,6 +614,9 @@ This depends on what response the app receives from the server.
|
|||
If the 'Playback' setting is broken, turning on this setting may resolve the issue.
|
||||
|
||||
If the 'Playback' setting is still broken even after enabling or disabling this setting, then you should clear the app data."</string>
|
||||
<string name="revanced_fix_transcript_summary_off">Transcript may not be available due to a precondition check failure.</string>
|
||||
<string name="revanced_fix_transcript_summary_on">Transcript is available.</string>
|
||||
<string name="revanced_fix_transcript_title">Fix transcript</string>
|
||||
<string name="revanced_fix_swipe_tap_and_hold_speed_summary_off">Tap and hold speed may sometimes be activated even if the user does not tap and hold.</string>
|
||||
<string name="revanced_fix_swipe_tap_and_hold_speed_summary_on">"Tap and hold speed is only activated when the user taps and holds.
|
||||
|
||||
|
|
|
|||
|
|
@ -158,6 +158,9 @@
|
|||
<app.morphe.extension.shared.settings.preference.ResettableEditTextPreference android:title="@string/revanced_transcript_cookies_title" android:key="revanced_transcript_cookies" android:summary="@string/revanced_transcript_cookies_summary" android:inputType="textMultiLine" />
|
||||
<app.morphe.extension.youtube.settings.preference.GetCookiesPreference android:title="@string/revanced_transcript_cookies_about_title" android:key="revanced_transcript_cookies_about" android:summary="@string/revanced_transcript_cookies_about_summary" />SETTINGS: SET_TRANSCRIPT_COOKIES -->
|
||||
|
||||
<!-- SETTINGS: FIX_TRANSCRIPT
|
||||
<SwitchPreference android:title="@string/revanced_fix_transcript_title" android:key="revanced_fix_transcript" android:summaryOn="@string/revanced_fix_transcript_summary_on" android:summaryOff="@string/revanced_fix_transcript_summary_off" />SETTINGS: FIX_TRANSCRIPT -->
|
||||
|
||||
<!-- PREFERENCE_CATEGORY: GENERAL_EXPERIMENTAL_FLAGS
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>PREFERENCE_CATEGORY: GENERAL_EXPERIMENTAL_FLAGS -->
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue