4 Commits

Author SHA1 Message Date
renato97
e9773c1353 Fix: ajuste de horarios +2 horas para Argentina (v10.0.6) 2026-01-26 22:20:25 +01:00
renato97
5bd1a2737d Feature: Enable in-app updates for private repository
- Added Gitea API token authentication to UpdateManager
- Now can check releases from private repository
- Bumped version to 10.0.5
2026-01-26 22:08:51 +01:00
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
6 changed files with 103 additions and 136 deletions

View File

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

View File

@@ -127,6 +127,8 @@ public class EventRepository {
JSONArray array = new JSONArray(json); JSONArray array = new JSONArray(json);
List<EventItem> events = new ArrayList<>(); List<EventItem> events = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
JSONObject obj = array.getJSONObject(i); JSONObject obj = array.getJSONObject(i);
String title = obj.optString("title"); String title = obj.optString("title");
@@ -135,8 +137,20 @@ public class EventRepository {
String status = obj.optString("status"); String status = obj.optString("status");
String link = obj.optString("link"); String link = obj.optString("link");
String normalized = normalizeLink(link); String normalized = normalizeLink(link);
// Ajustar hora: la web muestra hora de España, Argentina es +2 horas
String displayTime = time;
try {
if (time != null && !time.isEmpty()) {
LocalTime localTime = LocalTime.parse(time.trim(), formatter);
LocalTime adjustedTime = localTime.plusHours(2);
displayTime = adjustedTime.format(formatter);
}
} catch (DateTimeParseException ignored) {
}
long startMillis = parseEventTime(time); long startMillis = parseEventTime(time);
events.add(new EventItem(title, time, category, status, normalized, extractChannelName(link), startMillis)); events.add(new EventItem(title, displayTime, category, status, normalized, extractChannelName(link), startMillis));
} }
return Collections.unmodifiableList(events); return Collections.unmodifiableList(events);
} }
@@ -167,9 +181,11 @@ public class EventRepository {
try { try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime localTime = LocalTime.parse(time.trim(), formatter); LocalTime localTime = LocalTime.parse(time.trim(), formatter);
// Ajustar hora: la web muestra hora de España, Argentina es +2 horas
LocalTime adjustedTime = localTime.plusHours(2);
ZoneId zone = ZoneId.of("America/Argentina/Buenos_Aires"); ZoneId zone = ZoneId.of("America/Argentina/Buenos_Aires");
LocalDate today = LocalDate.now(zone); LocalDate today = LocalDate.now(zone);
ZonedDateTime start = ZonedDateTime.of(LocalDateTime.of(today, localTime), zone); ZonedDateTime start = ZonedDateTime.of(LocalDateTime.of(today, adjustedTime), zone);
ZonedDateTime now = ZonedDateTime.now(zone); ZonedDateTime now = ZonedDateTime.now(zone);
if (start.isBefore(now.minusHours(12))) { if (start.isBefore(now.minusHours(12))) {
start = start.plusDays(1); start = start.plusDays(1);

View File

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

View File

@@ -1,149 +1,94 @@
package com.streamplayer; package com.streamplayer;
import android.util.Base64;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.net.InetAddress;
import java.net.HttpURLConnection; import java.net.UnknownHostException;
import java.net.URL; import java.util.concurrent.TimeUnit;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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 { public final class StreamUrlResolver {
private static final Pattern ARRAY_NAME_PATTERN = // Patrón para extraer la URL del stream directamente
Pattern.compile("var\\s+playbackURL\\s*=\\s*\"\"\\s*,\\s*([A-Za-z0-9]+)\\s*=\\s*\\[\\]"); private static final Pattern PLAYBACK_URL_PATTERN =
private static final Pattern ENTRY_PATTERN = Pattern.compile("\\[(\\d+),\"([A-Za-z0-9+/=]+)\"\\]"); Pattern.compile("var\\s+playbackURL\\s*=\\s*[\"']([^\"']+)[\"']");
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; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
private static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 13) ExoPlayerResolver/1.0";
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() { private StreamUrlResolver() {
} }
public static String resolve(String pageUrl) throws IOException { public static String resolve(String pageUrl) throws IOException {
String html = downloadPage(pageUrl); String html = downloadPage(pageUrl);
long keyOffset = extractKeyOffset(html);
List<Entry> entries = extractEntries(html); // Buscar playbackURL directamente en el HTML
if (entries.isEmpty()) { Matcher matcher = PLAYBACK_URL_PATTERN.matcher(html);
throw new IOException("No se pudieron obtener los fragmentos del stream"); if (matcher.find()) {
String url = matcher.group(1);
if (url != null && !url.isEmpty() && url.startsWith("http")) {
return url;
}
} }
StringBuilder builder = new StringBuilder(); // Si no encontramos la URL, mostrar un fragmento del HTML para debug
for (Entry entry : entries) { String preview = html.length() > 500 ? html.substring(0, 500) : html;
String decoded = new String(Base64.decode(entry.encoded, Base64.DEFAULT), StandardCharsets.UTF_8); throw new IOException("No se encontró la URL del stream en la página. Vista previa: " + preview);
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;
} }
private static String downloadPage(String pageUrl) throws IOException { private static String downloadPage(String pageUrl) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(pageUrl).openConnection(); Request request = new Request.Builder()
connection.setConnectTimeout(15000); .url(pageUrl)
connection.setReadTimeout(15000); .header("User-Agent", USER_AGENT)
connection.setRequestProperty("User-Agent", USER_AGENT); .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml"); .header("Accept-Language", "es-ES,es;q=0.9,en;q=0.8")
.header("Referer", "https://streamtpcloud.com/")
.build();
try { try (Response response = CLIENT.newCall(request).execute()) {
int responseCode = connection.getResponseCode(); if (!response.isSuccessful()) {
if (responseCode != HttpURLConnection.HTTP_OK) { throw new IOException("Error HTTP " + response.code() + " al cargar la página del stream");
throw new IOException("Error HTTP " + responseCode + " al cargar la página del stream"); }
if (response.body() == null) {
throw new IOException("Respuesta vacía del servidor");
} }
String contentType = connection.getContentType(); return response.body().string();
// 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;
} }
} }
} }

View File

@@ -45,6 +45,7 @@ public class UpdateManager {
private static final String TAG = "UpdateManager"; private static final String TAG = "UpdateManager";
private static final String LATEST_RELEASE_URL = private static final String LATEST_RELEASE_URL =
"https://gitea.cbcren.online/api/v1/repos/renato97/app/releases/latest"; "https://gitea.cbcren.online/api/v1/repos/renato97/app/releases/latest";
private static final String GITEA_TOKEN = "4b94b3610136529861af0821040a801906821a0f";
private final Context appContext; private final Context appContext;
private final Handler mainHandler; private final Handler mainHandler;
@@ -74,6 +75,7 @@ public class UpdateManager {
try { try {
Request request = new Request.Builder() Request request = new Request.Builder()
.url(LATEST_RELEASE_URL) .url(LATEST_RELEASE_URL)
.header("Authorization", "token " + GITEA_TOKEN)
.get() .get()
.build(); .build();
try (Response response = httpClient.newCall(request).execute()) { try (Response response = httpClient.newCall(request).execute()) {
@@ -247,7 +249,11 @@ public class UpdateManager {
if (TextUtils.isEmpty(url)) { if (TextUtils.isEmpty(url)) {
continue; continue;
} }
Request request = new Request.Builder().url(url).get().build(); Request request = new Request.Builder()
.url(url)
.header("Authorization", "token " + GITEA_TOKEN)
.get()
.build();
try (Response response = httpClient.newCall(request).execute()) { try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful() || response.body() == null) { if (!response.isSuccessful() || response.body() == null) {
continue; continue;

View File

@@ -1,10 +1,10 @@
{ {
"versionCode": 100200, "versionCode": 100300,
"versionName": "10.0.2", "versionName": "10.0.3",
"minSupportedVersionCode": 91000, "minSupportedVersionCode": 91000,
"forceUpdate": false, "forceUpdate": false,
"downloadUrl": "https://gitea.cbcren.online/renato97/app/releases/download/v10.0.2/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.2.apk", "fileName": "StreamPlayer-v10.0.3.apk",
"sizeBytes": 0, "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'"
} }