Keep only Windows desktop source

This commit is contained in:
renato97
2025-12-17 19:31:05 +00:00
parent 8921d7f2a6
commit f247f9ddee
1247 changed files with 38 additions and 104243 deletions

View File

@@ -1,57 +0,0 @@
FROM openjdk:17-jdk-slim
# Evitar interactividad durante la instalación
ENV DEBIAN_FRONTEND=noninteractive
# Instalar dependencias necesarias para Android SDK
RUN apt-get update && apt-get install -y \
wget \
unzip \
git \
python3 \
python3-pip \
ncurses-bin \
build-essential \
lib32z1 \
lib32ncurses6 \
lib32stdc++6 \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
# Instalar Android SDK
ENV ANDROID_SDK_ROOT=/opt/android-sdk
ENV SDKMANAGER="$ANDROID_SDK_ROOT/cmdline-tools/bin/sdkmanager"
RUN mkdir -p $ANDROID_SDK_ROOT/cmdline-tools && \
wget -q https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip -O tools.zip && \
unzip -q tools.zip && \
mv cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest && \
rm tools.zip
# Aceptar licencias
RUN yes | $SDKMANAGER --licenses
# Instalar componentes necesarios
RUN $SDKMANAGER "platform-tools" "platforms;android-33" "build-tools;33.0.2" "platforms;android-31"
# Instalar Gradle
ENV GRADLE_HOME=/opt/gradle
RUN wget -q https://services.gradle.org/distributions/gradle-8.2-bin.zip -O gradle.zip && \
unzip -q gradle.zip && \
mv gradle-8.2 $GRADLE_HOME && \
rm gradle.zip
ENV PATH=$PATH:$GRADLE_HOME/bin:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/platform-tools
# Copiar proyecto
COPY . /app
WORKDIR /app
# Dar permisos de ejecución a gradlew
RUN chmod +x ./gradlew
# Construir APK
RUN ./gradlew assembleDebug
# Comando para copiar APK a un volumen montado
CMD ["cp", "/app/app/build/outputs/apk/debug/app-debug.apk", "/output/streamplayer.apk"]

328
README.md
View File

@@ -1,306 +1,54 @@
# 📺 StreamPlayer
## StreamPlayer Desktop (Windows)
[![Android](https://img.shields.io/badge/Platform-Android-green.svg)](https://android.com)
[![Java](https://img.shields.io/badge/Language-Java-orange.svg)](https://www.oracle.com/java/)
[![API](https://img.shields.io/badge/Min%20SDK-21%2B-brightgreen.svg)](https://android-developers.blogspot.com/)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
Este branch contiene únicamente la versión de escritorio desarrollada con **.NET 8 + Avalonia**. Replica todas las funciones del APK Android original (resolución de streams ofuscados, verificación remota de dispositivos, control de actualizaciones y reproducción protegida) pero genera un `.exe` listo para Windows.
Aplicación Android reproductora de streaming con optimización DNS para mejor rendimiento y acceso a contenido multimedia.
### Estructura
## 🌟 Características
- **▶️ Reproducción Streaming**: Reproductor de video streaming optimizado con ExoPlayer
- **🌐 Optimización DNS**: Configuración automática de DNS de Google (8.8.8.8, 8.8.4.4) para mejor conectividad
- **🔍 Resolución de URL**: Sistema avanzado que resuelve URLs ofuscadas de streaming
- **📱 Orientación Landscape**: Diseño optimizado para experiencia multimedia inmersiva
- **⚡ Alto Rendimiento**: Implementación asíncrona para respuesta rápida
- **🛡️ Manejo de Errores**: Sistema robusto de gestión de errores y estados
## 📋 Requisitos
- **Android SDK**: API 21 (Android 5.0) o superior
- **Target SDK**: API 33 (Android 13)
- **Permisos**:
- `INTERNET` - Acceso a streaming
- `ACCESS_NETWORK_STATE` - Verificación de conectividad
- `CHANGE_NETWORK_STATE` - Configuración de red
## 🏗️ Arquitectura
### Componentes Principales
- **MainActivity.java** (`/app/src/main/java/com/streamplayer/MainActivity.java`)
- Gestión del ciclo de vida del reproductor
- Configuración de ExoPlayer
- Manejo de estados (loading, error, reproducción)
- **StreamUrlResolver.java** (`/app/src/main/java/com/streamplayer/StreamUrlResolver.java`)
- Resolución de URLs ofuscadas
- Decodificación Base64
- Extracción de claves de JavaScript
- **DNSSetter.java** (`/app/src/main/java/com/streamplayer/DNSSetter.java`)
- Configuración de DNS de Google
- Optimización de red para streaming
- Pre-resolución de dominios
## 🚀 Instalación y Build
### Prerequisites
```bash
# Android SDK
# Java 8+
# Gradle 8.2+
```
windows/StreamPlayer.Desktop/
├── App.axaml / App.axaml.cs
├── Program.cs
├── AppVersion.cs
├── Models/ # ChannelSection, LiveEvent, UpdateInfo, etc.
├── Services/ # StreamUrlResolver, UpdateService, DeviceRegistryService, WindowsDnsService…
├── ViewModels/ # MainWindowViewModel con bloqueo previo y refrescos
├── Views/ # MainWindow, PlayerWindow (LibVLC), diálogos de update/bloqueo
└── StreamPlayer.Desktop.csproj
```
### Build con Gradle
```bash
# Clone el repositorio
git clone https://gitea.cbcren.online/renato97/app.git
cd app
### Requisitos
# Build APK debug
./gradlew assembleDebug
- .NET SDK 8.0
- Windows 10/11 x64
- Visual Studio 2022 (o `dotnet` CLI) con workloads “.NET desktop”.
- VLC runtimes incluidos vía `VideoLAN.LibVLC.Windows`.
# Build APK release
./gradlew assembleRelease
```
### Build con Docker
```bash
# Construir imagen
docker build -t streamplayer .
# Ejecutar build
docker run --rm -v $(pwd)/output:/output streamplayer
```
### Build Script Alternativo
```bash
# Usar script de build
chmod +x build_apk.sh
./build_apk.sh
```
## 🔄 Control de Instalaciones y Actualizaciones
StreamPlayer ahora consulta automáticamente las releases públicas del repositorio Gitea y puede forzar o sugerir actualizaciones directamente desde la app. Para aprovecharlo:
1. Ejecuta un build nuevo incrementando `versionCode`/`versionName` en `app/build.gradle`.
2. Crea una release en Gitea asignando un tag como `v9.1` y sube el APK.
3. Adjunta un archivo `update-manifest.json` en la misma release (puedes partir de `release/update-manifest.example.json`).
### Formato de `update-manifest.json`
```json
{
"versionCode": 91000,
"versionName": "9.1.0",
"minSupportedVersionCode": 90000,
"forceUpdate": false,
"downloadUrl": "https://gitea.cbcren.online/renato97/app/releases/download/v9.1/StreamPlayer-v9.1.apk",
"fileName": "StreamPlayer-v9.1.apk",
"sizeBytes": 12345678,
"notes": "Novedades destacadas que aparecerán en el diálogo dentro de la app"
}
```
- `versionCode` / `versionName`: deben coincidir con el APK publicado.
- `minSupportedVersionCode`: define desde qué versión mínima se permite seguir usando la app (ideal para bloquear instalaciones antiguas).
- `forceUpdate`: si es `true` la app mostrará un diálogo sin opción de omitir.
- `downloadUrl` / `fileName`: apuntan al asset `.apk` publicado en Gitea (puede ser el enlace de descarga directo).
- `notes`: texto libre mostrado en el diálogo dentro de la app; si lo omitís se usará el cuerpo de la release.
Si por algún motivo olvidas subir el manifiesto, la app igualmente tomará el primer asset `.apk` de la release, pero no podrá forzar versiones mínimas.
### Dashboard de Dispositivos y Bloqueo Remoto
Para saber en qué equipo está instalada la app y bloquear el acceso cuando lo necesites, se incluye un dashboard liviano en `dashboard/`:
1. Instala dependencias y ejecuta el servidor:
### Cómo compilar
```bash
cd dashboard
npm install
npm start # escucha en http://localhost:4000
git checkout windows-only
cd windows/StreamPlayer.Desktop
dotnet restore
dotnet build -c Release
# Para distribuir:
dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true
```
2. Copia `dashboard/config.example.json` a `dashboard/config.json` y completa `telegramBotToken` + `telegramChatId` (o usa variables de entorno `TELEGRAM_BOT_TOKEN` / `TELEGRAM_CHAT_ID`).
3. Ajusta `DEVICE_REGISTRY_URL` en `app/build.gradle` para apuntar al dominio/puerto donde despliegues el servidor (ya configurado como `http://194.163.191.200:4000`).
4. Distribuye el APK; cada instalación reportará `ANDROID_ID`, modelo, IP pública y país.
5. Entra a `http://TU_HOST:4000/` para ver el listado, asignar alias, bloquear/desbloquear o validar tokens.
El `.exe` resultante queda en `windows/StreamPlayer.Desktop/bin/Release/net8.0/win-x64/publish/`.
El servidor guarda los datos en `dashboard/data/devices.json`, por lo que puedes versionarlo o respaldarlo fácilmente. Cada registro almacena:
### Características clave
- `deviceId`: `Settings.Secure.ANDROID_ID` del equipo
- `deviceName`, `manufacturer`, `model`, `osVersion`
- `appVersionName`/`Code`
- `ip`, `country` detectados automáticamente
- `firstSeen`, `lastSeen`, `blocked`, `notes`, `verification.status`
- **Resolución de stream**: `Services/StreamUrlResolver.cs` analiza el JavaScript ofuscado y reconstruye el HLS real (idéntico al app móvil).
- **Reproducción**: `Views/PlayerWindow` usa LibVLC con los mismos headers/User-Agent del APK para evitar bloqueos de origen.
- **Verificación remota**: `DeviceRegistryService` sincroniza con tu dashboard y bloquea toda la UI hasta que el servidor permita el dispositivo.
- **Actualizaciones forzadas**: `UpdateService` consulta las releases de Gitea y puede abrir el browser o descargar la nueva versión.
- **DNS de Google**: `WindowsDnsService` fuerza 8.8.8.8 / 8.8.4.4 solicitando elevación (UAC); si el usuario rechaza, se muestra el mensaje para configurar manualmente antes de iniciar el player.
Cuando presionas “Bloquear”, la app recibe la respuesta `{"blocked": true}` y muestra un diálogo irreversible hasta que lo habilites. Esto añade una capa adicional de control aparte del sistema de actualizaciones.
### Uso
### Flujo dentro de la app y tokens divididos
1. Compila o publica el `.exe`.
2. Ejecuta una vez como administrador para que el cambio de DNS quede aplicado.
3. Configura tus endpoints (`AppVersion.DeviceRegistryUrl`, `LatestReleaseApi`) si necesitas apuntar a otros servicios.
4. Distribuye el `.exe` y sube releases/manifest igual que con el APK.
- Cada vez que se abre `MainActivity` se consulta `https://gitea.cbcren.online/api/v1/repos/renato97/app/releases/latest`.
- Si `versionCode` del servidor es mayor al instalado se muestra un diálogo para actualizar; el usuario puede abrir la release o descargarla directamente.
- Si `minSupportedVersionCode` es mayor al instalado la app bloqueará el uso hasta actualizar, cumpliendo con el requerimiento de controlar instalaciones.
- La descarga se gestiona con `DownloadManager` y, una vez completada, se lanza el instalador usando FileProvider.
- Mientras el dashboard mantenga un dispositivo "Pendiente" o "Bloqueado", la app muestra un diálogo con el motivo y la mitad del token que debe compartir la persona.
Cada instalación genera un token interno dividido en dos:
1. **Parte cliente**: se muestra en el diálogo del dispositivo bloqueado para que el usuario pueda copiarla.
2. **Parte admin**: llega al bot de Telegram configurado junto con la IP, país y datos del dispositivo.
Para autorizar un dispositivo pendiente:
1. Obtén la parte cliente desde el usuario (visible en pantalla).
2. Copia la parte admin del mensaje de Telegram.
3. En el dashboard presiona “Verificar token” e introduce ambas mitades. Si coinciden, el estado pasa a "Verificado" y la app se desbloquea automáticamente.
4. A partir de allí puedes bloquear/desbloquear manualmente cuando quieras.
También puedes gestionar todo desde Telegram:
- `/allow <deviceId> <token_cliente>` autoriza el dispositivo (verifica el token y lo desbloquea).
- `/deny <deviceId> <token_cliente> [motivo]` lo bloquea con un motivo opcional.
- `/pending` lista los registros que aún esperan un token válido.
Cada nuevo registro dispara una notificación de Telegram con la parte admin del token y recordatorios de esos comandos.
## 📱 Estructura del Proyecto
```
app/
├── src/main/
│ ├── java/com/streamplayer/
│ │ ├── MainActivity.java # Actividad principal
│ │ ├── StreamUrlResolver.java # Resolvedor de URLs
│ │ └── DNSSetter.java # Configuración DNS
│ ├── res/
│ │ ├── layout/
│ │ │ └── activity_main.xml # UI principal
│ │ ├── mipmap-*/ # Íconos de la app
│ │ ├── values/
│ │ │ ├── strings.xml # Cadenas de texto
│ │ │ ├── colors.xml # Colores
│ │ │ └── themes.xml # Temas
│ │ └── xml/ # Configuraciones
│ └── AndroidManifest.xml # Manifiesto Android
├── build.gradle # Configuración Gradle
└── proguard-rules.pro # Reglas ProGuard
```
## ⚙️ Configuración
### URL de Streaming
La aplicación está configurada por defecto para:
```
https://streamtpmedia.com/global2.php?stream=espn
```
### Configuración DNS
```java
// DNS configurados automáticamente
String[] GOOGLE_DNS = {"8.8.8.8", "8.8.4.4"};
```
## 🔧 Dependencias Principales
- **ExoPlayer 2.18.7**: Motor de reproducción multimedia
- **AndroidX AppCompat 1.6.1**: Compatibilidad hacia atrás
- **ConstraintLayout 2.1.4**: Layout moderno y flexible
## 🛠️ Desarrollo
### Flujo de Reproducción
1. **MainActivity** inicializa y configura DNS de Google
2. **StreamUrlResolver** obtiene y decodifica la URL real del stream
3. **ExoPlayer** inicia la reproducción con la URL resuelta
4. UI actualiza estados (loading, playing, error)
### Características Técnicas
- **Threading**: Operaciones de red en background thread
- **Memory Management**: Proper lifecycle management de ExoPlayer
- **Error Handling**: Captura y display de errores al usuario
- **Network Optimization**: Configuración DNS específica para streaming
## 📊 Build Configuration
| Atributo | Valor |
|----------|-------|
| `applicationId` | `com.streamplayer` |
| `minSdk` | 21 |
| `targetSdk` | 33 |
| `versionCode` | 90000 |
| `versionName` | "9.0.0" |
| `compileSdk` | 33 |
## 🔐 Permisos y Seguridad
La aplicación requiere los siguientes permisos:
-`INTERNET` - Para streaming de contenido
-`ACCESS_NETWORK_STATE` - Para verificar conectividad
-`CHANGE_NETWORK_STATE` - Para optimización de red
## 🐛 Troubleshooting
### Problemas Comunes
**Error de Conexión**
- Verificar conexión a internet
- Confirmar configuración DNS
- Revisar disponibilidad del servicio de streaming
**Error de Reproducción**
- Validar formato de URL
- Verificar permisos de red
- Revisar logs de ExoPlayer
**Build Fail**
```bash
# Limpiar proyecto
./gradlew clean
# Rebuild
./gradlew build
```
## 📝 Logs y Debug
La aplicación incluye console logging para:
- Configuración DNS
- Resolución de URLs
- Estados del reproductor
- Errores de red
## 🤝 Contribución
1. Fork del repositorio
2. Feature branch (`git checkout -b feature/NuevaCaracteristica`)
3. Commit cambios (`git commit -m 'Add feature'`)
4. Push al branch (`git push origin feature/NuevaCaracteristica`)
5. Pull Request
## 📄 Licencia
Este proyecto está licenciado bajo la Licencia MIT - ver archivo [LICENSE](LICENSE) para detalles.
## 👨‍💻 Autor
**renato97** - [Gitea Profile](https://gitea.cbcren.online/renato97)
---
⚠️ **Disclaimer**: Esta aplicación es para fines educativos y de demostración. El usuario es responsable de cumplir con los términos de servicio de las plataformas de streaming utilizadas.
## 📞 Soporte
Para soporte y preguntas:
- 📧 Crear un issue en el repositorio
- 💬 Comentarios en el código
- 📱 Testing en dispositivos reales recomendado
---
**🔗 Repositorio**: https://gitea.cbcren.online/renato97/app
Este branch **no** incluye ningún archivo Android; es solo el código fuente de la versión Windows. Para la versión móvil sigue usando `main`.

Binary file not shown.

3
app/.idea/.gitignore generated vendored
View File

@@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
</component>
</project>

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DeviceTable">
<option name="columnSorters">
<list>
<ColumnSorterState>
<option name="column" value="Name" />
<option name="order" value="ASCENDING" />
</ColumnSorterState>
</list>
</option>
</component>
</project>

12
app/.idea/gradle.xml generated
View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="CHOOSE_PER_TEST" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="ms-11" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

10
app/.idea/misc.xml generated
View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@@ -1,60 +0,0 @@
apply plugin: 'com.android.application'
android {
namespace "com.streamplayer"
compileSdk 33
defaultConfig {
applicationId "com.streamplayer"
minSdk 21
targetSdk 33
versionCode 94600
versionName "9.4.6"
buildConfigField "String", "DEVICE_REGISTRY_URL", '"http://194.163.191.200:4000"'
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lint {
checkReleaseBuilds = false
abortOnError = false
}
buildFeatures {
buildConfig = true
}
packaging {
resources {
excludes += 'META-INF/com.android.tools/proguard/coroutines.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
// ExoPlayer para reproducción de video
implementation 'com.google.android.exoplayer:exoplayer:2.18.7'
implementation 'com.google.android.exoplayer:extension-okhttp:2.18.7'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

View File

@@ -1,31 +0,0 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.streamplayer"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.google.android.exoplayer:exoplayer:2.8.4'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
}

View File

@@ -1,24 +0,0 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.google.android.exoplayer2.** { *; }
-keep class com.streamplayer.** { *; }

View File

@@ -1,58 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Permisos necesarios -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-feature
android:name="android.software.leanback"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:allowBackup="true"
android:banner="@drawable/banner_streamplayer"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.StreamPlayer"
android:usesCleartextTraffic="true">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<activity
android:name=".PlayerActivity"
android:exported="false"
android:screenOrientation="landscape" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -1,76 +0,0 @@
package com.streamplayer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ChannelViewHolder> {
public interface OnChannelClickListener {
void onChannelClick(StreamChannel channel);
}
private final List<StreamChannel> channels = new ArrayList<>();
private final OnChannelClickListener listener;
public ChannelAdapter(OnChannelClickListener listener) {
this.listener = listener;
}
@NonNull
@Override
public ChannelViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_channel, parent, false);
return new ChannelViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ChannelViewHolder holder, int position) {
StreamChannel channel = channels.get(position);
holder.name.setText(channel.getName());
holder.icon.setImageResource(R.drawable.ic_channel_default);
holder.itemView.setOnClickListener(v -> {
if (listener != null) {
listener.onChannelClick(channel);
}
});
holder.itemView.setOnFocusChangeListener((v, hasFocus) -> {
float scale = hasFocus ? 1.08f : 1f;
v.animate().scaleX(scale).scaleY(scale).setDuration(120).start();
v.setSelected(hasFocus);
});
}
@Override
public int getItemCount() {
return channels.size();
}
static class ChannelViewHolder extends RecyclerView.ViewHolder {
final ImageView icon;
final TextView name;
ChannelViewHolder(@NonNull View itemView) {
super(itemView);
icon = itemView.findViewById(R.id.channel_icon);
name = itemView.findViewById(R.id.channel_name);
}
}
public void submitList(List<StreamChannel> newChannels) {
channels.clear();
if (newChannels != null) {
channels.addAll(newChannels);
}
notifyDataSetChanged();
}
}

View File

@@ -1,92 +0,0 @@
package com.streamplayer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public final class ChannelRepository {
private static final List<StreamChannel> CHANNELS = createChannels();
private static List<StreamChannel> createChannels() {
List<StreamChannel> channels = new ArrayList<>(Arrays.asList(
new StreamChannel("ESPN", "https://streamtpmedia.com/global2.php?stream=espn"),
new StreamChannel("ESPN 2", "https://streamtpmedia.com/global2.php?stream=espn2"),
new StreamChannel("ESPN 3", "https://streamtpmedia.com/global2.php?stream=espn3"),
new StreamChannel("ESPN 4", "https://streamtpmedia.com/global2.php?stream=espn4"),
new StreamChannel("ESPN 3 MX", "https://streamtpmedia.com/global2.php?stream=espn3mx"),
new StreamChannel("ESPN 5", "https://streamtpmedia.com/global2.php?stream=espn5"),
new StreamChannel("Fox Sports 3 MX", "https://streamtpmedia.com/global2.php?stream=foxsports3mx"),
new StreamChannel("ESPN 6", "https://streamtpmedia.com/global2.php?stream=espn6"),
new StreamChannel("Fox Sports MX", "https://streamtpmedia.com/global2.php?stream=foxsportsmx"),
new StreamChannel("ESPN 7", "https://streamtpmedia.com/global2.php?stream=espn7"),
new StreamChannel("Azteca Deportes", "https://streamtpmedia.com/global2.php?stream=azteca_deportes"),
new StreamChannel("Win Plus", "https://streamtpmedia.com/global2.php?stream=winplus"),
new StreamChannel("DAZN 1", "https://streamtpmedia.com/global2.php?stream=dazn1"),
new StreamChannel("Win Plus 2", "https://streamtpmedia.com/global2.php?stream=winplus2"),
new StreamChannel("DAZN 2", "https://streamtpmedia.com/global2.php?stream=dazn2"),
new StreamChannel("Win Sports", "https://streamtpmedia.com/global2.php?stream=winsports"),
new StreamChannel("DAZN LaLiga", "https://streamtpmedia.com/global2.php?stream=dazn_laliga"),
new StreamChannel("Win Plus Online 1", "https://streamtpmedia.com/global2.php?stream=winplusonline1"),
new StreamChannel("Caracol TV", "https://streamtpmedia.com/global2.php?stream=caracoltv"),
new StreamChannel("Fox 1 AR", "https://streamtpmedia.com/global2.php?stream=fox1ar"),
new StreamChannel("Fox 2 USA", "https://streamtpmedia.com/global2.php?stream=fox_2_usa"),
new StreamChannel("Fox 2 AR", "https://streamtpmedia.com/global2.php?stream=fox2ar"),
new StreamChannel("TNT 1 GB", "https://streamtpmedia.com/global2.php?stream=tnt_1_gb"),
new StreamChannel("TNT 2 GB", "https://streamtpmedia.com/global2.php?stream=tnt_2_gb"),
new StreamChannel("Fox 3 AR", "https://streamtpmedia.com/global2.php?stream=fox3ar"),
new StreamChannel("Universo USA", "https://streamtpmedia.com/global2.php?stream=universo_usa"),
new StreamChannel("DSports", "https://streamtpmedia.com/global2.php?stream=dsports"),
new StreamChannel("Univision USA", "https://streamtpmedia.com/global2.php?stream=univision_usa"),
new StreamChannel("DSports 2", "https://streamtpmedia.com/global2.php?stream=dsports2"),
new StreamChannel("Fox Deportes USA", "https://streamtpmedia.com/global2.php?stream=fox_deportes_usa"),
new StreamChannel("DSports Plus", "https://streamtpmedia.com/global2.php?stream=dsportsplus"),
new StreamChannel("Fox Sports 2 MX", "https://streamtpmedia.com/global2.php?stream=foxsports2mx"),
new StreamChannel("TNT Sports Chile", "https://streamtpmedia.com/global2.php?stream=tntsportschile"),
new StreamChannel("Fox Sports Premium", "https://streamtpmedia.com/global2.php?stream=foxsportspremium"),
new StreamChannel("TNT Sports", "https://streamtpmedia.com/global2.php?stream=tntsports"),
new StreamChannel("ESPN MX", "https://streamtpmedia.com/global2.php?stream=espnmx"),
new StreamChannel("ESPN Premium", "https://streamtpmedia.com/global2.php?stream=espnpremium"),
new StreamChannel("ESPN 2 MX", "https://streamtpmedia.com/global2.php?stream=espn2mx"),
new StreamChannel("TyC Sports", "https://streamtpmedia.com/global2.php?stream=tycsports"),
new StreamChannel("TUDN USA", "https://streamtpmedia.com/global2.php?stream=tudn_usa"),
new StreamChannel("Telefe", "https://streamtpmedia.com/global2.php?stream=telefe"),
new StreamChannel("TNT 3 GB", "https://streamtpmedia.com/global2.php?stream=tnt_3_gb"),
new StreamChannel("TV Pública", "https://streamtpmedia.com/global2.php?stream=tv_publica"),
new StreamChannel("Fox 1 USA", "https://streamtpmedia.com/global2.php?stream=fox_1_usa"),
new StreamChannel("Liga 1 Max", "https://streamtpmedia.com/global2.php?stream=liga1max"),
new StreamChannel("Gol TV", "https://streamtpmedia.com/global2.php?stream=goltv"),
new StreamChannel("VTV Plus", "https://streamtpmedia.com/global2.php?stream=vtvplus"),
new StreamChannel("ESPN Deportes", "https://streamtpmedia.com/global2.php?stream=espndeportes"),
new StreamChannel("Gol Perú", "https://streamtpmedia.com/global2.php?stream=golperu"),
new StreamChannel("TNT 4 GB", "https://streamtpmedia.com/global2.php?stream=tnt_4_gb"),
new StreamChannel("SportTV BR 1", "https://streamtpmedia.com/global2.php?stream=sporttvbr1"),
new StreamChannel("SportTV BR 2", "https://streamtpmedia.com/global2.php?stream=sporttvbr2"),
new StreamChannel("SportTV BR 3", "https://streamtpmedia.com/global2.php?stream=sporttvbr3"),
new StreamChannel("Premiere 1", "https://streamtpmedia.com/global2.php?stream=premiere1"),
new StreamChannel("Premiere 2", "https://streamtpmedia.com/global2.php?stream=premiere2"),
new StreamChannel("Premiere 3", "https://streamtpmedia.com/global2.php?stream=premiere3"),
new StreamChannel("ESPN NL 1", "https://streamtpmedia.com/global2.php?stream=espn_nl1"),
new StreamChannel("ESPN NL 2", "https://streamtpmedia.com/global2.php?stream=espn_nl2"),
new StreamChannel("ESPN NL 3", "https://streamtpmedia.com/global2.php?stream=espn_nl3"),
new StreamChannel("Caliente TV MX", "https://streamtpmedia.com/global2.php?stream=calientetvmx"),
new StreamChannel("USA Network", "https://streamtpmedia.com/global2.php?stream=usa_network"),
new StreamChannel("TyC Internacional", "https://streamtpmedia.com/global2.php?stream=tycinternacional"),
new StreamChannel("Canal 5 MX", "https://streamtpmedia.com/global2.php?stream=canal5mx"),
new StreamChannel("TUDN MX", "https://streamtpmedia.com/global2.php?stream=TUDNMX"),
new StreamChannel("FUTV", "https://streamtpmedia.com/global2.php?stream=futv"),
new StreamChannel("LaLiga Hypermotion", "https://streamtpmedia.com/global2.php?stream=laligahypermotion")
));
channels.sort(Comparator.comparing(StreamChannel::getName, String.CASE_INSENSITIVE_ORDER));
return Collections.unmodifiableList(channels);
}
private ChannelRepository() {
}
public static List<StreamChannel> getChannels() {
return CHANNELS;
}
}

View File

@@ -1,109 +0,0 @@
package com.streamplayer;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.Build;
import java.net.InetAddress;
public class DNSSetter {
private static final String[] GOOGLE_DNS = {"8.8.8.8", "8.8.4.4"};
public static void configureDNSToGoogle(Context context) {
try {
// Configurar propiedades del sistema para usar DNS específicos
System.setProperty("networkaddress.cache.ttl", "60");
System.setProperty("networkaddress.cache.negative.ttl", "10");
// Forzar resolución usando DNS de Google
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
configureModernDNS(context);
} else {
configureLegacyDNS();
}
// Pre-resolver dominio con DNS de Google
preResolveWithGoogleDNS();
} catch (Exception e) {
System.out.println("Error configurando DNS de Google: " + e.getMessage());
}
}
private static void configureModernDNS(Context context) {
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest networkRequest = new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build();
connectivityManager.registerNetworkCallback(networkRequest, new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
super.onAvailable(network);
// Configuración para priorizar DNS de Google
// Aunque no podemos cambiar DNS directamente sin permisos especiales,
// podemos optimizar la configuración de red
try {
NetworkCapabilities caps = connectivityManager.getNetworkCapabilities(network);
if (caps != null) {
System.out.println("Red configurada con DNS optimizado para streaming");
}
} catch (Exception e) {
System.out.println("Error en configuración de red: " + e.getMessage());
}
}
});
} catch (Exception e) {
System.out.println("Error configurando DNS moderno: " + e.getMessage());
}
}
private static void configureLegacyDNS() {
try {
// Para versiones antiguas, configuramos propiedades del sistema
System.setProperty("sun.net.inetaddr.ttl", "60");
System.setProperty("sun.net.inetaddr.negative.ttl", "10");
System.out.println("DNS legacy configurado para streaming");
} catch (Exception e) {
System.out.println("Error configurando DNS legacy: " + e.getMessage());
}
}
private static void preResolveWithGoogleDNS() {
try {
// Pre-resolver algunos dominios comunes para caching
Thread thread = new Thread(() -> {
try {
String[] domains = {"streamtpmedia.com", "google.com", "doubleclick.net"};
for (String domain : domains) {
try {
InetAddress.getByName(domain);
System.out.println("Pre-resuelto: " + domain);
} catch (Exception e) {
System.out.println("Error pre-resolviendo " + domain + ": " + e.getMessage());
}
}
} catch (Exception e) {
System.out.println("Error en pre-resolución: " + e.getMessage());
}
});
thread.start();
} catch (Exception e) {
System.out.println("Error en pre-resolución DNS: " + e.getMessage());
}
}
public static String getGoogleDNSInfo() {
return "DNS de Google configurado: " + String.join(", ", GOOGLE_DNS);
}
}

View File

@@ -1,164 +0,0 @@
package com.streamplayer;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* Informa al dashboard qué dispositivos tienen instalada la app y permite bloquearlos remotamente.
*/
public class DeviceRegistry {
public interface Callback {
void onAllowed();
void onBlocked(String reason, String tokenPart);
void onError(String message);
}
private static final String TAG = "DeviceRegistry";
private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
private final Context appContext;
private final OkHttpClient httpClient;
private final ExecutorService executorService;
private final Handler mainHandler = new Handler(Looper.getMainLooper());
public DeviceRegistry(Context context) {
this.appContext = context.getApplicationContext();
this.httpClient = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.callTimeout(20, TimeUnit.SECONDS)
.build();
this.executorService = Executors.newSingleThreadExecutor();
}
public void syncDevice(Callback callback) {
if (TextUtils.isEmpty(BuildConfig.DEVICE_REGISTRY_URL)) {
postAllowed(callback);
return;
}
executorService.execute(() -> {
try {
JSONObject payload = new JSONObject();
payload.put("deviceId", getDeviceId());
payload.put("deviceName", Build.MODEL);
payload.put("model", Build.MODEL);
payload.put("manufacturer", capitalize(Build.MANUFACTURER));
payload.put("osVersion", Build.VERSION.RELEASE + " (API " + Build.VERSION.SDK_INT + ")");
payload.put("appVersionName", BuildConfig.VERSION_NAME);
payload.put("appVersionCode", BuildConfig.VERSION_CODE);
String endpoint = sanitizeBaseUrl(BuildConfig.DEVICE_REGISTRY_URL) + "/api/devices/register";
RequestBody body = RequestBody.create(payload.toString(), JSON);
Request request = new Request.Builder()
.url(endpoint)
.post(body)
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful() || response.body() == null) {
throw new IOException("HTTP " + response.code());
}
String responseText = response.body().string();
JSONObject json = new JSONObject(responseText);
JSONObject deviceJson = json.optJSONObject("device");
JSONObject verificationJson = json.optJSONObject("verification");
boolean blocked = json.optBoolean("blocked", false);
String reason = json.optString("message");
if (TextUtils.isEmpty(reason) && deviceJson != null) {
reason = deviceJson.optString("notes", "");
}
String tokenPart = "";
if (verificationJson != null) {
boolean verificationRequired = verificationJson.optBoolean("required", false);
blocked = blocked || verificationRequired;
tokenPart = verificationJson.optString("clientTokenPart", "");
}
if (blocked) {
postBlocked(callback, reason, tokenPart);
} else {
postAllowed(callback);
}
}
} catch (IOException | JSONException e) {
Log.w(TAG, "Device sync error", e);
postError(callback, e.getMessage());
}
});
}
private String sanitizeBaseUrl(String base) {
if (TextUtils.isEmpty(base)) {
return "";
}
if (base.endsWith("/")) {
return base.substring(0, base.length() - 1);
}
return base;
}
private String getDeviceId() {
String id = Settings.Secure.getString(appContext.getContentResolver(),
Settings.Secure.ANDROID_ID);
if (TextUtils.isEmpty(id)) {
id = Build.MODEL + "-" + Build.BOARD + "-" + BuildConfig.VERSION_CODE;
}
return id;
}
private String capitalize(String value) {
if (TextUtils.isEmpty(value)) {
return "";
}
return value.substring(0, 1).toUpperCase(Locale.getDefault())
+ value.substring(1);
}
public void release() {
executorService.shutdownNow();
}
private void postAllowed(Callback callback) {
if (callback == null) {
return;
}
mainHandler.post(callback::onAllowed);
}
private void postBlocked(Callback callback, String reason, String tokenPart) {
if (callback == null) {
return;
}
String reasonText = reason == null ? "" : reason;
String token = tokenPart == null ? "" : tokenPart;
mainHandler.post(() -> callback.onBlocked(reasonText, token));
}
private void postError(Callback callback, String message) {
if (callback == null) {
return;
}
mainHandler.post(() -> callback.onError(message));
}
}

View File

@@ -1,97 +0,0 @@
package com.streamplayer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class EventAdapter extends RecyclerView.Adapter<EventAdapter.EventViewHolder> {
public interface OnEventClickListener {
void onEventClick(EventItem event);
}
private final List<EventItem> events = new ArrayList<>();
private final OnEventClickListener listener;
public EventAdapter(OnEventClickListener listener) {
this.listener = listener;
}
public void submitList(List<EventItem> newEvents) {
events.clear();
events.addAll(newEvents);
notifyDataSetChanged();
}
@NonNull
@Override
public EventViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_event, parent, false);
return new EventViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull EventViewHolder holder, int position) {
EventItem event = events.get(position);
holder.title.setText(event.getTitle());
holder.time.setText(event.getTime());
holder.channel.setText(event.getChannelName());
holder.status.setText(buildStatusText(event));
holder.itemView.setOnClickListener(v -> {
if (listener != null) {
listener.onEventClick(event);
}
});
}
@Override
public int getItemCount() {
return events.size();
}
static class EventViewHolder extends RecyclerView.ViewHolder {
final TextView title;
final TextView time;
final TextView channel;
final TextView status;
EventViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.event_title);
time = itemView.findViewById(R.id.event_time);
channel = itemView.findViewById(R.id.event_channel);
status = itemView.findViewById(R.id.event_status);
}
}
private String buildStatusText(EventItem event) {
long start = event.getStartMillis();
if (start <= 0) {
return event.getStatus();
}
long now = System.currentTimeMillis();
long diff = start - now;
if (diff > 0) {
long hours = diff / 3600000;
long minutes = (diff % 3600000) / 60000;
if (hours > 0) {
return String.format(Locale.getDefault(), "En %dh %02dm", hours, minutes);
} else {
return String.format(Locale.getDefault(), "En %d min", Math.max(1, minutes));
}
} else if (Math.abs(diff) <= 2 * 3600000L) {
return "En vivo";
} else {
return "Finalizado";
}
}
}

View File

@@ -1,49 +0,0 @@
package com.streamplayer;
public class EventItem {
private final String title;
private final String time;
private final String category;
private final String status;
private final String pageUrl;
private final String channelName;
private final long startMillis;
public EventItem(String title, String time, String category, String status, String pageUrl, String channelName, long startMillis) {
this.title = title;
this.time = time;
this.category = category;
this.status = status;
this.pageUrl = pageUrl;
this.channelName = channelName;
this.startMillis = startMillis;
}
public String getTitle() {
return title;
}
public String getTime() {
return time;
}
public String getCategory() {
return category;
}
public String getStatus() {
return status;
}
public String getPageUrl() {
return pageUrl;
}
public String getChannelName() {
return channelName;
}
public long getStartMillis() {
return startMillis;
}
}

View File

@@ -1,163 +0,0 @@
package com.streamplayer;
import android.content.Context;
import android.content.SharedPreferences;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
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.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class EventRepository {
private static final String PREFS_NAME = "events_cache";
private static final String KEY_JSON = "json";
private static final String KEY_TIMESTAMP = "timestamp";
private static final long CACHE_DURATION = 24L * 60 * 60 * 1000; // 24 horas
private static final String EVENTS_URL = "https://streamtpmedia.com/eventos.json";
public interface Callback {
void onSuccess(List<EventItem> events);
void onError(String message);
}
public void loadEvents(Context context, boolean forceRefresh, Callback callback) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
long last = prefs.getLong(KEY_TIMESTAMP, 0);
long now = System.currentTimeMillis();
if (!forceRefresh && now - last < CACHE_DURATION) {
String cachedJson = prefs.getString(KEY_JSON, null);
if (cachedJson != null) {
try {
callback.onSuccess(parseEvents(cachedJson));
return;
} catch (JSONException ignored) {
}
}
}
new Thread(() -> {
try {
String json = downloadJson();
List<EventItem> events = parseEvents(json);
prefs.edit().putString(KEY_JSON, json).putLong(KEY_TIMESTAMP, System.currentTimeMillis()).apply();
callback.onSuccess(events);
} catch (IOException | JSONException e) {
String cachedJson = prefs.getString(KEY_JSON, null);
if (cachedJson != null) {
try {
callback.onSuccess(parseEvents(cachedJson));
return;
} catch (JSONException ignored) {
}
}
callback.onError(e.getMessage() != null ? e.getMessage() : "Error desconocido");
}
}).start();
}
public void prefetchEvents(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
new Thread(() -> {
try {
String json = downloadJson();
parseEvents(json);
prefs.edit()
.putString(KEY_JSON, json)
.putLong(KEY_TIMESTAMP, System.currentTimeMillis())
.apply();
} catch (IOException | JSONException ignored) {
}
}).start();
}
private String downloadJson() throws IOException {
URL url = new URL(EVENTS_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(15000);
connection.setReadTimeout(15000);
connection.setRequestMethod("GET");
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 List<EventItem> parseEvents(String json) throws JSONException {
JSONArray array = new JSONArray(json);
List<EventItem> events = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
JSONObject obj = array.getJSONObject(i);
String title = obj.optString("title");
String time = obj.optString("time");
String category = obj.optString("category");
String status = obj.optString("status");
String link = obj.optString("link");
String normalized = normalizeLink(link);
long startMillis = parseEventTime(time);
events.add(new EventItem(title, time, category, status, normalized, extractChannelName(link), startMillis));
}
return Collections.unmodifiableList(events);
}
private String normalizeLink(String link) {
if (link == null) {
return "";
}
return link.replace("global1.php", "global2.php");
}
private String extractChannelName(String link) {
if (link == null) {
return "";
}
int idx = link.indexOf("stream=");
if (idx == -1) {
return "";
}
return link.substring(idx + 7).replace("_", " ").toUpperCase();
}
private long parseEventTime(String time) {
if (time == null || time.isEmpty()) {
return -1;
}
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime localTime = LocalTime.parse(time.trim(), formatter);
ZoneId zone = ZoneId.of("America/Argentina/Buenos_Aires");
LocalDate today = LocalDate.now(zone);
ZonedDateTime start = ZonedDateTime.of(LocalDateTime.of(today, localTime), zone);
ZonedDateTime now = ZonedDateTime.now(zone);
if (start.isBefore(now.minusHours(12))) {
start = start.plusDays(1);
}
return start.toInstant().toEpochMilli();
} catch (DateTimeParseException e) {
return -1;
}
}
}

View File

@@ -1,546 +0,0 @@
package com.streamplayer;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity {
private static final long EVENT_PREFETCH_INTERVAL_MS = TimeUnit.HOURS.toMillis(1);
private RecyclerView sectionList;
private RecyclerView contentList;
private ProgressBar loadingIndicator;
private TextView messageView;
private TextView contentTitle;
private Button eventsRefreshButton;
private ChannelAdapter channelAdapter;
private EventAdapter eventAdapter;
private EventRepository eventRepository;
private SectionAdapter sectionAdapter;
private GridLayoutManager channelLayoutManager;
private LinearLayoutManager eventLayoutManager;
private final List<EventItem> cachedEvents = new ArrayList<>();
private List<SectionEntry> sections;
private SectionEntry currentSection;
private UpdateManager updateManager;
private AlertDialog updateDialog;
private AlertDialog blockedDialog;
private DeviceRegistry deviceRegistry;
private Handler eventPrefetchHandler;
private Runnable eventPrefetchRunnable;
private boolean isEventsRefreshing;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sectionList = findViewById(R.id.section_list);
contentList = findViewById(R.id.content_list);
loadingIndicator = findViewById(R.id.loading_indicator);
messageView = findViewById(R.id.message_view);
contentTitle = findViewById(R.id.content_title);
eventsRefreshButton = findViewById(R.id.events_refresh_button);
eventsRefreshButton.setOnClickListener(v -> manualRefreshEvents());
applyFocusHighlight(eventsRefreshButton);
channelAdapter = new ChannelAdapter(
channel -> openPlayer(channel.getName(), channel.getPageUrl()));
eventAdapter = new EventAdapter(event -> openPlayer(event.getTitle(), event.getPageUrl()));
eventRepository = new EventRepository();
channelLayoutManager = new GridLayoutManager(this, getSpanCount());
eventLayoutManager = new LinearLayoutManager(this);
sections = buildSections();
sectionList.setLayoutManager(new LinearLayoutManager(this));
sectionAdapter = new SectionAdapter(getSectionTitles(), this::selectSection);
sectionList.setAdapter(sectionAdapter);
selectSection(0);
updateManager = new UpdateManager(this);
updateManager.checkForUpdates(new UpdateManager.UpdateCallback() {
@Override
public void onUpdateAvailable(UpdateManager.UpdateInfo info) {
handleUpdateInfo(info);
}
@Override
public void onUpToDate() {
// Nothing to do.
}
@Override
public void onError(String message) {
Toast.makeText(MainActivity.this,
getString(R.string.update_error_checking, message),
Toast.LENGTH_SHORT).show();
}
});
deviceRegistry = new DeviceRegistry(this);
deviceRegistry.syncDevice(new DeviceRegistry.Callback() {
@Override
public void onAllowed() {
// Device authorized, continue normally.
}
@Override
public void onBlocked(String reason, String tokenPart) {
showBlockedDialog(reason, tokenPart);
}
@Override
public void onError(String message) {
if (!TextUtils.isEmpty(message)) {
Toast.makeText(MainActivity.this,
getString(R.string.device_registry_error, message),
Toast.LENGTH_SHORT).show();
}
}
});
startEventPrefetchScheduler();
}
@Override
protected void onResume() {
super.onResume();
if (updateManager != null) {
updateManager.resumePendingInstall(this);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (updateDialog != null && updateDialog.isShowing()) {
updateDialog.dismiss();
}
if (blockedDialog != null && blockedDialog.isShowing()) {
blockedDialog.dismiss();
}
if (updateManager != null) {
updateManager.release();
}
if (deviceRegistry != null) {
deviceRegistry.release();
}
stopEventPrefetchScheduler();
}
@Override
public void onBackPressed() {
closeAppCompletely();
}
private void selectSection(int index) {
if (sections == null || sections.isEmpty()) {
return;
}
if (index < 0 || index >= sections.size()) {
index = 0;
}
sectionAdapter.setSelectedIndex(index);
currentSection = sections.get(index);
if (currentSection.type == SectionEntry.Type.EVENTS) {
showEvents();
} else {
showChannels(currentSection);
}
}
private void showChannels(SectionEntry section) {
updateEventsRefreshVisibility(false);
contentTitle.setText(section.title);
contentList.setLayoutManager(channelLayoutManager);
contentList.setAdapter(channelAdapter);
loadingIndicator.setVisibility(View.GONE);
channelAdapter.submitList(section.channels);
if (section.channels.isEmpty()) {
messageView.setVisibility(View.VISIBLE);
messageView.setText(R.string.message_no_channels);
} else {
messageView.setVisibility(View.GONE);
contentList.post(() -> contentList.scrollToPosition(0));
}
}
private void showEvents() {
updateEventsRefreshVisibility(true);
contentTitle.setText(currentSection != null ? currentSection.title : getString(R.string.section_events));
contentList.setLayoutManager(eventLayoutManager);
contentList.setAdapter(eventAdapter);
if (cachedEvents.isEmpty()) {
loadEvents(false);
} else {
displayEvents();
}
}
private void loadEvents(boolean forceRefresh) {
if (currentSection != null && currentSection.type == SectionEntry.Type.EVENTS) {
setEventsRefreshing(true);
}
loadingIndicator.setVisibility(View.VISIBLE);
messageView.setVisibility(View.GONE);
eventRepository.loadEvents(this, forceRefresh, new EventRepository.Callback() {
@Override
public void onSuccess(List<EventItem> events) {
runOnUiThread(() -> {
cachedEvents.clear();
cachedEvents.addAll(events);
if (currentSection != null && currentSection.type == SectionEntry.Type.EVENTS) {
displayEvents();
} else {
loadingIndicator.setVisibility(View.GONE);
}
setEventsRefreshing(false);
});
}
@Override
public void onError(String message) {
runOnUiThread(() -> {
loadingIndicator.setVisibility(View.GONE);
messageView.setVisibility(View.VISIBLE);
messageView.setText(getString(R.string.message_events_error, message));
setEventsRefreshing(false);
});
}
});
}
private void manualRefreshEvents() {
if (isEventsRefreshing) {
return;
}
if (currentSection == null || currentSection.type != SectionEntry.Type.EVENTS) {
return;
}
loadEvents(true);
}
private void updateEventsRefreshVisibility(boolean visible) {
if (eventsRefreshButton == null) {
return;
}
eventsRefreshButton.setVisibility(visible ? View.VISIBLE : View.GONE);
if (visible) {
eventsRefreshButton.setEnabled(!isEventsRefreshing);
eventsRefreshButton.setText(isEventsRefreshing
? getString(R.string.events_refreshing)
: getString(R.string.events_refresh_action));
}
}
private void setEventsRefreshing(boolean refreshing) {
isEventsRefreshing = refreshing;
if (eventsRefreshButton == null) {
return;
}
if (eventsRefreshButton.getVisibility() == View.VISIBLE) {
eventsRefreshButton.setEnabled(!refreshing);
eventsRefreshButton.setText(refreshing
? getString(R.string.events_refreshing)
: getString(R.string.events_refresh_action));
}
}
private void displayEvents() {
loadingIndicator.setVisibility(View.GONE);
if (cachedEvents.isEmpty()) {
messageView.setVisibility(View.VISIBLE);
messageView.setText(R.string.message_no_events);
eventAdapter.submitList(new ArrayList<>());
} else {
messageView.setVisibility(View.GONE);
eventAdapter.submitList(new ArrayList<>(cachedEvents));
}
}
private void openPlayer(String name, String pageUrl) {
Intent intent = new Intent(MainActivity.this, PlayerActivity.class);
intent.putExtra(PlayerActivity.EXTRA_CHANNEL_NAME, name);
intent.putExtra(PlayerActivity.EXTRA_CHANNEL_URL, pageUrl);
startActivity(intent);
}
private void handleUpdateInfo(UpdateManager.UpdateInfo info) {
if (info == null) {
return;
}
showUpdateDialog(info);
}
private void showUpdateDialog(UpdateManager.UpdateInfo info) {
if (isFinishing()) {
return;
}
if (updateDialog != null && updateDialog.isShowing()) {
updateDialog.dismiss();
}
View dialogView = getLayoutInflater().inflate(R.layout.dialog_update, null);
TextView titleView = dialogView.findViewById(R.id.update_title);
TextView messageView = dialogView.findViewById(R.id.update_message);
Button positiveButton = dialogView.findViewById(R.id.update_positive_button);
Button negativeButton = dialogView.findViewById(R.id.update_negative_button);
titleView.setText(R.string.update_required_title);
messageView.setText(buildUpdateMessage(info));
AlertDialog dialog = new AlertDialog.Builder(this, R.style.ThemeOverlay_StreamPlayer_AlertDialog)
.setView(dialogView)
.setCancelable(false)
.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
}
positiveButton.setOnClickListener(v -> {
dialog.dismiss();
updateManager.downloadUpdate(MainActivity.this, info);
});
negativeButton.setOnClickListener(v -> closeAppCompletely());
applyFocusHighlight(positiveButton);
applyFocusHighlight(negativeButton);
positiveButton.requestFocus();
updateDialog = dialog;
}
private CharSequence buildUpdateMessage(UpdateManager.UpdateInfo info) {
StringBuilder builder = new StringBuilder();
builder.append(getString(R.string.update_current_version,
BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
builder.append('\n');
builder.append(getString(R.string.update_latest_version,
info.versionName, info.versionCode));
if (info.minSupportedVersionCode > 0) {
builder.append('\n').append(getString(R.string.update_min_supported,
info.minSupportedVersionCode));
}
String size = info.formatSize(this);
if (!size.isEmpty()) {
builder.append('\n').append(getString(R.string.update_download_size, size));
}
if (info.downloadCount > 0) {
builder.append('\n').append(getString(R.string.update_downloads,
info.downloadCount));
}
if (!info.releaseNotes.isEmpty()) {
builder.append("\n\n");
builder.append(getString(R.string.update_release_notes_title));
builder.append('\n');
builder.append(info.getReleaseNotesPreview());
}
return builder.toString();
}
private void showBlockedDialog(String reason, String tokenPart) {
if (isFinishing()) {
return;
}
String finalReason = TextUtils.isEmpty(reason)
? getString(R.string.device_blocked_default_reason)
: reason;
if (blockedDialog != null && blockedDialog.isShowing()) {
blockedDialog.dismiss();
}
View dialogView = getLayoutInflater().inflate(R.layout.dialog_blocked, null);
TextView messageText = dialogView.findViewById(R.id.blocked_message_text);
View tokenContainer = dialogView.findViewById(R.id.blocked_token_container);
TextView tokenValue = dialogView.findViewById(R.id.blocked_token_value);
messageText.setText(getString(R.string.device_blocked_message, finalReason));
boolean hasToken = !TextUtils.isEmpty(tokenPart);
if (hasToken) {
tokenContainer.setVisibility(View.VISIBLE);
tokenValue.setText(tokenPart);
tokenValue.setOnClickListener(v -> copyTokenToClipboard(tokenPart));
} else {
tokenContainer.setVisibility(View.GONE);
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.ThemeOverlay_StreamPlayer_AlertDialog)
.setTitle(R.string.device_blocked_title)
.setView(dialogView)
.setCancelable(false)
.setPositiveButton(R.string.device_blocked_close,
(dialog, which) -> closeAppCompletely());
if (hasToken) {
builder.setNeutralButton(R.string.device_blocked_copy_token,
(dialog, which) -> copyTokenToClipboard(tokenPart));
}
blockedDialog = builder.create();
blockedDialog.show();
}
private void copyTokenToClipboard(String tokenPart) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) {
Toast.makeText(this, R.string.device_blocked_copy_error, Toast.LENGTH_SHORT).show();
return;
}
ClipData data = ClipData.newPlainText("token", tokenPart);
clipboard.setPrimaryClip(data);
Toast.makeText(this, R.string.device_blocked_copy_success, Toast.LENGTH_SHORT).show();
}
private void applyFocusHighlight(View view) {
if (view == null) {
return;
}
view.setOnFocusChangeListener((v, hasFocus) -> {
float scale = hasFocus ? 1.05f : 1f;
v.animate().scaleX(scale).scaleY(scale).setDuration(120).start();
});
}
private void startEventPrefetchScheduler() {
if (eventPrefetchHandler == null) {
eventPrefetchHandler = new Handler(Looper.getMainLooper());
}
if (eventPrefetchRunnable == null) {
eventPrefetchRunnable = new Runnable() {
@Override
public void run() {
if (eventRepository != null) {
eventRepository.prefetchEvents(getApplicationContext());
}
if (eventPrefetchHandler != null) {
eventPrefetchHandler.postDelayed(this, EVENT_PREFETCH_INTERVAL_MS);
}
}
};
} else {
eventPrefetchHandler.removeCallbacks(eventPrefetchRunnable);
}
eventPrefetchHandler.post(eventPrefetchRunnable);
}
private void stopEventPrefetchScheduler() {
if (eventPrefetchHandler != null && eventPrefetchRunnable != null) {
eventPrefetchHandler.removeCallbacks(eventPrefetchRunnable);
}
}
private void closeAppCompletely() {
finishAffinity();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
private int getSpanCount() {
return getResources().getInteger(R.integer.channel_grid_span);
}
private List<SectionEntry> buildSections() {
List<SectionEntry> list = new ArrayList<>();
list.add(SectionEntry.events(getString(R.string.section_events)));
Map<String, List<StreamChannel>> grouped = new HashMap<>();
List<StreamChannel> allChannels = ChannelRepository.getChannels();
for (StreamChannel channel : allChannels) {
String key = deriveGroupName(channel.getName());
grouped.computeIfAbsent(key, k -> new ArrayList<>()).add(channel);
}
List<StreamChannel> espnChannels = grouped.remove("ESPN");
if (espnChannels != null && !espnChannels.isEmpty()) {
list.add(SectionEntry.channels("ESPN", espnChannels));
}
List<String> remaining = new ArrayList<>(grouped.keySet());
Collections.sort(remaining, String.CASE_INSENSITIVE_ORDER);
for (String key : remaining) {
List<StreamChannel> channels = grouped.get(key);
if (channels == null || channels.isEmpty()) {
continue;
}
list.add(SectionEntry.channels(key, channels));
}
list.add(SectionEntry.channels(getString(R.string.section_all_channels), allChannels));
return list;
}
private List<String> getSectionTitles() {
List<String> titles = new ArrayList<>();
for (SectionEntry entry : sections) {
titles.add(entry.title);
}
return titles;
}
private String deriveGroupName(String name) {
if (name == null) {
return getString(R.string.section_all_channels);
}
String upper = name.toUpperCase(Locale.US);
if (upper.startsWith("ESPN")) {
return "ESPN";
} else if (upper.contains("FOX SPORTS")) {
return "Fox Sports";
} else if (upper.contains("FOX")) {
return "Fox";
} else if (upper.contains("TNT")) {
return "TNT";
} else if (upper.contains("DAZN")) {
return "DAZN";
} else if (upper.contains("TUDN")) {
return "TUDN";
} else if (upper.contains("TYC")) {
return "TyC";
} else if (upper.contains("GOL")) {
return "Gol";
}
int spaceIndex = upper.indexOf(' ');
return spaceIndex > 0 ? upper.substring(0, spaceIndex) : upper;
}
private static class SectionEntry {
enum Type { EVENTS, CHANNELS }
final String title;
final Type type;
final List<StreamChannel> channels;
private SectionEntry(String title, Type type, List<StreamChannel> channels) {
this.title = title;
this.type = type;
this.channels = channels == null ? new ArrayList<>() : new ArrayList<>(channels);
}
static SectionEntry events(String title) {
return new SectionEntry(title, Type.EVENTS, null);
}
static SectionEntry channels(String title, List<StreamChannel> channels) {
return new SectionEntry(title, Type.CHANNELS, channels);
}
}
}

View File

@@ -1,279 +0,0 @@
package com.streamplayer;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.ExoPlayer;
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.ext.okhttp.OkHttpDataSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.util.Util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.dnsoverhttps.DnsOverHttps;
public class PlayerActivity extends AppCompatActivity {
public static final String EXTRA_CHANNEL_NAME = "extra_channel_name";
public static final String EXTRA_CHANNEL_URL = "extra_channel_url";
private PlayerView playerView;
private ProgressBar loadingIndicator;
private TextView errorMessage;
private TextView channelLabel;
private Button closeButton;
private View playerToolbar;
private ExoPlayer player;
private String channelName;
private String channelUrl;
private boolean overlayVisible = true;
private OkHttpClient okHttpClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder().permitAll().build()
);
setContentView(R.layout.activity_player);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Intent intent = getIntent();
if (intent == null) {
finish();
return;
}
channelName = intent.getStringExtra(EXTRA_CHANNEL_NAME);
channelUrl = intent.getStringExtra(EXTRA_CHANNEL_URL);
if (channelName == null || channelUrl == null) {
finish();
return;
}
initViews();
channelLabel.setText(channelName);
DNSSetter.configureDNSToGoogle(this);
loadChannel();
}
private void initViews() {
playerView = findViewById(R.id.player_view);
loadingIndicator = findViewById(R.id.loading_indicator);
errorMessage = findViewById(R.id.error_message);
channelLabel = findViewById(R.id.player_channel_label);
closeButton = findViewById(R.id.close_button);
playerToolbar = findViewById(R.id.player_toolbar);
closeButton.setOnClickListener(v -> finish());
playerView.setOnClickListener(v -> toggleOverlay());
}
private void loadChannel() {
showLoading(true);
new Thread(() -> {
try {
String resolvedUrl = StreamUrlResolver.resolve(channelUrl);
runOnUiThread(() -> startPlayback(resolvedUrl));
} catch (Exception e) {
runOnUiThread(() -> showError("Error al obtener stream: " + e.getMessage()));
}
}).start();
}
private void startPlayback(String streamUrl) {
try {
releasePlayer();
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this)
.setEnableDecoderFallback(true)
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
player = new ExoPlayer.Builder(this, renderersFactory)
.setSeekForwardIncrementMs(10_000)
.setSeekBackIncrementMs(10_000)
.build();
playerView.setPlayer(player);
player.addListener(new Player.Listener() {
@Override
public void onPlaybackStateChanged(int playbackState) {
if (playbackState == Player.STATE_READY) {
showLoading(false);
} else if (playbackState == Player.STATE_BUFFERING) {
showLoading(true);
}
}
@Override
public void onPlayerError(PlaybackException error) {
String detail = error.getCause() != null ?
error.getCause().getMessage() : "";
showError("Error al reproducir: " + error.getMessage() + " " + detail);
}
});
MediaItem mediaItem = MediaItem.fromUri(streamUrl);
player.setMediaSource(buildMediaSource(mediaItem));
player.prepare();
player.setPlayWhenReady(true);
setOverlayVisible(false);
} catch (Exception e) {
showError("Error al inicializar reproductor: " + e.getMessage());
}
}
private void showLoading(boolean show) {
loadingIndicator.setVisibility(show ? View.VISIBLE : View.GONE);
errorMessage.setVisibility(View.GONE);
playerView.setVisibility(show ? View.GONE : View.VISIBLE);
if (show) {
setOverlayVisible(true);
}
}
private void showError(String message) {
loadingIndicator.setVisibility(View.GONE);
playerView.setVisibility(View.GONE);
errorMessage.setVisibility(View.VISIBLE);
errorMessage.setText(message);
setOverlayVisible(true);
}
private void releasePlayer() {
if (player != null) {
player.release();
player = null;
}
}
private MediaSource buildMediaSource(MediaItem mediaItem) {
Map<String, String> headers = new HashMap<>();
headers.put("Referer", channelUrl);
headers.put("Origin", "https://streamtpmedia.com");
headers.put("Accept", "*/*");
headers.put("Connection", "keep-alive");
String userAgent = Util.getUserAgent(this, "StreamPlayer");
OkHttpDataSource.Factory factory = new OkHttpDataSource.Factory(provideOkHttpClient())
.setUserAgent(userAgent)
.setDefaultRequestProperties(headers);
return new HlsMediaSource.Factory(factory).createMediaSource(mediaItem);
}
private OkHttpClient provideOkHttpClient() {
if (okHttpClient != null) {
return okHttpClient;
}
try {
OkHttpClient bootstrap = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.build();
DnsOverHttps dohDns = new DnsOverHttps.Builder()
.client(bootstrap)
.url(HttpUrl.get("https://dns.adguard-dns.com/dns-query"))
.bootstrapDnsHosts(
InetAddress.getByName("94.140.14.14"),
InetAddress.getByName("94.140.15.15"))
.build();
okHttpClient = bootstrap.newBuilder()
.dns(dohDns)
.build();
} catch (UnknownHostException e) {
okHttpClient = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.build();
}
return okHttpClient;
}
@Override
protected void onStart() {
super.onStart();
if (player != null) {
playerView.onResume();
} else if (channelUrl != null) {
loadChannel();
}
}
@Override
protected void onResume() {
super.onResume();
if (player != null) {
playerView.onResume();
}
}
@Override
protected void onPause() {
super.onPause();
if (player != null) {
playerView.onPause();
}
}
@Override
protected void onStop() {
super.onStop();
releasePlayer();
}
@Override
protected void onDestroy() {
super.onDestroy();
releasePlayer();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
private void toggleOverlay() {
setOverlayVisible(!overlayVisible);
}
private void setOverlayVisible(boolean visible) {
overlayVisible = visible;
playerToolbar.setVisibility(visible ? View.VISIBLE : View.GONE);
}
@Override
public void onBackPressed() {
if (!overlayVisible) {
setOverlayVisible(true);
} else {
super.onBackPressed();
}
}
}

View File

@@ -1,88 +0,0 @@
package com.streamplayer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class SectionAdapter extends RecyclerView.Adapter<SectionAdapter.SectionViewHolder> {
public interface OnSectionSelectedListener {
void onSectionSelected(int position);
}
private final List<String> sections;
private final OnSectionSelectedListener listener;
private int selectedIndex = 0;
public SectionAdapter(List<String> sections, OnSectionSelectedListener listener) {
this.sections = sections;
this.listener = listener;
}
@NonNull
@Override
public SectionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_section, parent, false);
return new SectionViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull SectionViewHolder holder, int position) {
holder.title.setText(sections.get(position));
holder.itemView.setSelected(position == selectedIndex);
holder.itemView.setOnClickListener(v -> notifySelection(holder));
holder.itemView.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
notifySelection(holder);
}
});
}
@Override
public int getItemCount() {
return sections.size();
}
public void setSelectedIndex(int index) {
if (index < 0 || index >= sections.size()) {
return;
}
if (selectedIndex == index) {
return;
}
int previous = selectedIndex;
selectedIndex = index;
notifyItemChanged(previous);
notifyItemChanged(selectedIndex);
}
public int getSelectedIndex() {
return selectedIndex;
}
private void notifySelection(SectionViewHolder holder) {
int position = holder.getBindingAdapterPosition();
if (position == RecyclerView.NO_POSITION) {
return;
}
if (listener != null) {
listener.onSectionSelected(position);
}
}
static class SectionViewHolder extends RecyclerView.ViewHolder {
final TextView title;
SectionViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.section_title);
}
}
}

View File

@@ -1,19 +0,0 @@
package com.streamplayer;
public class StreamChannel {
private final String name;
private final String pageUrl;
public StreamChannel(String name, String pageUrl) {
this.name = name;
this.pageUrl = pageUrl;
}
public String getName() {
return name;
}
public String getPageUrl() {
return pageUrl;
}
}

View File

@@ -1,132 +0,0 @@
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.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Resuelve la URL real del stream analizando el JavaScript ofuscado de streamtpmedia.
*/
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";
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");
}
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;
}
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");
connection.connect();
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

@@ -1,518 +0,0 @@
package com.streamplayer;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.Log;
import android.widget.Toast;
import androidx.core.content.FileProvider;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
* Encapsula toda la lógica para consultar releases de Gitea, descargar el APK y lanzarlo.
*/
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 final Context appContext;
private final Handler mainHandler;
private final ExecutorService networkExecutor;
private final OkHttpClient httpClient;
private WeakReference<Activity> activityRef;
private DownloadReceiver downloadReceiver;
private long currentDownloadId = -1L;
private File downloadingFile;
private File pendingInstallFile;
private UpdateInfo cachedUpdate;
public UpdateManager(Context context) {
this.appContext = context.getApplicationContext();
this.mainHandler = new Handler(Looper.getMainLooper());
this.networkExecutor = Executors.newSingleThreadExecutor();
this.httpClient = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(20, TimeUnit.SECONDS)
.callTimeout(25, TimeUnit.SECONDS)
.build();
}
public void checkForUpdates(UpdateCallback callback) {
networkExecutor.execute(() -> {
try {
Request request = new Request.Builder()
.url(LATEST_RELEASE_URL)
.get()
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (response.body() == null) {
postError(callback, appContext.getString(R.string.update_error_empty_response));
return;
}
if (!response.isSuccessful()) {
postError(callback, appContext.getString(R.string.update_error_http,
response.code()));
return;
}
String body = response.body().string();
UpdateInfo info = parseRelease(body);
cachedUpdate = info;
if (info != null && info.isUpdateAvailable(BuildConfig.VERSION_CODE)) {
postAvailable(callback, info);
} else {
postUpToDate(callback);
}
}
} catch (IOException | JSONException e) {
Log.w(TAG, "Error checking updates", e);
postError(callback, e.getMessage());
}
});
}
public UpdateInfo getCachedUpdate() {
return cachedUpdate;
}
public void downloadUpdate(Activity activity, UpdateInfo info) {
if (info == null || TextUtils.isEmpty(info.downloadUrl)) {
showToast(appContext.getString(R.string.update_error_missing_url));
return;
}
DownloadManager downloadManager =
(DownloadManager) appContext.getSystemService(Context.DOWNLOAD_SERVICE);
if (downloadManager == null) {
showToast(appContext.getString(R.string.update_error_download_manager));
return;
}
File targetDir = appContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
if (targetDir == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
targetDir = appContext.getExternalFilesDir(null);
}
if (targetDir == null) {
showToast(appContext.getString(R.string.update_error_storage));
return;
}
if (!targetDir.exists() && !targetDir.mkdirs()) {
showToast(appContext.getString(R.string.update_error_storage));
return;
}
String fileName = info.getResolvedFileName();
File apkFile = new File(targetDir, fileName);
if (apkFile.exists() && !apkFile.delete()) {
showToast(appContext.getString(R.string.update_error_storage));
return;
}
Uri destination = Uri.fromFile(apkFile);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(info.downloadUrl));
request.setTitle(appContext.getString(R.string.update_notification_title, info.versionName));
request.setDescription(appContext.getString(R.string.update_notification_description));
request.setAllowedOverMetered(true);
request.setAllowedOverRoaming(false);
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationUri(destination);
try {
currentDownloadId = downloadManager.enqueue(request);
} catch (IllegalArgumentException e) {
showToast(appContext.getString(R.string.update_error_download, e.getMessage()));
return;
}
downloadingFile = apkFile;
activityRef = new WeakReference<>(activity);
registerDownloadReceiver();
showToast(appContext.getString(R.string.update_download_started));
}
public void resumePendingInstall(Activity activity) {
if (pendingInstallFile == null || !pendingInstallFile.exists()) {
return;
}
installDownloadedApk(activity, pendingInstallFile);
}
public void release() {
unregisterDownloadReceiver();
networkExecutor.shutdownNow();
activityRef = null;
}
private UpdateInfo parseRelease(String responseBody) throws JSONException, IOException {
JSONObject releaseJson = new JSONObject(responseBody);
String tagName = releaseJson.optString("tag_name", "");
String versionName = deriveVersionName(tagName, releaseJson.optString("name"));
int versionCode = parseVersionCode(versionName);
String releaseNotes = releaseJson.optString("body", "");
String releasePageUrl = releaseJson.optString("html_url", "");
JSONArray assets = releaseJson.optJSONArray("assets");
JSONObject apkAsset = findApkAsset(assets);
String downloadUrl = apkAsset != null ? apkAsset.optString("browser_download_url", "") : "";
String downloadFileName = apkAsset != null ? apkAsset.optString("name", "") : "";
long sizeBytes = apkAsset != null ? apkAsset.optLong("size", 0L) : 0L;
int downloadCount = apkAsset != null ? apkAsset.optInt("download_count", 0) : 0;
int minSupported = 0;
boolean forceUpdate = false;
JSONObject manifestJson = fetchManifest(assets);
if (manifestJson != null) {
versionCode = manifestJson.optInt("versionCode", versionCode);
versionName = manifestJson.optString("versionName", versionName);
minSupported = manifestJson.optInt("minSupportedVersionCode", 0);
forceUpdate = manifestJson.optBoolean("forceUpdate", false);
String manifestUrl = manifestJson.optString("downloadUrl", null);
if (!TextUtils.isEmpty(manifestUrl)) {
downloadUrl = manifestUrl;
}
if (manifestJson.has("fileName")) {
downloadFileName = manifestJson.optString("fileName", downloadFileName);
}
if (manifestJson.has("sizeBytes")) {
sizeBytes = manifestJson.optLong("sizeBytes", sizeBytes);
}
if (manifestJson.has("notes") && TextUtils.isEmpty(releaseNotes)) {
releaseNotes = manifestJson.optString("notes", releaseNotes);
}
}
if (TextUtils.isEmpty(downloadUrl)) {
return null;
}
return new UpdateInfo(versionCode, versionName, releaseNotes, downloadUrl,
downloadFileName, sizeBytes, downloadCount, releasePageUrl,
minSupported, forceUpdate);
}
private JSONObject fetchManifest(JSONArray assets) throws IOException, JSONException {
if (assets == null) {
return null;
}
for (int i = 0; i < assets.length(); i++) {
JSONObject asset = assets.optJSONObject(i);
if (asset == null) {
continue;
}
String name = asset.optString("name", "").toLowerCase(Locale.US);
if (TextUtils.isEmpty(name) || !name.endsWith(".json")) {
continue;
}
if (!(name.contains("update") || name.contains("manifest"))) {
continue;
}
String url = asset.optString("browser_download_url", "");
if (TextUtils.isEmpty(url)) {
continue;
}
Request request = new Request.Builder().url(url).get().build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful() || response.body() == null) {
continue;
}
String json = response.body().string();
if (!TextUtils.isEmpty(json)) {
return new JSONObject(json);
}
}
}
return null;
}
private JSONObject findApkAsset(JSONArray assets) {
if (assets == null) {
return null;
}
JSONObject fallback = null;
for (int i = 0; i < assets.length(); i++) {
JSONObject asset = assets.optJSONObject(i);
if (asset == null) {
continue;
}
if (fallback == null) {
fallback = asset;
}
String name = asset.optString("name", "").toLowerCase(Locale.US);
if (name.endsWith(".apk")) {
return asset;
}
}
return fallback;
}
private String deriveVersionName(String tagName, String fallback) {
String base = !TextUtils.isEmpty(tagName) ? tagName : fallback;
if (TextUtils.isEmpty(base)) {
return "";
}
return base.replaceFirst("^[Vv]", "").trim();
}
private int parseVersionCode(String versionName) {
if (TextUtils.isEmpty(versionName)) {
return -1;
}
String normalized = versionName.replaceAll("[^0-9\\.]", "");
if (TextUtils.isEmpty(normalized)) {
return -1;
}
String[] parts = normalized.split("\\.");
int major = parsePart(parts, 0);
int minor = parsePart(parts, 1);
int patch = parsePart(parts, 2);
return major * 10000 + minor * 100 + patch;
}
private int parsePart(String[] parts, int index) {
if (parts.length <= index) {
return 0;
}
try {
return Integer.parseInt(parts[index]);
} catch (NumberFormatException e) {
return 0;
}
}
private void installDownloadedApk(Activity activity, File apkFile) {
if (activity == null || apkFile == null || !apkFile.exists()) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
boolean canInstall = appContext.getPackageManager().canRequestPackageInstalls();
if (!canInstall) {
pendingInstallFile = apkFile;
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,
Uri.parse("package:" + appContext.getPackageName()));
try {
activity.startActivity(intent);
} catch (ActivityNotFoundException ignored) {
showToast(appContext.getString(R.string.update_error_install_permissions));
}
showToast(appContext.getString(R.string.update_permission_request));
return;
}
}
Uri uri = FileProvider.getUriForFile(appContext,
appContext.getPackageName() + ".fileprovider", apkFile);
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
activity.startActivity(installIntent);
pendingInstallFile = null;
} catch (ActivityNotFoundException e) {
showToast(appContext.getString(R.string.update_error_install_intent));
}
}
private void registerDownloadReceiver() {
if (downloadReceiver != null) {
return;
}
downloadReceiver = new DownloadReceiver();
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
appContext.registerReceiver(downloadReceiver, filter);
}
private void unregisterDownloadReceiver() {
if (downloadReceiver != null) {
try {
appContext.unregisterReceiver(downloadReceiver);
} catch (IllegalArgumentException ignored) {
}
downloadReceiver = null;
}
}
private void handleDownloadComplete(long downloadId) {
if (downloadId != currentDownloadId) {
return;
}
DownloadManager downloadManager =
(DownloadManager) appContext.getSystemService(Context.DOWNLOAD_SERVICE);
if (downloadManager == null) {
showToast(appContext.getString(R.string.update_error_download_manager));
cleanupDownloadState();
return;
}
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadId);
Cursor cursor = downloadManager.query(query);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
int status = cursor.getInt(cursor.getColumnIndexOrThrow(
DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_SUCCESSFUL && downloadingFile != null) {
pendingInstallFile = downloadingFile;
Activity activity = activityRef != null ? activityRef.get() : null;
mainHandler.post(() -> {
showToast(appContext.getString(R.string.update_download_complete));
installDownloadedApk(activity, pendingInstallFile);
});
} else {
int reason = cursor.getInt(cursor.getColumnIndexOrThrow(
DownloadManager.COLUMN_REASON));
mainHandler.post(() -> showToast(appContext.getString(
R.string.update_error_download_failed, reason)));
}
}
} finally {
cursor.close();
}
}
cleanupDownloadState();
}
private void cleanupDownloadState() {
unregisterDownloadReceiver();
currentDownloadId = -1L;
downloadingFile = null;
}
private void postAvailable(UpdateCallback callback, UpdateInfo info) {
if (callback == null) {
return;
}
mainHandler.post(() -> callback.onUpdateAvailable(info));
}
private void postUpToDate(UpdateCallback callback) {
if (callback == null) {
return;
}
mainHandler.post(callback::onUpToDate);
}
private void postError(UpdateCallback callback, String message) {
if (callback == null) {
return;
}
mainHandler.post(() -> callback.onError(message));
}
private void showToast(String message) {
mainHandler.post(() -> Toast.makeText(appContext, message, Toast.LENGTH_LONG).show());
}
private class DownloadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1L);
handleDownloadComplete(id);
}
}
public interface UpdateCallback {
void onUpdateAvailable(UpdateInfo info);
void onUpToDate();
void onError(String message);
}
public static class UpdateInfo {
public final int versionCode;
public final String versionName;
public final String releaseNotes;
public final String downloadUrl;
public final String downloadFileName;
public final long downloadSizeBytes;
public final int downloadCount;
public final String releasePageUrl;
public final int minSupportedVersionCode;
public final boolean forceUpdate;
UpdateInfo(int versionCode,
String versionName,
String releaseNotes,
String downloadUrl,
String downloadFileName,
long downloadSizeBytes,
int downloadCount,
String releasePageUrl,
int minSupportedVersionCode,
boolean forceUpdate) {
this.versionCode = versionCode;
this.versionName = versionName;
this.releaseNotes = releaseNotes == null ? "" : releaseNotes.trim();
this.downloadUrl = downloadUrl;
this.downloadFileName = downloadFileName;
this.downloadSizeBytes = downloadSizeBytes;
this.downloadCount = downloadCount;
this.releasePageUrl = releasePageUrl;
this.minSupportedVersionCode = minSupportedVersionCode;
this.forceUpdate = forceUpdate;
}
public boolean isUpdateAvailable(int currentVersionCode) {
return versionCode > currentVersionCode;
}
public boolean isMandatory(int currentVersionCode) {
return forceUpdate || currentVersionCode < minSupportedVersionCode;
}
public String getReleaseNotesPreview() {
if (TextUtils.isEmpty(releaseNotes)) {
return "";
}
final int limit = 900;
if (releaseNotes.length() <= limit) {
return releaseNotes;
}
return releaseNotes.substring(0, limit) + "\n…";
}
public String getResolvedFileName() {
if (!TextUtils.isEmpty(downloadFileName)) {
return downloadFileName;
}
String safeVersion = TextUtils.isEmpty(versionName) ? String.valueOf(versionCode)
: versionName.replaceAll("[^0-9a-zA-Z._-]", "");
return "StreamPlayer-" + safeVersion + ".apk";
}
public String formatSize(Context context) {
if (downloadSizeBytes <= 0) {
return "";
}
return Formatter.formatShortFileSize(context, downloadSizeBytes);
}
}
}

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/white" />
<item android:state_focused="true" android:color="@color/white" />
<item android:color="@color/text_secondary" />
</selector>

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="0"
android:endColor="#FF002766"
android:startColor="#FF0F4C81" />
<corners android:radius="12dp" />
</shape>
</item>
<item>
<bitmap
android:antialias="true"
android:gravity="center"
android:src="@mipmap/ic_launcher" />
</item>
</layer-list>

View File

@@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#88003C8F" />
<corners android:radius="18dp" />
<stroke
android:width="3dp"
android:color="#FFFFFFFF" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#55003C8F" />
<corners android:radius="18dp" />
<stroke
android:width="3dp"
android:color="#FFFFFFFF" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#55003C8F" />
<corners android:radius="18dp" />
<stroke
android:width="3dp"
android:color="#FFFFFFFF" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#33212121" />
<corners android:radius="18dp" />
<stroke
android:width="2dp"
android:color="#33FFFFFF" />
</shape>
</item>
</selector>

View File

@@ -1,62 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape>
<solid android:color="@color/accent_blue_disabled" />
<corners android:radius="28dp" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape>
<solid android:color="@color/accent_blue_light" />
<corners android:radius="28dp" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="@color/accent_blue_light" />
<corners android:radius="28dp" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item android:state_hovered="true">
<shape>
<solid android:color="@color/accent_blue_light" />
<corners android:radius="28dp" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/accent_blue" />
<corners android:radius="28dp" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
</selector>

View File

@@ -1,77 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape>
<solid android:color="#00000000" />
<corners android:radius="28dp" />
<stroke
android:width="2dp"
android:color="@color/accent_blue_disabled" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape>
<solid android:color="#26FFFFFF" />
<corners android:radius="28dp" />
<stroke
android:width="2dp"
android:color="@color/white" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="#26FFFFFF" />
<corners android:radius="28dp" />
<stroke
android:width="2dp"
android:color="@color/white" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item android:state_hovered="true">
<shape>
<solid android:color="#26FFFFFF" />
<corners android:radius="28dp" />
<stroke
android:width="2dp"
android:color="@color/white" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#00000000" />
<corners android:radius="28dp" />
<stroke
android:width="2dp"
android:color="@color/white" />
<padding
android:bottom="8dp"
android:left="16dp"
android:right="16dp"
android:top="8dp" />
</shape>
</item>
</selector>

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/dialog_background" />
<corners android:radius="18dp" />
<padding
android:bottom="16dp"
android:left="16dp"
android:right="16dp"
android:top="16dp" />
</shape>

View File

@@ -1,62 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape>
<solid android:color="@color/accent_blue_disabled" />
<corners android:radius="20dp" />
<padding
android:bottom="8dp"
android:left="20dp"
android:right="20dp"
android:top="8dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape>
<solid android:color="@color/accent_blue_light" />
<corners android:radius="20dp" />
<padding
android:bottom="8dp"
android:left="20dp"
android:right="20dp"
android:top="8dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="@color/accent_blue_light" />
<corners android:radius="20dp" />
<padding
android:bottom="8dp"
android:left="20dp"
android:right="20dp"
android:top="8dp" />
</shape>
</item>
<item android:state_hovered="true">
<shape>
<solid android:color="@color/accent_blue_light" />
<corners android:radius="20dp" />
<padding
android:bottom="8dp"
android:left="20dp"
android:right="20dp"
android:top="8dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/accent_blue" />
<corners android:radius="20dp" />
<padding
android:bottom="8dp"
android:left="20dp"
android:right="20dp"
android:top="8dp" />
</shape>
</item>
</selector>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"><shape android:shape="rectangle"><solid android:color="#202020"/></shape></item>
<item android:state_focused="true"><shape android:shape="rectangle"><solid android:color="#303030"/></shape></item>
<item><shape android:shape="rectangle"><solid android:color="@android:color/transparent"/></shape></item>
</selector>

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#18d763" />
<corners android:radius="20dp" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#5522c1ff" />
<corners android:radius="20dp" />
<stroke
android:width="2dp"
android:color="#88FFFFFF" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#3322c1ff" />
<corners android:radius="20dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#222222" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#44FFFFFF" />
</shape>
</item>
</selector>

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M21,6h-7.59l2.3,-2.29c0.63,-0.63 0.19,-1.71 -0.7,-1.71H8.99c-0.89,0 -1.33,1.08 -0.7,1.71L10.59,6H3c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h18c1.11,0 2,-0.9 2,-2L23,8c0,-1.1 -0.89,-2 -2,-2zM21,18H3L3,8h18v10z" />
<path
android:fillColor="#FFFFFFFF"
android:pathData="M9,10h2v6L9,16zM13,10h2v6h-2z" />
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 850 B

View File

@@ -1,135 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/nav_panel"
android:layout_width="180dp"
android:layout_height="0dp"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingTop="32dp"
android:paddingEnd="16dp"
android:paddingBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/app_brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/app_tagline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/home_tagline"
android:textColor="@color/text_secondary"
android:textSize="12sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/section_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="24dp"
android:layout_weight="1"
android:overScrollMode="never"
tools:listitem="@layout/item_section" />
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="#33FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/nav_panel"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/content_panel"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
android:paddingStart="24dp"
android:paddingTop="32dp"
android:paddingEnd="24dp"
android:paddingBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/divider"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/content_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/content_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Canales" />
<Button
android:id="@+id/events_refresh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:background="@drawable/bg_events_refresh_button"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textColor="@color/white"
android:text="@string/events_refresh_action"
android:textAllCaps="false"
android:visibility="gone" />
</LinearLayout>
<ProgressBar
android:id="@+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:visibility="gone" />
<TextView
android:id="@+id/message_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:textColor="@color/text_secondary"
android:textSize="14sp"
android:visibility="gone"
tools:text="Mensaje" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:overScrollMode="never"
android:nextFocusLeft="@id/section_list"
tools:listitem="@layout/item_channel" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,73 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".PlayerActivity">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="fill"
app:use_controller="true" />
<LinearLayout
android:id="@+id/player_toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#66000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/player_channel_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Canal"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Elegir otro"
android:textAllCaps="false" />
</LinearLayout>
<ProgressBar
android:id="@+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Error al reproducir" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,48 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/blocked_message_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/blocked_token_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="@+id/blocked_token_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_blocked_token_label"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/blocked_token_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="@android:color/transparent"
android:padding="8dp"
android:textColor="@color/white"
android:textIsSelectable="true"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@@ -1,79 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog_dark"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:id="@+id/update_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
android:text="@string/update_required_title" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:maxHeight="320dp"
android:overScrollMode="never">
<TextView
android:id="@+id/update_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="4dp"
android:textColor="@color/white"
android:textSize="14sp" />
</ScrollView>
<LinearLayout
android:id="@+id/update_button_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/update_positive_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_dialog_button_primary"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:text="@string/update_action_download"
android:textAllCaps="false"
android:textColor="@color/white"
android:textStyle="bold" />
<Space
android:layout_width="16dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/update_negative_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_dialog_button_secondary"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:text="@string/update_action_close_app"
android:textAllCaps="false"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:background="@drawable/bg_channel_item_selector"
android:focusable="true"
android:focusableInTouchMode="true"
android:defaultFocusHighlightEnabled="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:id="@+id/channel_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/app_name"
android:tint="@color/white"
android:src="@drawable/ic_channel_default" />
<TextView
android:id="@+id/channel_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:maxLines="2"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>

View File

@@ -1,56 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/bg_channel_item_selector"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/event_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="Partido" />
<TextView
android:id="@+id/event_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="@color/white"
android:textSize="14sp"
tools:text="20:00" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/event_channel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="14sp"
tools:text="ESPN" />
<TextView
android:id="@+id/event_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:textColor="#18d763"
android:textSize="14sp"
tools:text="En vivo" />
</LinearLayout>
</LinearLayout>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/bg_section_indicator"
android:padding="8dp">
<TextView
android:id="@+id/section_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/section_text_selector"
android:textSize="14sp"
android:textStyle="bold"
tools:text="Canales" />
</LinearLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="channel_grid_span">5</integer>
</resources>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="channel_entries">
<item>Azteca Deportes</item>
<item>Canal 5 MX</item>
<item>Caliente TV MX</item>
<item>DAZN 1</item>
<item>DAZN 2</item>
<item>DAZN LaLiga</item>
<item>DSports</item>
<item>DSports 2</item>
<item>DSports Plus</item>
<item>ESPN</item>
</string-array>
</resources>

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="text_secondary">#B3FFFFFF</color>
<color name="accent_blue">#FF1E88E5</color>
<color name="accent_blue_light">#FF42A5F5</color>
<color name="accent_blue_disabled">#661E88E5</color>
<color name="dialog_background">#FF121212</color>
</resources>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="channel_grid_span">3</integer>
</resources>

View File

@@ -1,48 +0,0 @@
<resources>
<string name="app_name">StreamPlayer</string>
<string name="home_tagline">Todo el deporte en un solo lugar</string>
<string name="section_channels">Canales</string>
<string name="section_events">Eventos</string>
<string name="section_all_channels">Todos los canales</string>
<string name="message_no_channels">No hay canales disponibles</string>
<string name="message_no_events">No hay eventos disponibles</string>
<string name="message_events_error">No se pudieron cargar los eventos: %1$s</string>
<string name="update_required_title">Actualización obligatoria</string>
<string name="update_available_title">Actualización disponible</string>
<string name="update_action_download">Actualizar</string>
<string name="update_action_close_app">Salir</string>
<string name="update_current_version">Versión instalada: %1$s (%2$d)</string>
<string name="update_latest_version">Última versión publicada: %1$s (%2$d)</string>
<string name="update_min_supported">Versiones anteriores a %1$d ya no están permitidas.</string>
<string name="update_download_size">Tamaño aproximado: %1$s</string>
<string name="update_downloads">Descargas registradas: %1$d</string>
<string name="update_release_notes_title">Novedades</string>
<string name="update_error_checking">No se pudo verificar actualizaciones (%1$s)</string>
<string name="update_error_open_release">No se pudo abrir el detalle de la versión</string>
<string name="update_error_empty_response">Respuesta vacía del servidor de releases</string>
<string name="update_error_http">Error de red (%1$d)</string>
<string name="update_error_missing_url">No se encontró URL de descarga</string>
<string name="update_error_download_manager">DownloadManager no está disponible en este dispositivo</string>
<string name="update_error_storage">No se pudo preparar el almacenamiento para la actualización</string>
<string name="update_error_download">Error al iniciar la descarga: %1$s</string>
<string name="update_download_started">Descarga iniciada, revisa la notificación para ver el progreso</string>
<string name="update_download_complete">Descarga finalizada, preparando instalación…</string>
<string name="update_error_download_failed">La descarga falló (código %1$d)</string>
<string name="update_error_install_permissions">No se pudo abrir la configuración de instalación desconocida</string>
<string name="update_permission_request">Habilita "Instalar apps desconocidas" para StreamPlayer y regresa para continuar.</string>
<string name="update_error_install_intent">No se pudo abrir el instalador de paquetes</string>
<string name="update_notification_title">StreamPlayer %1$s</string>
<string name="update_notification_description">Descargando nueva versión</string>
<string name="device_blocked_title">Dispositivo bloqueado</string>
<string name="device_blocked_message">Este dispositivo fue bloqueado desde el panel de control. Motivo: %1$s</string>
<string name="device_blocked_default_reason">Sin motivo especificado.</string>
<string name="device_blocked_token_hint">Comparte este código con el administrador para solicitar acceso: %1$s</string>
<string name="device_blocked_token_label">Código de verificación</string>
<string name="device_blocked_close">Salir</string>
<string name="device_blocked_copy_token">Copiar código</string>
<string name="device_blocked_copy_success">Código copiado al portapapeles</string>
<string name="device_blocked_copy_error">No se pudo copiar el código</string>
<string name="device_registry_error">No se pudo registrar el dispositivo (%1$s)</string>
<string name="events_refresh_action">Actualizar ahora</string>
<string name="events_refreshing">Actualizando...</string>
</resources>

View File

@@ -1,23 +0,0 @@
<resources>
<style name="Theme.StreamPlayer" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/black</item>
<item name="colorPrimaryDark">@color/black</item>
<item name="colorAccent">@color/white</item>
<item name="android:statusBarColor">@color/black</item>
<item name="android:navigationBarColor">@color/black</item>
</style>
<style name="ThemeOverlay.StreamPlayer.AlertDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="android:windowBackground">@drawable/bg_dialog_dark</item>
<item name="android:colorBackground">@color/dialog_background</item>
<item name="colorBackgroundFloating">@color/dialog_background</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/text_secondary</item>
<item name="colorAccent">@color/accent_blue</item>
<item name="android:buttonStyle">@style/StreamPlayer.DialogButton</item>
</style>
<style name="StreamPlayer.DialogButton" parent="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">@color/accent_blue</item>
</style>
</resources>

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample backup rules file; uncomment and customize as necessary.
See https://developer.android.com/guide/topics/data/autobackup
for details.
Note: This file is ignored for devices older that API 23, even
if they have auto backup available.
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->
<exclude domain="sharedpref" path="." />
</full-backup-content>

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!--
<include domain="file" path="."/>
<exclude domain="file" path="no_backup/"/>
-->
<exclude domain="sharedpref" path="." />
</cloud-backup>
<!--
<device-transfer>
<include domain="file" path="."/>
<exclude domain="file" path="no_backup/"/>
</device-transfer>
-->
</data-extraction-rules>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path
name="updates"
path="." />
</paths>

View File

@@ -1,20 +0,0 @@
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.5.1'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

View File

@@ -1,95 +0,0 @@
#!/bin/bash
# StreamPlayer APK Build Script
# Esta aplicación Android reproduce streaming usando DNS de Google
echo "=== StreamPlayer APK Build ==="
echo "URL: https://streamtpmedia.com/global2.php?stream=espn"
echo "DNS: 8.8.8.8, 8.8.4.4"
echo
# Crear APK básico con estructura Android
mkdir -p build/intermediates/classes/com/streamplayer
# Compilar archivos Kotlin (simulado para este demo)
echo "Compilando fuentes Kotlin..."
find app/src/main/java -name "*.kt" | while read file; do
echo "Compilando: $file"
done
# Copiar recursos
echo "Copiando recursos..."
cp -r app/src/main/res build/intermediates/
# Crear AndroidManifest.xml procesado
mkdir -p build/intermediates/manifests
cp app/src/main/AndroidManifest.xml build/intermediates/manifests/
# Crear APK structure
mkdir -p build/apk/lib
mkdir -p build/apk/res
mkdir -p build/apk/META-INF
# Copiar recursos al APK
cp -r build/intermediates/res/* build/apk/res/ 2>/dev/null || true
# Crear manifest simplificado para el APK
cat > build/apk/AndroidManifest.xml << 'EOF'
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.streamplayer" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="33"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:label="StreamPlayer" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity" android:exported="true"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
EOF
# Crear classes.dex (simulado)
echo "Creando classes.dex..."
echo "SIMULATED_DEX_FOR_STREAMPLAYER" > build/apk/classes.dex
# Crear resources.arsc (simulado)
echo "CREATED: $(date)" > build/apk/resources.arsc
# Crear APK usando zip
echo "Creando APK..."
cd build/apk
zip -r ../streamplayer.apk . > /dev/null
cd ../..
# Firmar APK (simulado)
echo "Firmando APK..."
echo "UNSIGNED_DEBUG_BUILD" >> build/streamplayer.apk
# Mover APK final
cp build/streamplayer.apk ./StreamPlayer.apk
echo
echo "✅ APK CREADO EXITOSAMENTE!"
echo "📁 Archivo: StreamPlayer.apk"
echo "📱 App: StreamPlayer - Reproductor con DNS Google"
echo "🌐 Stream: ESPN (vía DNS 8.8.8.8, 8.8.4.4)"
echo "🔐 Permisos: INTERNET, ACCESS_NETWORK_STATE"
echo
echo "Características:"
echo "• Reproducción de streaming HTTP/HTTPS"
echo "• Optimización DNS para streaming"
echo "• Interfaz fullscreen landscape"
echo "• ExoPlayer integrado"
echo "• Íconos personalizados"
echo
echo "Para instalar:"
echo "adb install StreamPlayer.apk"
echo
echo "⚠️ Nota: Este es un APK de demostración."
echo " Para producción, compílalo con Android Studio."
echo " La configuración DNS está implementada en DNSSetter.kt"

View File

@@ -1,4 +0,0 @@
{
"telegramBotToken": "123456:ABCDEF-TOKEN",
"telegramChatId": "123456789"
}

View File

@@ -1,26 +0,0 @@
[
{
"deviceId": "f91f2668e8dfb2a7",
"alias": "",
"deviceName": "SM-S928B",
"model": "SM-S928B",
"manufacturer": "Samsung",
"osVersion": "16 (API 36)",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-11-23T22:31:13.359Z",
"lastSeen": "2025-11-23T23:11:07.215Z",
"blocked": false,
"notes": "",
"installs": 7,
"ip": "181.23.253.20",
"country": "AR",
"verification": {
"clientPart": "1714c2bb93670c3f",
"adminPart": "9924c7049211c58c",
"status": "verified",
"createdAt": "2025-11-23T22:31:13.359Z",
"verifiedAt": "2025-11-23T22:33:11.942Z"
}
}
]

1
dashboard/node_modules/.bin/mime generated vendored
View File

@@ -1 +0,0 @@
../mime/cli.js

View File

@@ -1 +0,0 @@
../nodemon/bin/nodemon.js

View File

@@ -1 +0,0 @@
../touch/bin/nodetouch.js

1
dashboard/node_modules/.bin/semver generated vendored
View File

@@ -1 +0,0 @@
../semver/bin/semver.js

File diff suppressed because it is too large Load Diff

View File

@@ -1,243 +0,0 @@
1.3.8 / 2022-02-02
==================
* deps: mime-types@~2.1.34
- deps: mime-db@~1.51.0
* deps: negotiator@0.6.3
1.3.7 / 2019-04-29
==================
* deps: negotiator@0.6.2
- Fix sorting charset, encoding, and language with extra parameters
1.3.6 / 2019-04-28
==================
* deps: mime-types@~2.1.24
- deps: mime-db@~1.40.0
1.3.5 / 2018-02-28
==================
* deps: mime-types@~2.1.18
- deps: mime-db@~1.33.0
1.3.4 / 2017-08-22
==================
* deps: mime-types@~2.1.16
- deps: mime-db@~1.29.0
1.3.3 / 2016-05-02
==================
* deps: mime-types@~2.1.11
- deps: mime-db@~1.23.0
* deps: negotiator@0.6.1
- perf: improve `Accept` parsing speed
- perf: improve `Accept-Charset` parsing speed
- perf: improve `Accept-Encoding` parsing speed
- perf: improve `Accept-Language` parsing speed
1.3.2 / 2016-03-08
==================
* deps: mime-types@~2.1.10
- Fix extension of `application/dash+xml`
- Update primary extension for `audio/mp4`
- deps: mime-db@~1.22.0
1.3.1 / 2016-01-19
==================
* deps: mime-types@~2.1.9
- deps: mime-db@~1.21.0
1.3.0 / 2015-09-29
==================
* deps: mime-types@~2.1.7
- deps: mime-db@~1.19.0
* deps: negotiator@0.6.0
- Fix including type extensions in parameters in `Accept` parsing
- Fix parsing `Accept` parameters with quoted equals
- Fix parsing `Accept` parameters with quoted semicolons
- Lazy-load modules from main entry point
- perf: delay type concatenation until needed
- perf: enable strict mode
- perf: hoist regular expressions
- perf: remove closures getting spec properties
- perf: remove a closure from media type parsing
- perf: remove property delete from media type parsing
1.2.13 / 2015-09-06
===================
* deps: mime-types@~2.1.6
- deps: mime-db@~1.18.0
1.2.12 / 2015-07-30
===================
* deps: mime-types@~2.1.4
- deps: mime-db@~1.16.0
1.2.11 / 2015-07-16
===================
* deps: mime-types@~2.1.3
- deps: mime-db@~1.15.0
1.2.10 / 2015-07-01
===================
* deps: mime-types@~2.1.2
- deps: mime-db@~1.14.0
1.2.9 / 2015-06-08
==================
* deps: mime-types@~2.1.1
- perf: fix deopt during mapping
1.2.8 / 2015-06-07
==================
* deps: mime-types@~2.1.0
- deps: mime-db@~1.13.0
* perf: avoid argument reassignment & argument slice
* perf: avoid negotiator recursive construction
* perf: enable strict mode
* perf: remove unnecessary bitwise operator
1.2.7 / 2015-05-10
==================
* deps: negotiator@0.5.3
- Fix media type parameter matching to be case-insensitive
1.2.6 / 2015-05-07
==================
* deps: mime-types@~2.0.11
- deps: mime-db@~1.9.1
* deps: negotiator@0.5.2
- Fix comparing media types with quoted values
- Fix splitting media types with quoted commas
1.2.5 / 2015-03-13
==================
* deps: mime-types@~2.0.10
- deps: mime-db@~1.8.0
1.2.4 / 2015-02-14
==================
* Support Node.js 0.6
* deps: mime-types@~2.0.9
- deps: mime-db@~1.7.0
* deps: negotiator@0.5.1
- Fix preference sorting to be stable for long acceptable lists
1.2.3 / 2015-01-31
==================
* deps: mime-types@~2.0.8
- deps: mime-db@~1.6.0
1.2.2 / 2014-12-30
==================
* deps: mime-types@~2.0.7
- deps: mime-db@~1.5.0
1.2.1 / 2014-12-30
==================
* deps: mime-types@~2.0.5
- deps: mime-db@~1.3.1
1.2.0 / 2014-12-19
==================
* deps: negotiator@0.5.0
- Fix list return order when large accepted list
- Fix missing identity encoding when q=0 exists
- Remove dynamic building of Negotiator class
1.1.4 / 2014-12-10
==================
* deps: mime-types@~2.0.4
- deps: mime-db@~1.3.0
1.1.3 / 2014-11-09
==================
* deps: mime-types@~2.0.3
- deps: mime-db@~1.2.0
1.1.2 / 2014-10-14
==================
* deps: negotiator@0.4.9
- Fix error when media type has invalid parameter
1.1.1 / 2014-09-28
==================
* deps: mime-types@~2.0.2
- deps: mime-db@~1.1.0
* deps: negotiator@0.4.8
- Fix all negotiations to be case-insensitive
- Stable sort preferences of same quality according to client order
1.1.0 / 2014-09-02
==================
* update `mime-types`
1.0.7 / 2014-07-04
==================
* Fix wrong type returned from `type` when match after unknown extension
1.0.6 / 2014-06-24
==================
* deps: negotiator@0.4.7
1.0.5 / 2014-06-20
==================
* fix crash when unknown extension given
1.0.4 / 2014-06-19
==================
* use `mime-types`
1.0.3 / 2014-06-11
==================
* deps: negotiator@0.4.6
- Order by specificity when quality is the same
1.0.2 / 2014-05-29
==================
* Fix interpretation when header not in request
* deps: pin negotiator@0.4.5
1.0.1 / 2014-01-18
==================
* Identity encoding isn't always acceptable
* deps: negotiator@~0.4.0
1.0.0 / 2013-12-27
==================
* Genesis

View File

@@ -1,23 +0,0 @@
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,140 +0,0 @@
# accepts
[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][github-actions-ci-image]][github-actions-ci-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator).
Extracted from [koa](https://www.npmjs.com/package/koa) for general use.
In addition to negotiator, it allows:
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])`
as well as `('text/html', 'application/json')`.
- Allows type shorthands such as `json`.
- Returns `false` when no types match
- Treats non-existent headers as `*`
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```sh
$ npm install accepts
```
## API
```js
var accepts = require('accepts')
```
### accepts(req)
Create a new `Accepts` object for the given `req`.
#### .charset(charsets)
Return the first accepted charset. If nothing in `charsets` is accepted,
then `false` is returned.
#### .charsets()
Return the charsets that the request accepts, in the order of the client's
preference (most preferred first).
#### .encoding(encodings)
Return the first accepted encoding. If nothing in `encodings` is accepted,
then `false` is returned.
#### .encodings()
Return the encodings that the request accepts, in the order of the client's
preference (most preferred first).
#### .language(languages)
Return the first accepted language. If nothing in `languages` is accepted,
then `false` is returned.
#### .languages()
Return the languages that the request accepts, in the order of the client's
preference (most preferred first).
#### .type(types)
Return the first accepted type (and it is returned as the same text as what
appears in the `types` array). If nothing in `types` is accepted, then `false`
is returned.
The `types` array can contain full MIME types or file extensions. Any value
that is not a full MIME types is passed to `require('mime-types').lookup`.
#### .types()
Return the types that the request accepts, in the order of the client's
preference (most preferred first).
## Examples
### Simple type negotiation
This simple example shows how to use `accepts` to return a different typed
respond body based on what the client wants to accept. The server lists it's
preferences in order and will get back the best match between the client and
server.
```js
var accepts = require('accepts')
var http = require('http')
function app (req, res) {
var accept = accepts(req)
// the order of this list is significant; should be server preferred order
switch (accept.type(['json', 'html'])) {
case 'json':
res.setHeader('Content-Type', 'application/json')
res.write('{"hello":"world!"}')
break
case 'html':
res.setHeader('Content-Type', 'text/html')
res.write('<b>hello, world!</b>')
break
default:
// the fallback is text/plain, so no need to specify it above
res.setHeader('Content-Type', 'text/plain')
res.write('hello, world!')
break
}
res.end()
}
http.createServer(app).listen(3000)
```
You can test this out with the cURL program:
```sh
curl -I -H'Accept: text/html' http://localhost:3000/
```
## License
[MIT](LICENSE)
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master
[coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master
[github-actions-ci-image]: https://badgen.net/github/checks/jshttp/accepts/master?label=ci
[github-actions-ci-url]: https://github.com/jshttp/accepts/actions/workflows/ci.yml
[node-version-image]: https://badgen.net/npm/node/accepts
[node-version-url]: https://nodejs.org/en/download
[npm-downloads-image]: https://badgen.net/npm/dm/accepts
[npm-url]: https://npmjs.org/package/accepts
[npm-version-image]: https://badgen.net/npm/v/accepts

View File

@@ -1,238 +0,0 @@
/*!
* accepts
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var Negotiator = require('negotiator')
var mime = require('mime-types')
/**
* Module exports.
* @public
*/
module.exports = Accepts
/**
* Create a new Accepts object for the given req.
*
* @param {object} req
* @public
*/
function Accepts (req) {
if (!(this instanceof Accepts)) {
return new Accepts(req)
}
this.headers = req.headers
this.negotiator = new Negotiator(req)
}
/**
* Check if the given `type(s)` is acceptable, returning
* the best match when true, otherwise `undefined`, in which
* case you should respond with 406 "Not Acceptable".
*
* The `type` value may be a single mime type string
* such as "application/json", the extension name
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
* or array is given the _best_ match, if any is returned.
*
* Examples:
*
* // Accept: text/html
* this.types('html');
* // => "html"
*
* // Accept: text/*, application/json
* this.types('html');
* // => "html"
* this.types('text/html');
* // => "text/html"
* this.types('json', 'text');
* // => "json"
* this.types('application/json');
* // => "application/json"
*
* // Accept: text/*, application/json
* this.types('image/png');
* this.types('png');
* // => undefined
*
* // Accept: text/*;q=.5, application/json
* this.types(['html', 'json']);
* this.types('html', 'json');
* // => "json"
*
* @param {String|Array} types...
* @return {String|Array|Boolean}
* @public
*/
Accepts.prototype.type =
Accepts.prototype.types = function (types_) {
var types = types_
// support flattened arguments
if (types && !Array.isArray(types)) {
types = new Array(arguments.length)
for (var i = 0; i < types.length; i++) {
types[i] = arguments[i]
}
}
// no types, return all requested types
if (!types || types.length === 0) {
return this.negotiator.mediaTypes()
}
// no accept header, return first given type
if (!this.headers.accept) {
return types[0]
}
var mimes = types.map(extToMime)
var accepts = this.negotiator.mediaTypes(mimes.filter(validMime))
var first = accepts[0]
return first
? types[mimes.indexOf(first)]
: false
}
/**
* Return accepted encodings or best fit based on `encodings`.
*
* Given `Accept-Encoding: gzip, deflate`
* an array sorted by quality is returned:
*
* ['gzip', 'deflate']
*
* @param {String|Array} encodings...
* @return {String|Array}
* @public
*/
Accepts.prototype.encoding =
Accepts.prototype.encodings = function (encodings_) {
var encodings = encodings_
// support flattened arguments
if (encodings && !Array.isArray(encodings)) {
encodings = new Array(arguments.length)
for (var i = 0; i < encodings.length; i++) {
encodings[i] = arguments[i]
}
}
// no encodings, return all requested encodings
if (!encodings || encodings.length === 0) {
return this.negotiator.encodings()
}
return this.negotiator.encodings(encodings)[0] || false
}
/**
* Return accepted charsets or best fit based on `charsets`.
*
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
* an array sorted by quality is returned:
*
* ['utf-8', 'utf-7', 'iso-8859-1']
*
* @param {String|Array} charsets...
* @return {String|Array}
* @public
*/
Accepts.prototype.charset =
Accepts.prototype.charsets = function (charsets_) {
var charsets = charsets_
// support flattened arguments
if (charsets && !Array.isArray(charsets)) {
charsets = new Array(arguments.length)
for (var i = 0; i < charsets.length; i++) {
charsets[i] = arguments[i]
}
}
// no charsets, return all requested charsets
if (!charsets || charsets.length === 0) {
return this.negotiator.charsets()
}
return this.negotiator.charsets(charsets)[0] || false
}
/**
* Return accepted languages or best fit based on `langs`.
*
* Given `Accept-Language: en;q=0.8, es, pt`
* an array sorted by quality is returned:
*
* ['es', 'pt', 'en']
*
* @param {String|Array} langs...
* @return {Array|String}
* @public
*/
Accepts.prototype.lang =
Accepts.prototype.langs =
Accepts.prototype.language =
Accepts.prototype.languages = function (languages_) {
var languages = languages_
// support flattened arguments
if (languages && !Array.isArray(languages)) {
languages = new Array(arguments.length)
for (var i = 0; i < languages.length; i++) {
languages[i] = arguments[i]
}
}
// no languages, return all requested languages
if (!languages || languages.length === 0) {
return this.negotiator.languages()
}
return this.negotiator.languages(languages)[0] || false
}
/**
* Convert extnames to mime.
*
* @param {String} type
* @return {String}
* @private
*/
function extToMime (type) {
return type.indexOf('/') === -1
? mime.lookup(type)
: type
}
/**
* Check if mime is valid.
*
* @param {String} type
* @return {String}
* @private
*/
function validMime (type) {
return typeof type === 'string'
}

View File

@@ -1,47 +0,0 @@
{
"name": "accepts",
"description": "Higher-level content negotiation",
"version": "1.3.8",
"contributors": [
"Douglas Christopher Wilson <doug@somethingdoug.com>",
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
],
"license": "MIT",
"repository": "jshttp/accepts",
"dependencies": {
"mime-types": "~2.1.34",
"negotiator": "0.6.3"
},
"devDependencies": {
"deep-equal": "1.0.1",
"eslint": "7.32.0",
"eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-markdown": "2.2.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.3.1",
"eslint-plugin-standard": "4.1.0",
"mocha": "9.2.0",
"nyc": "15.1.0"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"lint": "eslint .",
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-ci": "nyc --reporter=lcov --reporter=text npm test",
"test-cov": "nyc --reporter=html --reporter=text npm test"
},
"keywords": [
"content",
"negotiation",
"accept",
"accepts"
]
}

View File

@@ -1,15 +0,0 @@
The ISC License
Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com)
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@@ -1,87 +0,0 @@
anymatch [![Build Status](https://travis-ci.org/micromatch/anymatch.svg?branch=master)](https://travis-ci.org/micromatch/anymatch) [![Coverage Status](https://img.shields.io/coveralls/micromatch/anymatch.svg?branch=master)](https://coveralls.io/r/micromatch/anymatch?branch=master)
======
Javascript module to match a string against a regular expression, glob, string,
or function that takes the string as an argument and returns a truthy or falsy
value. The matcher can also be an array of any or all of these. Useful for
allowing a very flexible user-defined config to define things like file paths.
__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
Usage
-----
```sh
npm install anymatch
```
#### anymatch(matchers, testString, [returnIndex], [options])
* __matchers__: (_Array|String|RegExp|Function_)
String to be directly matched, string with glob patterns, regular expression
test, function that takes the testString as an argument and returns a truthy
value if it should be matched, or an array of any number and mix of these types.
* __testString__: (_String|Array_) The string to test against the matchers. If
passed as an array, the first element of the array will be used as the
`testString` for non-function matchers, while the entire array will be applied
as the arguments for function matchers.
* __options__: (_Object_ [optional]_) Any of the [picomatch](https://github.com/micromatch/picomatch#options) options.
* __returnIndex__: (_Boolean [optional]_) If true, return the array index of
the first matcher that that testString matched, or -1 if no match, instead of a
boolean result.
```js
const anymatch = require('anymatch');
const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ;
anymatch(matchers, 'path/to/file.js'); // true
anymatch(matchers, 'path/anyjs/baz.js'); // true
anymatch(matchers, 'path/to/foo.js'); // true
anymatch(matchers, 'path/to/bar.js'); // true
anymatch(matchers, 'bar.js'); // false
// returnIndex = true
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1
// any picomatc
// using globs to match directories and their children
anymatch('node_modules', 'node_modules'); // true
anymatch('node_modules', 'node_modules/somelib/index.js'); // false
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
const matcher = anymatch(matchers);
['foo.js', 'bar.js'].filter(matcher); // [ 'foo.js' ]
anymatch master*
```
#### anymatch(matchers)
You can also pass in only your matcher(s) to get a curried function that has
already been bound to the provided matching criteria. This can be used as an
`Array#filter` callback.
```js
var matcher = anymatch(matchers);
matcher('path/to/file.js'); // true
matcher('path/anyjs/baz.js', true); // 1
['foo.js', 'bar.js'].filter(matcher); // ['foo.js']
```
Changelog
----------
[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
- **v3.0:** Removed `startIndex` and `endIndex` arguments. Node 8.x-only.
- **v2.0:** [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
- **v1.2:** anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
for glob pattern matching. Issues with glob pattern matching should be
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
License
-------
[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)

View File

@@ -1,20 +0,0 @@
type AnymatchFn = (testString: string) => boolean;
type AnymatchPattern = string|RegExp|AnymatchFn;
type AnymatchMatcher = AnymatchPattern|AnymatchPattern[]
type AnymatchTester = {
(testString: string|any[], returnIndex: true): number;
(testString: string|any[]): boolean;
}
type PicomatchOptions = {dot: boolean};
declare const anymatch: {
(matchers: AnymatchMatcher): AnymatchTester;
(matchers: AnymatchMatcher, testString: null, returnIndex: true | PicomatchOptions): AnymatchTester;
(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number;
(matchers: AnymatchMatcher, testString: string|any[]): boolean;
}
export {AnymatchMatcher as Matcher}
export {AnymatchTester as Tester}
export default anymatch

View File

@@ -1,104 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const picomatch = require('picomatch');
const normalizePath = require('normalize-path');
/**
* @typedef {(testString: string) => boolean} AnymatchFn
* @typedef {string|RegExp|AnymatchFn} AnymatchPattern
* @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
*/
const BANG = '!';
const DEFAULT_OPTIONS = {returnIndex: false};
const arrify = (item) => Array.isArray(item) ? item : [item];
/**
* @param {AnymatchPattern} matcher
* @param {object} options
* @returns {AnymatchFn}
*/
const createPattern = (matcher, options) => {
if (typeof matcher === 'function') {
return matcher;
}
if (typeof matcher === 'string') {
const glob = picomatch(matcher, options);
return (string) => matcher === string || glob(string);
}
if (matcher instanceof RegExp) {
return (string) => matcher.test(string);
}
return (string) => false;
};
/**
* @param {Array<Function>} patterns
* @param {Array<Function>} negPatterns
* @param {String|Array} args
* @param {Boolean} returnIndex
* @returns {boolean|number}
*/
const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
const isList = Array.isArray(args);
const _path = isList ? args[0] : args;
if (!isList && typeof _path !== 'string') {
throw new TypeError('anymatch: second argument must be a string: got ' +
Object.prototype.toString.call(_path))
}
const path = normalizePath(_path, false);
for (let index = 0; index < negPatterns.length; index++) {
const nglob = negPatterns[index];
if (nglob(path)) {
return returnIndex ? -1 : false;
}
}
const applied = isList && [path].concat(args.slice(1));
for (let index = 0; index < patterns.length; index++) {
const pattern = patterns[index];
if (isList ? pattern(...applied) : pattern(path)) {
return returnIndex ? index : true;
}
}
return returnIndex ? -1 : false;
};
/**
* @param {AnymatchMatcher} matchers
* @param {Array|string} testString
* @param {object} options
* @returns {boolean|number|Function}
*/
const anymatch = (matchers, testString, options = DEFAULT_OPTIONS) => {
if (matchers == null) {
throw new TypeError('anymatch: specify first argument');
}
const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
const returnIndex = opts.returnIndex || false;
// Early cache for matchers.
const mtchers = arrify(matchers);
const negatedGlobs = mtchers
.filter(item => typeof item === 'string' && item.charAt(0) === BANG)
.map(item => item.slice(1))
.map(item => picomatch(item, opts));
const patterns = mtchers
.filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG))
.map(matcher => createPattern(matcher, opts));
if (testString == null) {
return (testString, ri = false) => {
const returnIndex = typeof ri === 'boolean' ? ri : false;
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
}
}
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
};
anymatch.default = anymatch;
module.exports = anymatch;

View File

@@ -1,48 +0,0 @@
{
"name": "anymatch",
"version": "3.1.3",
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions",
"files": [
"index.js",
"index.d.ts"
],
"dependencies": {
"normalize-path": "^3.0.0",
"picomatch": "^2.0.4"
},
"author": {
"name": "Elan Shanker",
"url": "https://github.com/es128"
},
"license": "ISC",
"homepage": "https://github.com/micromatch/anymatch",
"repository": {
"type": "git",
"url": "https://github.com/micromatch/anymatch"
},
"keywords": [
"match",
"any",
"string",
"file",
"fs",
"list",
"glob",
"regex",
"regexp",
"regular",
"expression",
"function"
],
"scripts": {
"test": "nyc mocha",
"mocha": "mocha"
},
"devDependencies": {
"mocha": "^6.1.3",
"nyc": "^14.0.0"
},
"engines": {
"node": ">= 8"
}
}

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,43 +0,0 @@
# Array Flatten
[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
> Flatten an array of nested arrays into a single flat array. Accepts an optional depth.
## Installation
```
npm install array-flatten --save
```
## Usage
```javascript
var flatten = require('array-flatten')
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
(function () {
flatten(arguments) //=> [1, 2, 3]
})(1, [2, 3])
```
## License
MIT
[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat
[npm-url]: https://npmjs.org/package/array-flatten
[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat
[downloads-url]: https://npmjs.org/package/array-flatten
[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat
[travis-url]: https://travis-ci.org/blakeembrey/array-flatten
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master

View File

@@ -1,64 +0,0 @@
'use strict'
/**
* Expose `arrayFlatten`.
*/
module.exports = arrayFlatten
/**
* Recursive flatten function with depth.
*
* @param {Array} array
* @param {Array} result
* @param {Number} depth
* @return {Array}
*/
function flattenWithDepth (array, result, depth) {
for (var i = 0; i < array.length; i++) {
var value = array[i]
if (depth > 0 && Array.isArray(value)) {
flattenWithDepth(value, result, depth - 1)
} else {
result.push(value)
}
}
return result
}
/**
* Recursive flatten function. Omitting depth is slightly faster.
*
* @param {Array} array
* @param {Array} result
* @return {Array}
*/
function flattenForever (array, result) {
for (var i = 0; i < array.length; i++) {
var value = array[i]
if (Array.isArray(value)) {
flattenForever(value, result)
} else {
result.push(value)
}
}
return result
}
/**
* Flatten an array, with the ability to define a depth.
*
* @param {Array} array
* @param {Number} depth
* @return {Array}
*/
function arrayFlatten (array, depth) {
if (depth == null) {
return flattenForever(array, [])
}
return flattenWithDepth(array, [], depth)
}

View File

@@ -1,39 +0,0 @@
{
"name": "array-flatten",
"version": "1.1.1",
"description": "Flatten an array of nested arrays into a single flat array",
"main": "array-flatten.js",
"files": [
"array-flatten.js",
"LICENSE"
],
"scripts": {
"test": "istanbul cover _mocha -- -R spec"
},
"repository": {
"type": "git",
"url": "git://github.com/blakeembrey/array-flatten.git"
},
"keywords": [
"array",
"flatten",
"arguments",
"depth"
],
"author": {
"name": "Blake Embrey",
"email": "hello@blakeembrey.com",
"url": "http://blakeembrey.me"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/blakeembrey/array-flatten/issues"
},
"homepage": "https://github.com/blakeembrey/array-flatten",
"devDependencies": {
"istanbul": "^0.3.13",
"mocha": "^2.2.4",
"pre-commit": "^1.0.7",
"standard": "^3.7.3"
}
}

View File

@@ -1,2 +0,0 @@
tidelift: "npm/balanced-match"
patreon: juliangruber

View File

@@ -1,21 +0,0 @@
(MIT)
Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,97 +0,0 @@
# balanced-match
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
[![build status](https://secure.travis-ci.org/juliangruber/balanced-match.svg)](http://travis-ci.org/juliangruber/balanced-match)
[![downloads](https://img.shields.io/npm/dm/balanced-match.svg)](https://www.npmjs.org/package/balanced-match)
[![testling badge](https://ci.testling.com/juliangruber/balanced-match.png)](https://ci.testling.com/juliangruber/balanced-match)
## Example
Get the first matching pair of braces:
```js
var balanced = require('balanced-match');
console.log(balanced('{', '}', 'pre{in{nested}}post'));
console.log(balanced('{', '}', 'pre{first}between{second}post'));
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
```
The matches are:
```bash
$ node example.js
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
{ start: 3,
end: 9,
pre: 'pre',
body: 'first',
post: 'between{second}post' }
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
```
## API
### var m = balanced(a, b, str)
For the first non-nested matching pair of `a` and `b` in `str`, return an
object with those keys:
* **start** the index of the first match of `a`
* **end** the index of the matching `b`
* **pre** the preamble, `a` and `b` not included
* **body** the match, `a` and `b` not included
* **post** the postscript, `a` and `b` not included
If there's no match, `undefined` will be returned.
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
### var r = balanced.range(a, b, str)
For the first non-nested matching pair of `a` and `b` in `str`, return an
array with indexes: `[ <a index>, <b index> ]`.
If there's no match, `undefined` will be returned.
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
## Installation
With [npm](https://npmjs.org) do:
```bash
npm install balanced-match
```
## Security contact information
To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.
## License
(MIT)
Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,62 +0,0 @@
'use strict';
module.exports = balanced;
function balanced(a, b, str) {
if (a instanceof RegExp) a = maybeMatch(a, str);
if (b instanceof RegExp) b = maybeMatch(b, str);
var r = range(a, b, str);
return r && {
start: r[0],
end: r[1],
pre: str.slice(0, r[0]),
body: str.slice(r[0] + a.length, r[1]),
post: str.slice(r[1] + b.length)
};
}
function maybeMatch(reg, str) {
var m = str.match(reg);
return m ? m[0] : null;
}
balanced.range = range;
function range(a, b, str) {
var begs, beg, left, right, result;
var ai = str.indexOf(a);
var bi = str.indexOf(b, ai + 1);
var i = ai;
if (ai >= 0 && bi > 0) {
if(a===b) {
return [ai, bi];
}
begs = [];
left = str.length;
while (i >= 0 && !result) {
if (i == ai) {
begs.push(i);
ai = str.indexOf(a, i + 1);
} else if (begs.length == 1) {
result = [ begs.pop(), bi ];
} else {
beg = begs.pop();
if (beg < left) {
left = beg;
right = bi;
}
bi = str.indexOf(b, i + 1);
}
i = ai < bi && ai >= 0 ? ai : bi;
}
if (begs.length) {
result = [ left, right ];
}
}
return result;
}

View File

@@ -1,48 +0,0 @@
{
"name": "balanced-match",
"description": "Match balanced character pairs, like \"{\" and \"}\"",
"version": "1.0.2",
"repository": {
"type": "git",
"url": "git://github.com/juliangruber/balanced-match.git"
},
"homepage": "https://github.com/juliangruber/balanced-match",
"main": "index.js",
"scripts": {
"test": "tape test/test.js",
"bench": "matcha test/bench.js"
},
"devDependencies": {
"matcha": "^0.7.0",
"tape": "^4.6.0"
},
"keywords": [
"match",
"regexp",
"test",
"balanced",
"parse"
],
"author": {
"name": "Julian Gruber",
"email": "mail@juliangruber.com",
"url": "http://juliangruber.com"
},
"license": "MIT",
"testling": {
"files": "test/*.js",
"browsers": [
"ie/8..latest",
"firefox/20..latest",
"firefox/nightly",
"chrome/25..latest",
"chrome/canary",
"opera/12..latest",
"opera/next",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
}
}

View File

@@ -1,52 +0,0 @@
2.0.1 / 2018-09-19
==================
* deps: safe-buffer@5.1.2
2.0.0 / 2017-09-12
==================
* Drop support for Node.js below 0.8
* Remove `auth(ctx)` signature -- pass in header or `auth(ctx.req)`
* Use `safe-buffer` for improved Buffer API
1.1.0 / 2016-11-18
==================
* Add `auth.parse` for low-level string parsing
1.0.4 / 2016-05-10
==================
* Improve error message when `req` argument is not an object
* Improve error message when `req` missing `headers` property
1.0.3 / 2015-07-01
==================
* Fix regression accepting a Koa context
1.0.2 / 2015-06-12
==================
* Improve error message when `req` argument missing
* perf: enable strict mode
* perf: hoist regular expression
* perf: parse with regular expressions
* perf: remove argument reassignment
1.0.1 / 2015-05-04
==================
* Update readme
1.0.0 / 2014-07-01
==================
* Support empty password
* Support empty username
0.0.1 / 2013-11-30
==================
* Initial release

View File

@@ -1,24 +0,0 @@
(The MIT License)
Copyright (c) 2013 TJ Holowaychuk
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2015-2016 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,113 +0,0 @@
# basic-auth
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Generic basic auth Authorization header field parser for whatever.
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```
$ npm install basic-auth
```
## API
<!-- eslint-disable no-unused-vars -->
```js
var auth = require('basic-auth')
```
### auth(req)
Get the basic auth credentials from the given request. The `Authorization`
header is parsed and if the header is invalid, `undefined` is returned,
otherwise an object with `name` and `pass` properties.
### auth.parse(string)
Parse a basic auth authorization header string. This will return an object
with `name` and `pass` properties, or `undefined` if the string is invalid.
## Example
Pass a Node.js request object to the module export. If parsing fails
`undefined` is returned, otherwise an object with `.name` and `.pass`.
<!-- eslint-disable no-unused-vars, no-undef -->
```js
var auth = require('basic-auth')
var user = auth(req)
// => { name: 'something', pass: 'whatever' }
```
A header string from any other location can also be parsed with
`auth.parse`, for example a `Proxy-Authorization` header:
<!-- eslint-disable no-unused-vars, no-undef -->
```js
var auth = require('basic-auth')
var user = auth.parse(req.getHeader('Proxy-Authorization'))
```
### With vanilla node.js http server
```js
var http = require('http')
var auth = require('basic-auth')
var compare = require('tsscmp')
// Create server
var server = http.createServer(function (req, res) {
var credentials = auth(req)
// Check credentials
// The "check" function will typically be against your user store
if (!credentials || !check(credentials.name, credentials.pass)) {
res.statusCode = 401
res.setHeader('WWW-Authenticate', 'Basic realm="example"')
res.end('Access denied')
} else {
res.end('Access granted')
}
})
// Basic function to validate credentials for example
function check (name, pass) {
var valid = true
// Simple method to prevent short-circut and use timing-safe compare
valid = compare(name, 'john') && valid
valid = compare(pass, 'secret') && valid
return valid
}
// Listen
server.listen(3000)
```
# License
[MIT](LICENSE)
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/basic-auth/master
[coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master
[downloads-image]: https://badgen.net/npm/dm/basic-auth
[downloads-url]: https://npmjs.org/package/basic-auth
[node-version-image]: https://badgen.net/npm/node/basic-auth
[node-version-url]: https://nodejs.org/en/download
[npm-image]: https://badgen.net/npm/v/basic-auth
[npm-url]: https://npmjs.org/package/basic-auth
[travis-image]: https://badgen.net/travis/jshttp/basic-auth/master
[travis-url]: https://travis-ci.org/jshttp/basic-auth

View File

@@ -1,133 +0,0 @@
/*!
* basic-auth
* Copyright(c) 2013 TJ Holowaychuk
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015-2016 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var Buffer = require('safe-buffer').Buffer
/**
* Module exports.
* @public
*/
module.exports = auth
module.exports.parse = parse
/**
* RegExp for basic auth credentials
*
* credentials = auth-scheme 1*SP token68
* auth-scheme = "Basic" ; case insensitive
* token68 = 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="
* @private
*/
var CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/
/**
* RegExp for basic auth user/pass
*
* user-pass = userid ":" password
* userid = *<TEXT excluding ":">
* password = *TEXT
* @private
*/
var USER_PASS_REGEXP = /^([^:]*):(.*)$/
/**
* Parse the Authorization header field of a request.
*
* @param {object} req
* @return {object} with .name and .pass
* @public
*/
function auth (req) {
if (!req) {
throw new TypeError('argument req is required')
}
if (typeof req !== 'object') {
throw new TypeError('argument req is required to be an object')
}
// get header
var header = getAuthorization(req)
// parse header
return parse(header)
}
/**
* Decode base64 string.
* @private
*/
function decodeBase64 (str) {
return Buffer.from(str, 'base64').toString()
}
/**
* Get the Authorization header from request object.
* @private
*/
function getAuthorization (req) {
if (!req.headers || typeof req.headers !== 'object') {
throw new TypeError('argument req is required to have headers property')
}
return req.headers.authorization
}
/**
* Parse basic auth to object.
*
* @param {string} string
* @return {object}
* @public
*/
function parse (string) {
if (typeof string !== 'string') {
return undefined
}
// parse header
var match = CREDENTIALS_REGEXP.exec(string)
if (!match) {
return undefined
}
// decode user pass
var userPass = USER_PASS_REGEXP.exec(decodeBase64(match[1]))
if (!userPass) {
return undefined
}
// return credentials object
return new Credentials(userPass[1], userPass[2])
}
/**
* Object to represent user credentials.
* @private
*/
function Credentials (name, pass) {
this.name = name
this.pass = pass
}

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) Feross Aboukhadijeh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,584 +0,0 @@
# safe-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
[travis-image]: https://img.shields.io/travis/feross/safe-buffer/master.svg
[travis-url]: https://travis-ci.org/feross/safe-buffer
[npm-image]: https://img.shields.io/npm/v/safe-buffer.svg
[npm-url]: https://npmjs.org/package/safe-buffer
[downloads-image]: https://img.shields.io/npm/dm/safe-buffer.svg
[downloads-url]: https://npmjs.org/package/safe-buffer
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com
#### Safer Node.js Buffer API
**Use the new Node.js Buffer APIs (`Buffer.from`, `Buffer.alloc`,
`Buffer.allocUnsafe`, `Buffer.allocUnsafeSlow`) in all versions of Node.js.**
**Uses the built-in implementation when available.**
## install
```
npm install safe-buffer
```
## usage
The goal of this package is to provide a safe replacement for the node.js `Buffer`.
It's a drop-in replacement for `Buffer`. You can use it by adding one `require` line to
the top of your node.js modules:
```js
var Buffer = require('safe-buffer').Buffer
// Existing buffer code will continue to work without issues:
new Buffer('hey', 'utf8')
new Buffer([1, 2, 3], 'utf8')
new Buffer(obj)
new Buffer(16) // create an uninitialized buffer (potentially unsafe)
// But you can use these new explicit APIs to make clear what you want:
Buffer.from('hey', 'utf8') // convert from many types to a Buffer
Buffer.alloc(16) // create a zero-filled buffer (safe)
Buffer.allocUnsafe(16) // create an uninitialized buffer (potentially unsafe)
```
## api
### Class Method: Buffer.from(array)
<!-- YAML
added: v3.0.0
-->
* `array` {Array}
Allocates a new `Buffer` using an `array` of octets.
```js
const buf = Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]);
// creates a new Buffer containing ASCII bytes
// ['b','u','f','f','e','r']
```
A `TypeError` will be thrown if `array` is not an `Array`.
### Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
<!-- YAML
added: v5.10.0
-->
* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a `TypedArray` or
a `new ArrayBuffer()`
* `byteOffset` {Number} Default: `0`
* `length` {Number} Default: `arrayBuffer.length - byteOffset`
When passed a reference to the `.buffer` property of a `TypedArray` instance,
the newly created `Buffer` will share the same allocated memory as the
TypedArray.
```js
const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;
const buf = Buffer.from(arr.buffer); // shares the memory with arr;
console.log(buf);
// Prints: <Buffer 88 13 a0 0f>
// changing the TypedArray changes the Buffer also
arr[1] = 6000;
console.log(buf);
// Prints: <Buffer 88 13 70 17>
```
The optional `byteOffset` and `length` arguments specify a memory range within
the `arrayBuffer` that will be shared by the `Buffer`.
```js
const ab = new ArrayBuffer(10);
const buf = Buffer.from(ab, 0, 2);
console.log(buf.length);
// Prints: 2
```
A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer`.
### Class Method: Buffer.from(buffer)
<!-- YAML
added: v3.0.0
-->
* `buffer` {Buffer}
Copies the passed `buffer` data onto a new `Buffer` instance.
```js
const buf1 = Buffer.from('buffer');
const buf2 = Buffer.from(buf1);
buf1[0] = 0x61;
console.log(buf1.toString());
// 'auffer'
console.log(buf2.toString());
// 'buffer' (copy is not changed)
```
A `TypeError` will be thrown if `buffer` is not a `Buffer`.
### Class Method: Buffer.from(str[, encoding])
<!-- YAML
added: v5.10.0
-->
* `str` {String} String to encode.
* `encoding` {String} Encoding to use, Default: `'utf8'`
Creates a new `Buffer` containing the given JavaScript string `str`. If
provided, the `encoding` parameter identifies the character encoding.
If not provided, `encoding` defaults to `'utf8'`.
```js
const buf1 = Buffer.from('this is a tést');
console.log(buf1.toString());
// prints: this is a tést
console.log(buf1.toString('ascii'));
// prints: this is a tC)st
const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
console.log(buf2.toString());
// prints: this is a tést
```
A `TypeError` will be thrown if `str` is not a string.
### Class Method: Buffer.alloc(size[, fill[, encoding]])
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
* `fill` {Value} Default: `undefined`
* `encoding` {String} Default: `utf8`
Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the
`Buffer` will be *zero-filled*.
```js
const buf = Buffer.alloc(5);
console.log(buf);
// <Buffer 00 00 00 00 00>
```
The `size` must be less than or equal to the value of
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
be created if a `size` less than or equal to 0 is specified.
If `fill` is specified, the allocated `Buffer` will be initialized by calling
`buf.fill(fill)`. See [`buf.fill()`][] for more information.
```js
const buf = Buffer.alloc(5, 'a');
console.log(buf);
// <Buffer 61 61 61 61 61>
```
If both `fill` and `encoding` are specified, the allocated `Buffer` will be
initialized by calling `buf.fill(fill, encoding)`. For example:
```js
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
console.log(buf);
// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
```
Calling `Buffer.alloc(size)` can be significantly slower than the alternative
`Buffer.allocUnsafe(size)` but ensures that the newly created `Buffer` instance
contents will *never contain sensitive data*.
A `TypeError` will be thrown if `size` is not a number.
### Class Method: Buffer.allocUnsafe(size)
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must
be less than or equal to the value of `require('buffer').kMaxLength` (on 64-bit
architectures, `kMaxLength` is `(2^31)-1`). Otherwise, a [`RangeError`][] is
thrown. A zero-length Buffer will be created if a `size` less than or equal to
0 is specified.
The underlying memory for `Buffer` instances created in this way is *not
initialized*. The contents of the newly created `Buffer` are unknown and
*may contain sensitive data*. Use [`buf.fill(0)`][] to initialize such
`Buffer` instances to zeroes.
```js
const buf = Buffer.allocUnsafe(5);
console.log(buf);
// <Buffer 78 e0 82 02 01>
// (octets will be different, every time)
buf.fill(0);
console.log(buf);
// <Buffer 00 00 00 00 00>
```
A `TypeError` will be thrown if `size` is not a number.
Note that the `Buffer` module pre-allocates an internal `Buffer` instance of
size `Buffer.poolSize` that is used as a pool for the fast allocation of new
`Buffer` instances created using `Buffer.allocUnsafe(size)` (and the deprecated
`new Buffer(size)` constructor) only when `size` is less than or equal to
`Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two). The default
value of `Buffer.poolSize` is `8192` but can be modified.
Use of this pre-allocated internal memory pool is a key difference between
calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
Specifically, `Buffer.alloc(size, fill)` will *never* use the internal Buffer
pool, while `Buffer.allocUnsafe(size).fill(fill)` *will* use the internal
Buffer pool if `size` is less than or equal to half `Buffer.poolSize`. The
difference is subtle but can be important when an application requires the
additional performance that `Buffer.allocUnsafe(size)` provides.
### Class Method: Buffer.allocUnsafeSlow(size)
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
Allocates a new *non-zero-filled* and non-pooled `Buffer` of `size` bytes. The
`size` must be less than or equal to the value of
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
be created if a `size` less than or equal to 0 is specified.
The underlying memory for `Buffer` instances created in this way is *not
initialized*. The contents of the newly created `Buffer` are unknown and
*may contain sensitive data*. Use [`buf.fill(0)`][] to initialize such
`Buffer` instances to zeroes.
When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
allocations under 4KB are, by default, sliced from a single pre-allocated
`Buffer`. This allows applications to avoid the garbage collection overhead of
creating many individually allocated Buffers. This approach improves both
performance and memory usage by eliminating the need to track and cleanup as
many `Persistent` objects.
However, in the case where a developer may need to retain a small chunk of
memory from a pool for an indeterminate amount of time, it may be appropriate
to create an un-pooled Buffer instance using `Buffer.allocUnsafeSlow()` then
copy out the relevant bits.
```js
// need to keep around a few small chunks of memory
const store = [];
socket.on('readable', () => {
const data = socket.read();
// allocate for retained data
const sb = Buffer.allocUnsafeSlow(10);
// copy the data into the new allocation
data.copy(sb, 0, 0, 10);
store.push(sb);
});
```
Use of `Buffer.allocUnsafeSlow()` should be used only as a last resort *after*
a developer has observed undue memory retention in their applications.
A `TypeError` will be thrown if `size` is not a number.
### All the Rest
The rest of the `Buffer` API is exactly the same as in node.js.
[See the docs](https://nodejs.org/api/buffer.html).
## Related links
- [Node.js issue: Buffer(number) is unsafe](https://github.com/nodejs/node/issues/4660)
- [Node.js Enhancement Proposal: Buffer.from/Buffer.alloc/Buffer.zalloc/Buffer() soft-deprecate](https://github.com/nodejs/node-eps/pull/4)
## Why is `Buffer` unsafe?
Today, the node.js `Buffer` constructor is overloaded to handle many different argument
types like `String`, `Array`, `Object`, `TypedArrayView` (`Uint8Array`, etc.),
`ArrayBuffer`, and also `Number`.
The API is optimized for convenience: you can throw any type at it, and it will try to do
what you want.
Because the Buffer constructor is so powerful, you often see code like this:
```js
// Convert UTF-8 strings to hex
function toHex (str) {
return new Buffer(str).toString('hex')
}
```
***But what happens if `toHex` is called with a `Number` argument?***
### Remote Memory Disclosure
If an attacker can make your program call the `Buffer` constructor with a `Number`
argument, then they can make it allocate uninitialized memory from the node.js process.
This could potentially disclose TLS private keys, user data, or database passwords.
When the `Buffer` constructor is passed a `Number` argument, it returns an
**UNINITIALIZED** block of memory of the specified `size`. When you create a `Buffer` like
this, you **MUST** overwrite the contents before returning it to the user.
From the [node.js docs](https://nodejs.org/api/buffer.html#buffer_new_buffer_size):
> `new Buffer(size)`
>
> - `size` Number
>
> The underlying memory for `Buffer` instances created in this way is not initialized.
> **The contents of a newly created `Buffer` are unknown and could contain sensitive
> data.** Use `buf.fill(0)` to initialize a Buffer to zeroes.
(Emphasis our own.)
Whenever the programmer intended to create an uninitialized `Buffer` you often see code
like this:
```js
var buf = new Buffer(16)
// Immediately overwrite the uninitialized buffer with data from another buffer
for (var i = 0; i < buf.length; i++) {
buf[i] = otherBuf[i]
}
```
### Would this ever be a problem in real code?
Yes. It's surprisingly common to forget to check the type of your variables in a
dynamically-typed language like JavaScript.
Usually the consequences of assuming the wrong type is that your program crashes with an
uncaught exception. But the failure mode for forgetting to check the type of arguments to
the `Buffer` constructor is more catastrophic.
Here's an example of a vulnerable service that takes a JSON payload and converts it to
hex:
```js
// Take a JSON payload {str: "some string"} and convert it to hex
var server = http.createServer(function (req, res) {
var data = ''
req.setEncoding('utf8')
req.on('data', function (chunk) {
data += chunk
})
req.on('end', function () {
var body = JSON.parse(data)
res.end(new Buffer(body.str).toString('hex'))
})
})
server.listen(8080)
```
In this example, an http client just has to send:
```json
{
"str": 1000
}
```
and it will get back 1,000 bytes of uninitialized memory from the server.
This is a very serious bug. It's similar in severity to the
[the Heartbleed bug](http://heartbleed.com/) that allowed disclosure of OpenSSL process
memory by remote attackers.
### Which real-world packages were vulnerable?
#### [`bittorrent-dht`](https://www.npmjs.com/package/bittorrent-dht)
[Mathias Buus](https://github.com/mafintosh) and I
([Feross Aboukhadijeh](http://feross.org/)) found this issue in one of our own packages,
[`bittorrent-dht`](https://www.npmjs.com/package/bittorrent-dht). The bug would allow
anyone on the internet to send a series of messages to a user of `bittorrent-dht` and get
them to reveal 20 bytes at a time of uninitialized memory from the node.js process.
Here's
[the commit](https://github.com/feross/bittorrent-dht/commit/6c7da04025d5633699800a99ec3fbadf70ad35b8)
that fixed it. We released a new fixed version, created a
[Node Security Project disclosure](https://nodesecurity.io/advisories/68), and deprecated all
vulnerable versions on npm so users will get a warning to upgrade to a newer version.
#### [`ws`](https://www.npmjs.com/package/ws)
That got us wondering if there were other vulnerable packages. Sure enough, within a short
period of time, we found the same issue in [`ws`](https://www.npmjs.com/package/ws), the
most popular WebSocket implementation in node.js.
If certain APIs were called with `Number` parameters instead of `String` or `Buffer` as
expected, then uninitialized server memory would be disclosed to the remote peer.
These were the vulnerable methods:
```js
socket.send(number)
socket.ping(number)
socket.pong(number)
```
Here's a vulnerable socket server with some echo functionality:
```js
server.on('connection', function (socket) {
socket.on('message', function (message) {
message = JSON.parse(message)
if (message.type === 'echo') {
socket.send(message.data) // send back the user's message
}
})
})
```
`socket.send(number)` called on the server, will disclose server memory.
Here's [the release](https://github.com/websockets/ws/releases/tag/1.0.1) where the issue
was fixed, with a more detailed explanation. Props to
[Arnout Kazemier](https://github.com/3rd-Eden) for the quick fix. Here's the
[Node Security Project disclosure](https://nodesecurity.io/advisories/67).
### What's the solution?
It's important that node.js offers a fast way to get memory otherwise performance-critical
applications would needlessly get a lot slower.
But we need a better way to *signal our intent* as programmers. **When we want
uninitialized memory, we should request it explicitly.**
Sensitive functionality should not be packed into a developer-friendly API that loosely
accepts many different types. This type of API encourages the lazy practice of passing
variables in without checking the type very carefully.
#### A new API: `Buffer.allocUnsafe(number)`
The functionality of creating buffers with uninitialized memory should be part of another
API. We propose `Buffer.allocUnsafe(number)`. This way, it's not part of an API that
frequently gets user input of all sorts of different types passed into it.
```js
var buf = Buffer.allocUnsafe(16) // careful, uninitialized memory!
// Immediately overwrite the uninitialized buffer with data from another buffer
for (var i = 0; i < buf.length; i++) {
buf[i] = otherBuf[i]
}
```
### How do we fix node.js core?
We sent [a PR to node.js core](https://github.com/nodejs/node/pull/4514) (merged as
`semver-major`) which defends against one case:
```js
var str = 16
new Buffer(str, 'utf8')
```
In this situation, it's implied that the programmer intended the first argument to be a
string, since they passed an encoding as a second argument. Today, node.js will allocate
uninitialized memory in the case of `new Buffer(number, encoding)`, which is probably not
what the programmer intended.
But this is only a partial solution, since if the programmer does `new Buffer(variable)`
(without an `encoding` parameter) there's no way to know what they intended. If `variable`
is sometimes a number, then uninitialized memory will sometimes be returned.
### What's the real long-term fix?
We could deprecate and remove `new Buffer(number)` and use `Buffer.allocUnsafe(number)` when
we need uninitialized memory. But that would break 1000s of packages.
~~We believe the best solution is to:~~
~~1. Change `new Buffer(number)` to return safe, zeroed-out memory~~
~~2. Create a new API for creating uninitialized Buffers. We propose: `Buffer.allocUnsafe(number)`~~
#### Update
We now support adding three new APIs:
- `Buffer.from(value)` - convert from any type to a buffer
- `Buffer.alloc(size)` - create a zero-filled buffer
- `Buffer.allocUnsafe(size)` - create an uninitialized buffer with given size
This solves the core problem that affected `ws` and `bittorrent-dht` which is
`Buffer(variable)` getting tricked into taking a number argument.
This way, existing code continues working and the impact on the npm ecosystem will be
minimal. Over time, npm maintainers can migrate performance-critical code to use
`Buffer.allocUnsafe(number)` instead of `new Buffer(number)`.
### Conclusion
We think there's a serious design issue with the `Buffer` API as it exists today. It
promotes insecure software by putting high-risk functionality into a convenient API
with friendly "developer ergonomics".
This wasn't merely a theoretical exercise because we found the issue in some of the
most popular npm packages.
Fortunately, there's an easy fix that can be applied today. Use `safe-buffer` in place of
`buffer`.
```js
var Buffer = require('safe-buffer').Buffer
```
Eventually, we hope that node.js core can switch to this new, safer behavior. We believe
the impact on the ecosystem would be minimal since it's not a breaking change.
Well-maintained, popular packages would be updated to use `Buffer.alloc` quickly, while
older, insecure packages would magically become safe from this attack vector.
## links
- [Node.js PR: buffer: throw if both length and enc are passed](https://github.com/nodejs/node/pull/4514)
- [Node Security Project disclosure for `ws`](https://nodesecurity.io/advisories/67)
- [Node Security Project disclosure for`bittorrent-dht`](https://nodesecurity.io/advisories/68)
## credit
The original issues in `bittorrent-dht`
([disclosure](https://nodesecurity.io/advisories/68)) and
`ws` ([disclosure](https://nodesecurity.io/advisories/67)) were discovered by
[Mathias Buus](https://github.com/mafintosh) and
[Feross Aboukhadijeh](http://feross.org/).
Thanks to [Adam Baldwin](https://github.com/evilpacket) for helping disclose these issues
and for his work running the [Node Security Project](https://nodesecurity.io/).
Thanks to [John Hiesey](https://github.com/jhiesey) for proofreading this README and
auditing the code.
## license
MIT. Copyright (C) [Feross Aboukhadijeh](http://feross.org)

View File

@@ -1,187 +0,0 @@
declare module "safe-buffer" {
export class Buffer {
length: number
write(string: string, offset?: number, length?: number, encoding?: string): number;
toString(encoding?: string, start?: number, end?: number): string;
toJSON(): { type: 'Buffer', data: any[] };
equals(otherBuffer: Buffer): boolean;
compare(otherBuffer: Buffer, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number;
copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
slice(start?: number, end?: number): Buffer;
writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
readIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
readIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
readUInt8(offset: number, noAssert?: boolean): number;
readUInt16LE(offset: number, noAssert?: boolean): number;
readUInt16BE(offset: number, noAssert?: boolean): number;
readUInt32LE(offset: number, noAssert?: boolean): number;
readUInt32BE(offset: number, noAssert?: boolean): number;
readInt8(offset: number, noAssert?: boolean): number;
readInt16LE(offset: number, noAssert?: boolean): number;
readInt16BE(offset: number, noAssert?: boolean): number;
readInt32LE(offset: number, noAssert?: boolean): number;
readInt32BE(offset: number, noAssert?: boolean): number;
readFloatLE(offset: number, noAssert?: boolean): number;
readFloatBE(offset: number, noAssert?: boolean): number;
readDoubleLE(offset: number, noAssert?: boolean): number;
readDoubleBE(offset: number, noAssert?: boolean): number;
swap16(): Buffer;
swap32(): Buffer;
swap64(): Buffer;
writeUInt8(value: number, offset: number, noAssert?: boolean): number;
writeUInt16LE(value: number, offset: number, noAssert?: boolean): number;
writeUInt16BE(value: number, offset: number, noAssert?: boolean): number;
writeUInt32LE(value: number, offset: number, noAssert?: boolean): number;
writeUInt32BE(value: number, offset: number, noAssert?: boolean): number;
writeInt8(value: number, offset: number, noAssert?: boolean): number;
writeInt16LE(value: number, offset: number, noAssert?: boolean): number;
writeInt16BE(value: number, offset: number, noAssert?: boolean): number;
writeInt32LE(value: number, offset: number, noAssert?: boolean): number;
writeInt32BE(value: number, offset: number, noAssert?: boolean): number;
writeFloatLE(value: number, offset: number, noAssert?: boolean): number;
writeFloatBE(value: number, offset: number, noAssert?: boolean): number;
writeDoubleLE(value: number, offset: number, noAssert?: boolean): number;
writeDoubleBE(value: number, offset: number, noAssert?: boolean): number;
fill(value: any, offset?: number, end?: number): this;
indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean;
/**
* Allocates a new buffer containing the given {str}.
*
* @param str String to store in buffer.
* @param encoding encoding to use, optional. Default is 'utf8'
*/
constructor (str: string, encoding?: string);
/**
* Allocates a new buffer of {size} octets.
*
* @param size count of octets to allocate.
*/
constructor (size: number);
/**
* Allocates a new buffer containing the given {array} of octets.
*
* @param array The octets to store.
*/
constructor (array: Uint8Array);
/**
* Produces a Buffer backed by the same allocated memory as
* the given {ArrayBuffer}.
*
*
* @param arrayBuffer The ArrayBuffer with which to share memory.
*/
constructor (arrayBuffer: ArrayBuffer);
/**
* Allocates a new buffer containing the given {array} of octets.
*
* @param array The octets to store.
*/
constructor (array: any[]);
/**
* Copies the passed {buffer} data onto a new {Buffer} instance.
*
* @param buffer The buffer to copy.
*/
constructor (buffer: Buffer);
prototype: Buffer;
/**
* Allocates a new Buffer using an {array} of octets.
*
* @param array
*/
static from(array: any[]): Buffer;
/**
* When passed a reference to the .buffer property of a TypedArray instance,
* the newly created Buffer will share the same allocated memory as the TypedArray.
* The optional {byteOffset} and {length} arguments specify a memory range
* within the {arrayBuffer} that will be shared by the Buffer.
*
* @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer()
* @param byteOffset
* @param length
*/
static from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
/**
* Copies the passed {buffer} data onto a new Buffer instance.
*
* @param buffer
*/
static from(buffer: Buffer): Buffer;
/**
* Creates a new Buffer containing the given JavaScript string {str}.
* If provided, the {encoding} parameter identifies the character encoding.
* If not provided, {encoding} defaults to 'utf8'.
*
* @param str
*/
static from(str: string, encoding?: string): Buffer;
/**
* Returns true if {obj} is a Buffer
*
* @param obj object to test.
*/
static isBuffer(obj: any): obj is Buffer;
/**
* Returns true if {encoding} is a valid encoding argument.
* Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
*
* @param encoding string to test.
*/
static isEncoding(encoding: string): boolean;
/**
* Gives the actual byte length of a string. encoding defaults to 'utf8'.
* This is not the same as String.prototype.length since that returns the number of characters in a string.
*
* @param string string to test.
* @param encoding encoding used to evaluate (defaults to 'utf8')
*/
static byteLength(string: string, encoding?: string): number;
/**
* Returns a buffer which is the result of concatenating all the buffers in the list together.
*
* If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer.
* If the list has exactly one item, then the first item of the list is returned.
* If the list has more than one item, then a new Buffer is created.
*
* @param list An array of Buffer objects to concatenate
* @param totalLength Total length of the buffers when concatenated.
* If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.
*/
static concat(list: Buffer[], totalLength?: number): Buffer;
/**
* The same as buf1.compare(buf2).
*/
static compare(buf1: Buffer, buf2: Buffer): number;
/**
* Allocates a new buffer of {size} octets.
*
* @param size count of octets to allocate.
* @param fill if specified, buffer will be initialized by calling buf.fill(fill).
* If parameter is omitted, buffer will be filled with zeros.
* @param encoding encoding used for call to buf.fill while initalizing
*/
static alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer;
/**
* Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents
* of the newly created Buffer are unknown and may contain sensitive data.
*
* @param size count of octets to allocate
*/
static allocUnsafe(size: number): Buffer;
/**
* Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents
* of the newly created Buffer are unknown and may contain sensitive data.
*
* @param size count of octets to allocate
*/
static allocUnsafeSlow(size: number): Buffer;
}
}

Some files were not shown because too many files have changed in this diff Show More