Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
305e1362a6 | ||
|
|
e9773c1353 | ||
|
|
5bd1a2737d | ||
|
|
e3aafd3290 |
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "com.streamplayer"
|
||||
minSdk 21
|
||||
targetSdk 33
|
||||
versionCode 100300
|
||||
versionName "10.0.3"
|
||||
versionCode 100700
|
||||
versionName "10.0.7"
|
||||
buildConfigField "String", "DEVICE_REGISTRY_URL", '"http://194.163.191.200:4000"'
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,8 @@ public class EventRepository {
|
||||
|
||||
JSONArray array = new JSONArray(json);
|
||||
List<EventItem> events = new ArrayList<>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject obj = array.getJSONObject(i);
|
||||
String title = obj.optString("title");
|
||||
@@ -135,8 +137,20 @@ public class EventRepository {
|
||||
String status = obj.optString("status");
|
||||
String link = obj.optString("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);
|
||||
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);
|
||||
}
|
||||
@@ -167,9 +181,11 @@ public class EventRepository {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
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");
|
||||
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);
|
||||
if (start.isBefore(now.minusHours(12))) {
|
||||
start = start.plusDays(1);
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
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.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
|
||||
@@ -46,6 +47,7 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
private View playerToolbar;
|
||||
|
||||
private ExoPlayer player;
|
||||
private DefaultTrackSelector trackSelector;
|
||||
private String channelName;
|
||||
private String channelUrl;
|
||||
private boolean overlayVisible = true;
|
||||
@@ -115,7 +117,16 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this)
|
||||
.setEnableDecoderFallback(true)
|
||||
.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)
|
||||
.setTrackSelector(trackSelector)
|
||||
.setSeekForwardIncrementMs(10_000)
|
||||
.setSeekBackIncrementMs(10_000)
|
||||
.build();
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
package com.streamplayer;
|
||||
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
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.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -22,17 +14,16 @@ import okhttp3.Response;
|
||||
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.
|
||||
*/
|
||||
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;
|
||||
|
||||
@@ -54,7 +45,7 @@ public final class StreamUrlResolver {
|
||||
.build();
|
||||
builder.dns(dns);
|
||||
} 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();
|
||||
@@ -65,34 +56,28 @@ public final class 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");
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
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 {
|
||||
Request request = new Request.Builder()
|
||||
.url(pageUrl)
|
||||
.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();
|
||||
|
||||
try (Response response = CLIENT.newCall(request).execute()) {
|
||||
@@ -103,71 +88,7 @@ public final class StreamUrlResolver {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class UpdateManager {
|
||||
private static final String TAG = "UpdateManager";
|
||||
private static final String LATEST_RELEASE_URL =
|
||||
"https://gitea.cbcren.online/api/v1/repos/renato97/app/releases/latest";
|
||||
private static final String GITEA_TOKEN = "4b94b3610136529861af0821040a801906821a0f";
|
||||
|
||||
private final Context appContext;
|
||||
private final Handler mainHandler;
|
||||
@@ -74,6 +75,7 @@ public class UpdateManager {
|
||||
try {
|
||||
Request request = new Request.Builder()
|
||||
.url(LATEST_RELEASE_URL)
|
||||
.header("Authorization", "token " + GITEA_TOKEN)
|
||||
.get()
|
||||
.build();
|
||||
try (Response response = httpClient.newCall(request).execute()) {
|
||||
@@ -247,7 +249,11 @@ public class UpdateManager {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
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()) {
|
||||
if (!response.isSuccessful() || response.body() == null) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user