From 2e9cc8d3b2eba92181beb2b23437e42242b64fc2 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:12:48 +0400 Subject: [PATCH 1/3] fix(YouTube - Spoof video streams): Use system language as default iOS audio stream --- .../extension/youtube/patches/spoof/requests/PlayerRoutes.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java index 8d6782cb31..f6e3082100 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java @@ -7,6 +7,7 @@ import java.net.HttpURLConnection; import app.revanced.extension.shared.Logger; +import app.revanced.extension.shared.Utils; import app.revanced.extension.shared.requests.Requester; import app.revanced.extension.shared.requests.Route; import app.revanced.extension.youtube.patches.spoof.ClientType; @@ -41,6 +42,8 @@ static String createInnertubeBody(ClientType clientType) { if (clientType.androidSdkVersion != null) { client.put("androidSdkVersion", clientType.androidSdkVersion); } + String languageCode = Utils.getContext().getResources().getConfiguration().locale.getLanguage(); + client.put("hl", languageCode); context.put("client", client); From 78a6dba936d9ab2f24428ec745801d223b858f2a Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:13:04 +0400 Subject: [PATCH 2/3] fix extension refactor --- .../revanced/extension/shared/settings/Setting.java | 2 +- .../settings/preference/ImportExportPreference.java | 6 +++--- .../youtube/sponsorblock/SponsorBlockSettings.java | 11 ++--------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/Setting.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/Setting.java index 5f5a974748..db5ecc844b 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/Setting.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/Setting.java @@ -438,7 +438,7 @@ public static boolean importFromJSON(@NonNull Context alertDialogContext, @NonNu } for (ImportExportCallback callback : importExportCallbacks) { - callback.settingsExported(alertDialogContext); + callback.settingsImported(alertDialogContext); } Utils.showToastLong(numberOfSettingsImported == 0 diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ImportExportPreference.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ImportExportPreference.java index 4c06a97df0..a1d051c2b8 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ImportExportPreference.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ImportExportPreference.java @@ -72,21 +72,21 @@ protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { builder.setNeutralButton(str("revanced_settings_import_copy"), (dialog, which) -> { Utils.setClipboard(getEditText().getText().toString()); }).setPositiveButton(str("revanced_settings_import"), (dialog, which) -> { - importSettings(getEditText().getText().toString()); + importSettings(builder.getContext(), getEditText().getText().toString()); }); } catch (Exception ex) { Logger.printException(() -> "onPrepareDialogBuilder failure", ex); } } - private void importSettings(String replacementSettings) { + private void importSettings(Context context, String replacementSettings) { try { if (replacementSettings.equals(existingSettings)) { return; } AbstractPreferenceFragment.settingImportInProgress = true; - final boolean rebootNeeded = Setting.importFromJSON(Utils.getContext(), replacementSettings); + final boolean rebootNeeded = Setting.importFromJSON(context, replacementSettings); if (rebootNeeded) { AbstractPreferenceFragment.showRestartDialog(getContext()); } diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/sponsorblock/SponsorBlockSettings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/sponsorblock/SponsorBlockSettings.java index 00ecfacf98..45739f267f 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/sponsorblock/SponsorBlockSettings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/sponsorblock/SponsorBlockSettings.java @@ -30,7 +30,7 @@ public class SponsorBlockSettings { public static final Setting.ImportExportCallback SB_IMPORT_EXPORT_CALLBACK = new Setting.ImportExportCallback() { @Override public void settingsImported(@Nullable Context context) { - updateFromImportedSettings(); + SegmentCategory.loadAllCategoriesFromSettings(); } @Override public void settingsExported(@Nullable Context context) { @@ -172,7 +172,7 @@ public static String exportDesktopSettings() { /** * Export the categories using flatten json (no embedded dictionaries or arrays). */ - public static void showExportWarningIfNeeded(@Nullable Context dialogContext) { + private static void showExportWarningIfNeeded(@Nullable Context dialogContext) { Utils.verifyOnMainThread(); initialize(); @@ -245,11 +245,4 @@ public static void initialize() { SegmentCategory.updateEnabledCategories(); } - - /** - * Updates internal data based on {@link Setting} values. - */ - public static void updateFromImportedSettings() { - SegmentCategory.loadAllCategoriesFromSettings(); - } } From 99f90a45e7bcfa864fb636839dfb4352eeaade05 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:41:30 +0400 Subject: [PATCH 3/3] refactor --- .../youtube/patches/spoof/requests/PlayerRoutes.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java index f6e3082100..f77288ccc3 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/requests/PlayerRoutes.java @@ -25,6 +25,9 @@ final class PlayerRoutes { */ private static final int CONNECTION_TIMEOUT_MILLISECONDS = 10 * 1000; // 10 Seconds. + private static final String LOCALE_LANGUAGE = Utils.getContext().getResources() + .getConfiguration().locale.getLanguage(); + private PlayerRoutes() { } @@ -35,6 +38,8 @@ static String createInnertubeBody(ClientType clientType) { JSONObject context = new JSONObject(); JSONObject client = new JSONObject(); + // Required to use correct default audio channel with iOS. + client.put("hl", LOCALE_LANGUAGE); client.put("clientName", clientType.name()); client.put("clientVersion", clientType.clientVersion); client.put("deviceModel", clientType.deviceModel); @@ -42,9 +47,6 @@ static String createInnertubeBody(ClientType clientType) { if (clientType.androidSdkVersion != null) { client.put("androidSdkVersion", clientType.androidSdkVersion); } - String languageCode = Utils.getContext().getResources().getConfiguration().locale.getLanguage(); - client.put("hl", languageCode); - context.put("client", client); innerTubeBody.put("context", context);