This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
446 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...in/java/app/revanced/integrations/youtube/patches/BypassImageRegionRestrictionsPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.