This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube Music - Thumbnails): Add
Alternative domain
patch
--------- Co-authored-by: inotia00 <[email protected]>
- Loading branch information
1 parent
28b648c
commit 15ae875
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/src/main/java/app/revanced/integrations/music/patches/misc/AlternativeDomainPatch.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,38 @@ | ||
package app.revanced.integrations.music.patches.misc; | ||
|
||
import static app.revanced.integrations.music.settings.Settings.ALTERNATIVE_DOMAIN; | ||
import static app.revanced.integrations.music.settings.Settings.USE_ALTERNATIVE_DOMAIN; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import app.revanced.integrations.shared.utils.Logger; | ||
|
||
@SuppressWarnings("unused") | ||
public final class AlternativeDomainPatch { | ||
|
||
private static final String YOUTUBE_STATIC_THUMBNAILS_DOMAIN_REGEX = "(yt[3-4]|lh[3-6]|play-lh)\\.(ggpht|googleusercontent)\\.com"; | ||
|
||
private static final Pattern YOUTUBE_STATIC_THUMBNAILS_DOMAIN_PATTERN = Pattern.compile(YOUTUBE_STATIC_THUMBNAILS_DOMAIN_REGEX); | ||
|
||
|
||
public static String overrideImageURL(String originalUrl) { | ||
try { | ||
if (USE_ALTERNATIVE_DOMAIN.get()) { | ||
final Matcher matcher = YOUTUBE_STATIC_THUMBNAILS_DOMAIN_PATTERN.matcher(originalUrl); | ||
if (matcher.find()) { | ||
final String finalOriginalUrl = originalUrl; | ||
final String finalReplacementUrl = originalUrl.replaceAll( | ||
YOUTUBE_STATIC_THUMBNAILS_DOMAIN_REGEX, | ||
ALTERNATIVE_DOMAIN.get() | ||
); | ||
Logger.printDebug(() -> "Replaced: '" + finalOriginalUrl + "' with: '" + finalReplacementUrl + "'"); | ||
return finalReplacementUrl; | ||
} | ||
} | ||
} 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