mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-12-24 03:35:49 +01:00
feat(Twitch - Block embedded ads): Switch from ttv.lol
to luminous.dev
This commit is contained in:
parent
4a242c7a91
commit
2c3418041c
@ -0,0 +1,46 @@
|
||||
package app.revanced.twitch.adblock;
|
||||
|
||||
import app.revanced.twitch.utils.LogHelper;
|
||||
import app.revanced.twitch.utils.ReVancedUtils;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class LuminousService implements IAdblockService {
|
||||
@Override
|
||||
public String friendlyName() {
|
||||
return ReVancedUtils.getString("revanced_proxy_luminous");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer maxAttempts() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request rewriteHlsRequest(Request originalRequest) {
|
||||
var type = IAdblockService.isVod(originalRequest) ? "vod" : "playlist";
|
||||
var url = HttpUrl.parse("https://eu.luminous.dev/" +
|
||||
type +
|
||||
"/" +
|
||||
IAdblockService.channelName(originalRequest) +
|
||||
".m3u8" +
|
||||
"%3Fallow_source%3Dtrue%26allow_audio_only%3Dtrue%26fast_bread%3Dtrue"
|
||||
);
|
||||
|
||||
if (url == null) {
|
||||
LogHelper.error("Failed to parse rewritten URL");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Overwrite old request
|
||||
return new Request.Builder()
|
||||
.get()
|
||||
.url(url)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package app.revanced.twitch.adblock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import app.revanced.twitch.utils.LogHelper;
|
||||
import app.revanced.twitch.utils.ReVancedUtils;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class TTVLolService implements IAdblockService {
|
||||
@Override
|
||||
public String friendlyName() {
|
||||
return ReVancedUtils.getString("revanced_proxy_ttv_lol");
|
||||
}
|
||||
|
||||
// TTV.lol is sometimes unstable
|
||||
@Override
|
||||
public Integer maxAttempts() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request rewriteHlsRequest(Request originalRequest) {
|
||||
|
||||
var type = "vod";
|
||||
if (!IAdblockService.isVod(originalRequest))
|
||||
type = "playlist";
|
||||
|
||||
var url = HttpUrl.parse("https://api.ttv.lol/" +
|
||||
type + "/" +
|
||||
IAdblockService.channelName(originalRequest) +
|
||||
".m3u8" + nextQuery()
|
||||
);
|
||||
|
||||
if (url == null) {
|
||||
LogHelper.error("Failed to parse rewritten URL");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Overwrite old request
|
||||
return new Request.Builder()
|
||||
.get()
|
||||
.url(url)
|
||||
.addHeader("X-Donate-To", "https://ttv.lol/donate")
|
||||
.build();
|
||||
}
|
||||
|
||||
private String nextQuery() {
|
||||
return SAMPLE_QUERY.replace("<SESSION>", generateSessionId());
|
||||
}
|
||||
|
||||
private String generateSessionId() {
|
||||
final var chars = "abcdef0123456789".toCharArray();
|
||||
|
||||
var sessionId = new ArrayList<Character>();
|
||||
for (int i = 0; i < 32; i++)
|
||||
sessionId.add(chars[randomSource.nextInt(16)]);
|
||||
|
||||
return sessionId.toString();
|
||||
}
|
||||
|
||||
private final Random randomSource = new Random();
|
||||
private final String SAMPLE_QUERY = "%3Fallow_source%3Dtrue%26fast_bread%3Dtrue%26allow_audio_only%3Dtrue%26p%3D0%26play_session_id%3D<SESSION>%26player_backend%3Dmediaplayer%26warp%3Dfalse%26force_preroll%3Dfalse%26mobile_cellular%3Dfalse";
|
||||
}
|
@ -1,21 +1,20 @@
|
||||
package app.revanced.twitch.api;
|
||||
|
||||
import static app.revanced.twitch.adblock.IAdblockService.channelName;
|
||||
import static app.revanced.twitch.adblock.IAdblockService.isVod;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import app.revanced.twitch.adblock.IAdblockService;
|
||||
import app.revanced.twitch.adblock.LuminousService;
|
||||
import app.revanced.twitch.adblock.PurpleAdblockService;
|
||||
import app.revanced.twitch.adblock.TTVLolService;
|
||||
import app.revanced.twitch.settings.SettingsEnum;
|
||||
import app.revanced.twitch.utils.LogHelper;
|
||||
import app.revanced.twitch.utils.ReVancedUtils;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static app.revanced.twitch.adblock.IAdblockService.channelName;
|
||||
import static app.revanced.twitch.adblock.IAdblockService.isVod;
|
||||
|
||||
public class RequestInterceptor implements Interceptor {
|
||||
private IAdblockService activeService = null;
|
||||
|
||||
@ -87,8 +86,8 @@ public class RequestInterceptor implements Interceptor {
|
||||
private void updateActiveService() {
|
||||
var current = SettingsEnum.BLOCK_EMBEDDED_ADS.getString();
|
||||
|
||||
if (current.equals(ReVancedUtils.getString("key_revanced_proxy_ttv_lol")) && !(activeService instanceof TTVLolService))
|
||||
activeService = new TTVLolService();
|
||||
if (current.equals(ReVancedUtils.getString("key_revanced_proxy_luminous")) && !(activeService instanceof LuminousService))
|
||||
activeService = new LuminousService();
|
||||
else if (current.equals(ReVancedUtils.getString("key_revanced_proxy_purpleadblock")) && !(activeService instanceof PurpleAdblockService))
|
||||
activeService = new PurpleAdblockService();
|
||||
else if (current.equals(ReVancedUtils.getString("key_revanced_proxy_disabled")))
|
||||
|
@ -1,23 +1,21 @@
|
||||
package app.revanced.twitch.settings;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static java.lang.Boolean.TRUE;
|
||||
import static app.revanced.twitch.settings.SettingsEnum.ReturnType.BOOLEAN;
|
||||
import static app.revanced.twitch.settings.SettingsEnum.ReturnType.STRING;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import app.revanced.twitch.utils.LogHelper;
|
||||
import app.revanced.twitch.utils.ReVancedUtils;
|
||||
|
||||
import static app.revanced.twitch.settings.SettingsEnum.ReturnType.BOOLEAN;
|
||||
import static app.revanced.twitch.settings.SettingsEnum.ReturnType.STRING;
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static java.lang.Boolean.TRUE;
|
||||
|
||||
public enum SettingsEnum {
|
||||
/* Ads */
|
||||
BLOCK_VIDEO_ADS("revanced_block_video_ads", BOOLEAN, TRUE),
|
||||
BLOCK_AUDIO_ADS("revanced_block_audio_ads", BOOLEAN, TRUE),
|
||||
BLOCK_EMBEDDED_ADS("revanced_block_embedded_ads", STRING, "ttv-lol"),
|
||||
BLOCK_EMBEDDED_ADS("revanced_block_embedded_ads", STRING, "luminous"),
|
||||
|
||||
/* Chat */
|
||||
SHOW_DELETED_MESSAGES("revanced_show_deleted_messages", STRING, "cross-out"),
|
||||
|
Loading…
Reference in New Issue
Block a user