4 Commits

Author SHA1 Message Date
renato97
305e1362a6 Feature: forzar máxima calidad de video (v10.0.7) 2026-01-26 22:25:00 +01:00
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
5 changed files with 59 additions and 105 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId "com.streamplayer" applicationId "com.streamplayer"
minSdk 21 minSdk 21
targetSdk 33 targetSdk 33
versionCode 100300 versionCode 100700
versionName "10.0.3" versionName "10.0.7"
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

@@ -16,6 +16,7 @@ import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource; import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource;
@@ -46,6 +47,7 @@ public class PlayerActivity extends AppCompatActivity {
private View playerToolbar; private View playerToolbar;
private ExoPlayer player; private ExoPlayer player;
private DefaultTrackSelector trackSelector;
private String channelName; private String channelName;
private String channelUrl; private String channelUrl;
private boolean overlayVisible = true; private boolean overlayVisible = true;
@@ -115,7 +117,16 @@ public class PlayerActivity extends AppCompatActivity {
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this) DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this)
.setEnableDecoderFallback(true) .setEnableDecoderFallback(true)
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON); .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
// Configurar track selector para máxima calidad
trackSelector = new DefaultTrackSelector(this);
DefaultTrackSelector.Parameters params = trackSelector.buildUponParameters()
.setForceHighestSupportedBitrate(true) // Forzar máximo bitrate
.build();
trackSelector.setParameters(params);
player = new ExoPlayer.Builder(this, renderersFactory) player = new ExoPlayer.Builder(this, renderersFactory)
.setTrackSelector(trackSelector)
.setSeekForwardIncrementMs(10_000) .setSeekForwardIncrementMs(10_000)
.setSeekBackIncrementMs(10_000) .setSeekBackIncrementMs(10_000)
.build(); .build();

View File

@@ -1,16 +1,8 @@
package com.streamplayer; package com.streamplayer;
import android.util.Base64;
import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -22,17 +14,16 @@ import okhttp3.Response;
import okhttp3.dnsoverhttps.DnsOverHttps; import okhttp3.dnsoverhttps.DnsOverHttps;
/** /**
* Resuelve la URL real del stream analizando el JavaScript ofuscado de streamtpcloud. * Resuelve la URL real del stream extrayendo playbackURL de la página.
* Utiliza DNS de Google para evitar bloqueos. * 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; private static final OkHttpClient CLIENT;
@@ -54,7 +45,7 @@ public final class StreamUrlResolver {
.build(); .build();
builder.dns(dns); builder.dns(dns);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
// Fallback a DNS del sistema si falla la inicialización (raro con IPs hardcoded) // Fallback a DNS del sistema
} }
CLIENT = builder.build(); CLIENT = builder.build();
@@ -65,34 +56,28 @@ public final class 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")) {
StringBuilder builder = new StringBuilder(); return url;
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()) { // Si no encontramos la URL, mostrar un fragmento del HTML para debug
throw new IOException("No se pudo reconstruir la URL del stream"); 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);
return url;
} }
private static String downloadPage(String pageUrl) throws IOException { private static String downloadPage(String pageUrl) throws IOException {
Request request = new Request.Builder() Request request = new Request.Builder()
.url(pageUrl) .url(pageUrl)
.header("User-Agent", USER_AGENT) .header("User-Agent", USER_AGENT)
.header("Accept", "text/html,application/xhtml+xml") .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(); .build();
try (Response response = CLIENT.newCall(request).execute()) { try (Response response = CLIENT.newCall(request).execute()) {
@@ -103,71 +88,7 @@ public final class StreamUrlResolver {
throw new IOException("Respuesta vacía del servidor"); throw new IOException("Respuesta vacía del servidor");
} }
// Validar Content-Type
String contentType = response.header("Content-Type");
if (contentType != null && !contentType.contains("html") && !contentType.contains("text")) {
if (contentType.startsWith("image/") || contentType.startsWith("video/") || contentType.startsWith("audio/")) {
throw new IOException("El servidor devolvió " + contentType + " en lugar de HTML");
}
}
return response.body().string(); return response.body().string();
} }
} }
private static long extractKeyOffset(String html) throws IOException {
Matcher matcher = KEY_FUNCTIONS_PATTERN.matcher(html);
if (!matcher.find()) {
// Logging para debug si es necesario, pero lanzamos excepción limpia
throw new IOException("No se encontró la clave del stream (posible bloqueo o cambio en la página)");
}
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;