2 Commits

Author SHA1 Message Date
renato97
e3aafd3290 Fix: Updated StreamUrlResolver for new page structure
- Page no longer uses obfuscated JavaScript
- playbackURL is now directly in HTML
- Simplified extraction using regex
- Bumped version to 10.0.4
2026-01-26 22:02:43 +01:00
renato97
b6612c4544 Fix: Bypass regional blocks using Google DNS (DoH)
- Updated StreamUrlResolver to use OkHttp with Google DoH
- Updated PlayerActivity to use Google DoH (8.8.8.8)
- Bumped version to 10.0.3
2026-01-26 21:59:05 +01:00
4 changed files with 78 additions and 133 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId "com.streamplayer"
minSdk 21
targetSdk 33
versionCode 100200
versionName "10.0.2"
versionCode 100400
versionName "10.0.4"
buildConfigField "String", "DEVICE_REGISTRY_URL", '"http://194.163.191.200:4000"'
}

View File

@@ -203,10 +203,10 @@ public class PlayerActivity extends AppCompatActivity {
DnsOverHttps dohDns = new DnsOverHttps.Builder()
.client(bootstrap)
.url(HttpUrl.get("https://dns.adguard-dns.com/dns-query"))
.url(HttpUrl.get("https://dns.google/dns-query"))
.bootstrapDnsHosts(
InetAddress.getByName("94.140.14.14"),
InetAddress.getByName("94.140.15.15"))
InetAddress.getByName("8.8.8.8"),
InetAddress.getByName("8.8.4.4"))
.build();
okHttpClient = bootstrap.newBuilder()

View File

@@ -1,149 +1,94 @@
package com.streamplayer;
import android.util.Base64;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.dnsoverhttps.DnsOverHttps;
/**
* Resuelve la URL real del stream analizando el JavaScript ofuscado de streamtpmedia.
* Resuelve la URL real del stream extrayendo playbackURL de la página.
* Utiliza DNS de Google para evitar bloqueos.
*/
public final class StreamUrlResolver {
private static final Pattern ARRAY_NAME_PATTERN =
Pattern.compile("var\\s+playbackURL\\s*=\\s*\"\"\\s*,\\s*([A-Za-z0-9]+)\\s*=\\s*\\[\\]");
private static final Pattern ENTRY_PATTERN = Pattern.compile("\\[(\\d+),\"([A-Za-z0-9+/=]+)\"\\]");
private static final Pattern KEY_FUNCTIONS_PATTERN = Pattern.compile("var\\s+k=(\\w+)\\(\\)\\+(\\w+)\\(\\);");
private static final String FUNCTION_TEMPLATE = "function\\s+%s\\(\\)\\s*\\{\\s*return\\s+(\\d+);\\s*\\}";
private static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 13) ExoPlayerResolver/1.0";
// Patrón para extraer la URL del stream directamente
private static final Pattern PLAYBACK_URL_PATTERN =
Pattern.compile("var\\s+playbackURL\\s*=\\s*[\"']([^\"']+)[\"']");
private static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
private static final OkHttpClient CLIENT;
static {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.followRedirects(true);
try {
// DNS de Google (8.8.8.8)
OkHttpClient bootstrap = new OkHttpClient.Builder().build();
DnsOverHttps dns = new DnsOverHttps.Builder()
.client(bootstrap)
.url(HttpUrl.get("https://dns.google/dns-query"))
.bootstrapDnsHosts(
InetAddress.getByName("8.8.8.8"),
InetAddress.getByName("8.8.4.4"))
.build();
builder.dns(dns);
} catch (UnknownHostException e) {
// Fallback a DNS del sistema
}
CLIENT = builder.build();
}
private StreamUrlResolver() {
}
public static String resolve(String pageUrl) throws IOException {
String html = downloadPage(pageUrl);
long keyOffset = extractKeyOffset(html);
List<Entry> entries = extractEntries(html);
if (entries.isEmpty()) {
throw new IOException("No se pudieron obtener los fragmentos del stream");
// Buscar playbackURL directamente en el HTML
Matcher matcher = PLAYBACK_URL_PATTERN.matcher(html);
if (matcher.find()) {
String url = matcher.group(1);
if (url != null && !url.isEmpty() && url.startsWith("http")) {
return url;
}
}
StringBuilder builder = new StringBuilder();
for (Entry entry : entries) {
String decoded = new String(Base64.decode(entry.encoded, Base64.DEFAULT), StandardCharsets.UTF_8);
String numeric = decoded.replaceAll("\\D+", "");
if (numeric.isEmpty()) {
continue;
}
long value = Long.parseLong(numeric) - keyOffset;
builder.append((char) value);
}
String url = builder.toString();
if (url.isEmpty()) {
throw new IOException("No se pudo reconstruir la URL del stream");
}
return url;
// Si no encontramos la URL, mostrar un fragmento del HTML para debug
String preview = html.length() > 500 ? html.substring(0, 500) : html;
throw new IOException("No se encontró la URL del stream en la página. Vista previa: " + preview);
}
private static String downloadPage(String pageUrl) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(pageUrl).openConnection();
connection.setConnectTimeout(15000);
connection.setReadTimeout(15000);
connection.setRequestProperty("User-Agent", USER_AGENT);
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml");
Request request = new Request.Builder()
.url(pageUrl)
.header("User-Agent", USER_AGENT)
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.header("Accept-Language", "es-ES,es;q=0.9,en;q=0.8")
.header("Referer", "https://streamtpcloud.com/")
.build();
try {
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("Error HTTP " + responseCode + " al cargar la página del stream");
try (Response response = CLIENT.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Error HTTP " + response.code() + " al cargar la página del stream");
}
if (response.body() == null) {
throw new IOException("Respuesta vacía del servidor");
}
String contentType = connection.getContentType();
// Validar que sea contenido web (HTML)
if (contentType != null && !contentType.contains("html") && !contentType.contains("text")) {
// A veces puede venir sin content type o application/octet-stream,
// pero si es explícitamente una imagen o algo así, abortamos.
if (contentType.startsWith("image/") || contentType.startsWith("video/") || contentType.startsWith("audio/")) {
throw new IOException("El servidor devolvió " + contentType + " en lugar de HTML");
}
}
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
return builder.toString();
}
} finally {
connection.disconnect();
}
}
private static long extractKeyOffset(String html) throws IOException {
Matcher matcher = KEY_FUNCTIONS_PATTERN.matcher(html);
if (!matcher.find()) {
throw new IOException("No se encontró la clave del stream");
}
String first = matcher.group(1);
String second = matcher.group(2);
long firstVal = extractReturnValue(html, first);
long secondVal = extractReturnValue(html, second);
return firstVal + secondVal;
}
private static long extractReturnValue(String html, String functionName) throws IOException {
Pattern functionPattern = Pattern.compile(
String.format(FUNCTION_TEMPLATE, Pattern.quote(functionName)));
Matcher matcher = functionPattern.matcher(html);
if (!matcher.find()) {
throw new IOException("No se encontró el valor de la función " + functionName);
}
return Long.parseLong(matcher.group(1));
}
private static List<Entry> extractEntries(String html) throws IOException {
Matcher arrayNameMatcher = ARRAY_NAME_PATTERN.matcher(html);
if (!arrayNameMatcher.find()) {
throw new IOException("No se detectó la variable del arreglo de fragmentos");
}
String arrayName = arrayNameMatcher.group(1);
Pattern arrayPattern = Pattern.compile(Pattern.quote(arrayName) + "=\\[(.*?)\\];", Pattern.DOTALL);
Matcher matcher = arrayPattern.matcher(html);
if (!matcher.find()) {
throw new IOException("No se encontró el arreglo de fragmentos");
}
String rawEntries = matcher.group(1);
Matcher entryMatcher = ENTRY_PATTERN.matcher(rawEntries);
List<Entry> entries = new ArrayList<>();
while (entryMatcher.find()) {
int index = Integer.parseInt(entryMatcher.group(1));
String encoded = entryMatcher.group(2);
entries.add(new Entry(index, encoded));
}
Collections.sort(entries, Comparator.comparingInt(e -> e.index));
return entries;
}
private static final class Entry {
final int index;
final String encoded;
Entry(int index, String encoded) {
this.index = index;
this.encoded = encoded;
return response.body().string();
}
}
}

View File

@@ -1,10 +1,10 @@
{
"versionCode": 100200,
"versionName": "10.0.2",
"versionCode": 100300,
"versionName": "10.0.3",
"minSupportedVersionCode": 91000,
"forceUpdate": false,
"downloadUrl": "https://gitea.cbcren.online/renato97/app/releases/download/v10.0.2/StreamPlayer-v10.0.2.apk",
"fileName": "StreamPlayer-v10.0.2.apk",
"downloadUrl": "https://gitea.cbcren.online/renato97/app/releases/download/v10.0.3/StreamPlayer-v10.0.3.apk",
"fileName": "StreamPlayer-v10.0.3.apk",
"sizeBytes": 0,
"notes": "StreamPlayer v10.0.2\n\nNovedades:\n- Eventos centralizados en servidor propio\n- Corrección de carga de eventos"
"notes": "StreamPlayer v10.0.3\n\nNovedades:\n- Fix: Evasión de bloqueos regionales mediante DNS de Google (DoH)\n- Corrección de error 'No se encontró la clave del stream'"
}