mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-27 14:26:49 +01:00
feat(YouTube): Add Bypass image region restrictions
patch (#667)
This commit is contained in:
parent
67ff3172bb
commit
396ba77c20
@ -0,0 +1,46 @@
|
||||
package app.revanced.integrations.youtube.patches;
|
||||
|
||||
import static app.revanced.integrations.youtube.settings.Settings.BYPASS_IMAGE_REGION_RESTRICTIONS;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.youtube.settings.Settings;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class BypassImageRegionRestrictionsPatch {
|
||||
|
||||
private static final boolean BYPASS_IMAGE_REGION_RESTRICTIONS_ENABLED = BYPASS_IMAGE_REGION_RESTRICTIONS.get();
|
||||
|
||||
private static final String REPLACEMENT_IMAGE_DOMAIN = "https://yt4.ggpht.com";
|
||||
|
||||
/**
|
||||
* YouTube static images domain. Includes user and channel avatar images and community post images.
|
||||
*/
|
||||
private static final Pattern YOUTUBE_STATIC_IMAGE_DOMAIN_PATTERN
|
||||
= Pattern.compile("^https://(yt3|lh[3-6]|play-lh)\\.(ggpht|googleusercontent)\\.com");
|
||||
|
||||
/**
|
||||
* Injection point. Called off the main thread and by multiple threads at the same time.
|
||||
*
|
||||
* @param originalUrl Image url for all image urls loaded.
|
||||
*/
|
||||
public static String overrideImageURL(String originalUrl) {
|
||||
try {
|
||||
if (BYPASS_IMAGE_REGION_RESTRICTIONS_ENABLED) {
|
||||
String replacement = YOUTUBE_STATIC_IMAGE_DOMAIN_PATTERN
|
||||
.matcher(originalUrl).replaceFirst(REPLACEMENT_IMAGE_DOMAIN);
|
||||
|
||||
if (Settings.DEBUG.get() && !replacement.equals(originalUrl)) {
|
||||
Logger.printDebug(() -> "Replaced: '" + originalUrl + "' with: '" + replacement + "'");
|
||||
}
|
||||
|
||||
return replacement;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "overrideImageURL failure", ex);
|
||||
}
|
||||
|
||||
return originalUrl;
|
||||
}
|
||||
}
|
@ -189,6 +189,7 @@ public class Settings extends BaseSettings {
|
||||
public static final StringSetting SPOOF_APP_VERSION_TARGET = new StringSetting("revanced_spoof_app_version_target", "17.33.42", true, parent(SPOOF_APP_VERSION));
|
||||
public static final BooleanSetting TABLET_LAYOUT = new BooleanSetting("revanced_tablet_layout", FALSE, true, "revanced_tablet_layout_user_dialog_message");
|
||||
public static final BooleanSetting WIDE_SEARCHBAR = new BooleanSetting("revanced_wide_searchbar", FALSE, true);
|
||||
public static final BooleanSetting BYPASS_IMAGE_REGION_RESTRICTIONS = new BooleanSetting("revanced_bypass_image_region_restrictions", FALSE, true);
|
||||
public static final BooleanSetting REMOVE_VIEWER_DISCRETION_DIALOG = new BooleanSetting("revanced_remove_viewer_discretion_dialog", FALSE,
|
||||
"revanced_remove_viewer_discretion_dialog_user_dialog_message");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user