mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-30 15:52:55 +01:00
feat(youtube/open-links-directly): skip every redirect url
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
85cae1e5d6
commit
2d73b8b29b
@ -1,18 +1,25 @@
|
||||
package app.revanced.integrations.patches;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.net.Uri;
|
||||
import app.revanced.integrations.settings.SettingsEnum;
|
||||
|
||||
public class OpenLinksDirectlyPatch {
|
||||
private static final String YOUTUBE_REDIRECT_PATH = "redirect";
|
||||
|
||||
public static String parseRedirectUri(String uri) {
|
||||
/**
|
||||
* Parses the given YouTube redirect uri by extracting the redirect query.
|
||||
*
|
||||
* @param uri The YouTube redirect uri.
|
||||
* @return The redirect query.
|
||||
*/
|
||||
public static Uri parseRedirectUri(String uri) {
|
||||
if (SettingsEnum.OPEN_LINKS_DIRECTLY.getBoolean()) {
|
||||
Matcher matcher = Pattern.compile("&q=(http.+?)&v=").matcher(uri);
|
||||
return matcher.find() ? URLDecoder.decode(matcher.group(1)) : uri;
|
||||
final var parsed = Uri.parse(uri);
|
||||
|
||||
if (parsed.getPath().equals(YOUTUBE_REDIRECT_PATH))
|
||||
Uri.parse(parsed.getQueryParameter("q"));
|
||||
}
|
||||
return uri;
|
||||
|
||||
return Uri.parse(uri);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user