Upload 4 files
Browse files- Dockerfile +32 -0
- README.md +162 -7
- app.py +391 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Usa l'immagine base di Python
|
2 |
+
FROM python:3.12-slim
|
3 |
+
|
4 |
+
# Installa git e certificati SSL
|
5 |
+
RUN apt-get update && apt-get install -y \
|
6 |
+
git \
|
7 |
+
ca-certificates \
|
8 |
+
&& rm -rf /var/lib/apt/lists/*
|
9 |
+
|
10 |
+
# Imposta la directory di lavoro
|
11 |
+
WORKDIR /app
|
12 |
+
|
13 |
+
# Clona il repository GitHub
|
14 |
+
RUN git clone https://github.com/nzo66/tvproxy .
|
15 |
+
|
16 |
+
# Installa le dipendenze
|
17 |
+
RUN pip install --upgrade pip
|
18 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
19 |
+
|
20 |
+
# Espone la porta 7860 per Flask/Gunicorn
|
21 |
+
EXPOSE 7860
|
22 |
+
|
23 |
+
# Comando ottimizzato per avviare il server
|
24 |
+
CMD ["gunicorn", "app:app", \
|
25 |
+
"-w", "4", \
|
26 |
+
"--worker-class", "gevent", \
|
27 |
+
"--worker-connections", "100", \
|
28 |
+
"-b", "0.0.0.0:7860", \
|
29 |
+
"--timeout", "120", \
|
30 |
+
"--keep-alive", "5", \
|
31 |
+
"--max-requests", "1000", \
|
32 |
+
"--max-requests-jitter", "100"]
|
README.md
CHANGED
@@ -1,10 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
8 |
---
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 📺 tvproxy
|
2 |
+
|
3 |
+
## 🚀 M3U8 Proxy Dockerizzato
|
4 |
+
|
5 |
+
Un server proxy leggero basato su **Flask** e **Requests**, progettato per:
|
6 |
+
|
7 |
+
- 📥 Scaricare e modificare flussi **.m3u / .m3u8**
|
8 |
+
- 🔁 Proxare i segmenti `.ts`, mantenendo header personalizzati
|
9 |
+
- 🚫 Superare restrizioni come **Referer**, **User-Agent**, ecc.
|
10 |
+
- 🐳 Essere facilmente **dockerizzabile** su qualsiasi macchina o server
|
11 |
+
|
12 |
+
---
|
13 |
+
|
14 |
+
## ☁️ Deploy su Render
|
15 |
+
|
16 |
+
1. Vai su **Projects → Deploy a Web Service → Public Git Repo**
|
17 |
+
2. Inserisci il repo: `https://github.com/nzo66/tvproxy` → **Connect**
|
18 |
+
3. Dai un nome a piacere
|
19 |
+
4. Imposta **Instance Type** su `Free`
|
20 |
+
5. Clicca su **Deploy Web Service**
|
21 |
+
|
22 |
---
|
23 |
+
|
24 |
+
## 🤗 Deploy su HuggingFace
|
25 |
+
|
26 |
+
`ricora di fare factory rebuild per aggiornare il proxy se ci sono aggiornamenti!`
|
27 |
+
|
28 |
+
1. Crea un nuovo **Space**
|
29 |
+
2. Scegli un nome qualsiasi e imposta **Docker** come tipo
|
30 |
+
3. Lascia **Public** e crea lo Space
|
31 |
+
4. Vai in alto a destra → `⋮` → **Files** → carica **DockerfileHF** rinominandolo **Dockerfile**
|
32 |
+
5. Infine vai su `⋮` → **Embed this Space** per ottenere il **Direct URL**
|
33 |
+
|
34 |
---
|
35 |
|
36 |
+
## 🐳 Docker (Locale o Server)
|
37 |
+
|
38 |
+
### ✅ Costruzione e Avvio
|
39 |
+
|
40 |
+
```bash
|
41 |
+
git clone https://github.com/nzo66/tvproxy.git
|
42 |
+
cd tvproxy
|
43 |
+
docker build -t tvproxy .
|
44 |
+
docker run -d -p 7860:7860 --name tvproxy tvproxy
|
45 |
+
```
|
46 |
+
|
47 |
+
---
|
48 |
+
|
49 |
+
## 🐧 Termux (Dispositivi Android)
|
50 |
+
|
51 |
+
### ✅ Costruzione e Avvio
|
52 |
+
|
53 |
+
```bash
|
54 |
+
pkg install git python -y
|
55 |
+
git clone https://github.com/nzo66/tvproxy.git
|
56 |
+
cd tvproxy
|
57 |
+
pip install -r requirements.txt'
|
58 |
+
gunicorn app:app -w 4 --worker-class gevent --worker-connections 100 -b 0.0.0.0:7860 --timeout 120 --keep-alive 5 --max-requests 1000 --max-requests-jitter 100
|
59 |
+
```
|
60 |
+
|
61 |
+
---
|
62 |
+
|
63 |
+
## 🐍 Avvio con Python (Locale)
|
64 |
+
|
65 |
+
### ✅ Setup e Avvio
|
66 |
+
|
67 |
+
```bash
|
68 |
+
# Clona il repository
|
69 |
+
git clone https://github.com/nzo66/tvproxy.git
|
70 |
+
cd tvproxy
|
71 |
+
|
72 |
+
# Installa le dipendenze
|
73 |
+
pip install -r requirements.txt
|
74 |
+
|
75 |
+
# Avvia il server
|
76 |
+
gunicorn app:app -w 4 --worker-class gevent --worker-connections 100 -b 0.0.0.0:7860 --timeout 120 --keep-alive 5 --max-requests 1000 --max-requests-jitter 100
|
77 |
+
```
|
78 |
+
|
79 |
+
---
|
80 |
+
|
81 |
+
## 🛠️ Gestione Docker
|
82 |
+
|
83 |
+
- 📄 Logs: `docker logs -f tvproxy`
|
84 |
+
- ⛔ Stop: `docker stop tvproxy`
|
85 |
+
- 🔄 Start: `docker start tvproxy`
|
86 |
+
- 🧹 Rimozione: `docker rm -f tvproxy`
|
87 |
+
|
88 |
+
---
|
89 |
+
|
90 |
+
## 🛠️ Come Utilizzare
|
91 |
+
|
92 |
+
Assicurati di sostituire i placeholder come `<server-ip>` con l'indirizzo IP o l'hostname effettivo del tuo server e `<URL_...>` con gli URL specifici.
|
93 |
+
|
94 |
+
---
|
95 |
+
|
96 |
+
### 1. Proxy per Liste M3U Complete 📡
|
97 |
+
|
98 |
+
Questo endpoint è progettato per proxare l'intera lista M3U. È particolarmente utile per garantire compatibilità e stabilità, con supporto menzionato per formati come Vavoo e Daddylive.
|
99 |
+
|
100 |
+
**Formato URL:**
|
101 |
+
```text
|
102 |
+
http://<server-ip>:7860/proxy?url=<URL_LISTA_M3U>
|
103 |
+
```
|
104 |
+
|
105 |
+
**Dove:**
|
106 |
+
- `<server-ip>`: L'indirizzo IP o hostname del tuo server proxy.
|
107 |
+
- `<URL_LISTA_M3U>`: L'URL completo della lista M3U che vuoi proxare.
|
108 |
+
|
109 |
+
> 📝 **Nota:** Questo endpoint è ideale per gestire l'intera collezione di flussi contenuta in un file M3U.
|
110 |
+
|
111 |
+
---
|
112 |
+
|
113 |
+
### 2. Proxy per Singoli Flussi M3U8 (con Headers Personalizzati) 📺✨
|
114 |
+
|
115 |
+
Questo endpoint è specifico per proxare singoli flussi video `.m3u8`. La sua caratteristica distintiva è la capacità di inoltrare headers HTTP personalizzati, essenziale per scenari che richiedono autenticazione specifica o per simulare richieste da client particolari.
|
116 |
+
|
117 |
+
**Formato URL Base:**
|
118 |
+
```text
|
119 |
+
http://<server-ip>:7860/proxy/m3u?url=<URL_FLUSSO_M3U8>
|
120 |
+
```
|
121 |
+
|
122 |
+
**Esempio:**
|
123 |
+
```text
|
124 |
+
http://<server-ip>:7860/proxy/m3u?url=https://example.com/stream.m3u8
|
125 |
+
```
|
126 |
+
|
127 |
+
**Dove:**
|
128 |
+
- `<server-ip>`: L'indirizzo IP o hostname del tuo server proxy.
|
129 |
+
- `<URL_FLUSSO_M3U8>`: L'URL completo del singolo flusso M3U8.
|
130 |
+
|
131 |
+
#### 🎯 Aggiungere Headers HTTP Personalizzati (Opzionale)
|
132 |
+
|
133 |
+
Per includere headers personalizzati nella richiesta al flusso M3U8, accodali all'URL del proxy. Ogni header deve essere prefissato da `&h_`, seguito dal nome dell'header, un segno di uguale (`=`), e il valore dell'header.
|
134 |
+
|
135 |
+
**Formato per gli Headers:**
|
136 |
+
```text
|
137 |
+
&h_<NOME_HEADER>=<VALORE_HEADER>
|
138 |
+
```
|
139 |
+
|
140 |
+
**Esempio con Headers Personalizzati:**
|
141 |
+
```text
|
142 |
+
http://<server-ip>:7860/proxy/m3u?url=https://example.com/stream.m3u8&h_user-agent=Mozilla/5.0...&h_referer=https://ilovetoplay.xyz/&h_origin=https://ilovetoplay.xyz
|
143 |
+
```
|
144 |
+
|
145 |
+
> ⚠️ **Attenzione:**
|
146 |
+
> - Ricorda di sostituire `Mozilla/5.0...` con lo User-Agent completo che intendi utilizzare.
|
147 |
+
> - Se i valori degli header contengono caratteri speciali (es. spazi, due punti), assicurati che siano correttamente URL-encoded per evitare errori.
|
148 |
+
|
149 |
+
---
|
150 |
+
|
151 |
+
## ✅ Caratteristiche
|
152 |
+
|
153 |
+
- 📁 Supporta **.m3u** e **.m3u8** automaticamente
|
154 |
+
- 🧾 Inoltra gli **HTTP Headers** necessari (Auth, Referer, etc.)
|
155 |
+
- 🔓 Supera restrizioni geografiche o di accesso
|
156 |
+
- ����️ Compatibile con **qualsiasi player IPTV**
|
157 |
+
- 🐳 Totalmente dockerizzato, pronto per il deploy
|
158 |
+
- 🐍 Avviabile anche direttamente con **Python**
|
159 |
+
|
160 |
+
---
|
161 |
+
|
162 |
+
## 🎉 Fine!
|
163 |
+
|
164 |
+
> Ora puoi guardare flussi M3U8 ovunque, senza restrizioni!
|
165 |
+
> Enjoy the Stream 🚀
|
app.py
ADDED
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, Response
|
2 |
+
import requests
|
3 |
+
from urllib.parse import urlparse, urljoin, quote, unquote
|
4 |
+
import re
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
def detect_m3u_type(content):
|
11 |
+
"""Rileva se è un M3U (lista IPTV) o un M3U8 (flusso HLS)"""
|
12 |
+
if "#EXTM3U" in content and "#EXTINF" in content:
|
13 |
+
return "m3u8"
|
14 |
+
return "m3u"
|
15 |
+
|
16 |
+
def replace_key_uri(line, headers_query):
|
17 |
+
"""Sostituisce l'URI della chiave AES-128 con il proxy"""
|
18 |
+
match = re.search(r'URI="([^"]+)"', line)
|
19 |
+
if match:
|
20 |
+
key_url = match.group(1)
|
21 |
+
proxied_key_url = f"/proxy/key?url={quote(key_url)}&{headers_query}"
|
22 |
+
return line.replace(key_url, proxied_key_url)
|
23 |
+
return line
|
24 |
+
|
25 |
+
def resolve_m3u8_link(url, headers=None):
|
26 |
+
"""
|
27 |
+
Tenta di risolvere un URL M3U8 supportando sia URL puliti che URL con header concatenati.
|
28 |
+
Gestisce automaticamente l'estrazione degli header dai parametri dell'URL.
|
29 |
+
"""
|
30 |
+
if not url:
|
31 |
+
print("Errore: URL non fornito.")
|
32 |
+
return {"resolved_url": None, "headers": {}}
|
33 |
+
|
34 |
+
print(f"Tentativo di risoluzione URL: {url}")
|
35 |
+
|
36 |
+
# Inizializza gli header di default
|
37 |
+
current_headers = headers if headers else {
|
38 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
|
39 |
+
}
|
40 |
+
|
41 |
+
# **SUPPORTO PER ENTRAMBE LE VERSIONI**
|
42 |
+
clean_url = url
|
43 |
+
extracted_headers = {}
|
44 |
+
|
45 |
+
# Define newkso.ru specific sites and headers
|
46 |
+
daddy_php_sites = [
|
47 |
+
"https://new.newkso.ru/wind/",
|
48 |
+
"https://new.newkso.ru/ddy6/",
|
49 |
+
"https://new.newkso.ru/zeko/",
|
50 |
+
"https://new.newkso.ru/nfs/",
|
51 |
+
"https://new.newkso.ru/dokko1/",
|
52 |
+
]
|
53 |
+
|
54 |
+
# Verifica se l'URL contiene parametri header concatenati
|
55 |
+
if '&h_' in url or '%26h_' in url:
|
56 |
+
print("Rilevati parametri header nell'URL - Estrazione in corso...")
|
57 |
+
|
58 |
+
# Gestisci sia il formato normale che quello URL-encoded
|
59 |
+
if '%26h_' in url:
|
60 |
+
# Per vavoo.to, sostituisci solo %26 con & senza doppia decodifica
|
61 |
+
if 'vavoo.to' in url.lower():
|
62 |
+
url = url.replace('%26', '&')
|
63 |
+
print(f"URL vavoo.to processato: {url}")
|
64 |
+
else:
|
65 |
+
# Per altri URL, applica la doppia decodifica completa
|
66 |
+
url = unquote(unquote(url))
|
67 |
+
print(f"URL con doppia decodifica: {url}")
|
68 |
+
|
69 |
+
# Separa l'URL base dai parametri degli header
|
70 |
+
url_parts = url.split('&h_', 1)
|
71 |
+
clean_url = url_parts[0]
|
72 |
+
header_params = '&h_' + url_parts[1]
|
73 |
+
|
74 |
+
# Estrai gli header dai parametri
|
75 |
+
for param in header_params.split('&'):
|
76 |
+
if param.startswith('h_'):
|
77 |
+
try:
|
78 |
+
key_value = param[2:].split('=', 1)
|
79 |
+
if len(key_value) == 2:
|
80 |
+
key = unquote(key_value[0]).replace('_', '-')
|
81 |
+
value = unquote(key_value[1])
|
82 |
+
extracted_headers[key] = value
|
83 |
+
print(f"Header estratto: {key} = {value}")
|
84 |
+
except Exception as e:
|
85 |
+
print(f"Errore nell'estrazione dell'header {param}: {e}")
|
86 |
+
|
87 |
+
# Combina gli header estratti con quelli esistenti
|
88 |
+
current_headers.update(extracted_headers)
|
89 |
+
print(f"URL pulito: {clean_url}")
|
90 |
+
print(f"Header finali: {current_headers}")
|
91 |
+
else:
|
92 |
+
print("URL pulito rilevato - Nessuna estrazione header necessaria")
|
93 |
+
|
94 |
+
# New logic for thedaddy.click .php URLs
|
95 |
+
if clean_url.endswith('.php'):
|
96 |
+
print(f"Rilevato URL .php {clean_url}")
|
97 |
+
channel_id_match = re.search(r'stream-(\d+)\.php', clean_url)
|
98 |
+
if channel_id_match:
|
99 |
+
channel_id = channel_id_match.group(1)
|
100 |
+
print(f"Channel ID estratto: {channel_id}")
|
101 |
+
|
102 |
+
newkso_headers_for_php_resolution = {
|
103 |
+
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1',
|
104 |
+
'Referer': 'https://forcedtoplay.xyz/',
|
105 |
+
'Origin': 'https://forcedtoplay.xyz/'
|
106 |
+
}
|
107 |
+
|
108 |
+
# Handle Tennis Channels (ID starts with 15 and length 4)
|
109 |
+
if channel_id.startswith("15") and len(channel_id) == 4:
|
110 |
+
tennis_suffix = channel_id[2:]
|
111 |
+
folder_name = f"wikiten{tennis_suffix}"
|
112 |
+
test_url = f"https://new.newkso.ru/wikihz/{folder_name}/mono.m3u8"
|
113 |
+
print(f"Tentativo canale Tennis: {test_url}")
|
114 |
+
try:
|
115 |
+
response = requests.head(test_url, headers=newkso_headers_for_php_resolution, timeout=2.5, allow_redirects=True)
|
116 |
+
if response.status_code == 200:
|
117 |
+
print(f"Stream Tennis trovato: {test_url}")
|
118 |
+
return {"resolved_url": test_url, "headers": newkso_headers_for_php_resolution}
|
119 |
+
except requests.RequestException as e:
|
120 |
+
print(f"Errore HEAD per Tennis stream {test_url}: {e}")
|
121 |
+
|
122 |
+
# Handle Other Daddy Channels
|
123 |
+
else:
|
124 |
+
folder_name = f"premium{channel_id}"
|
125 |
+
for site in daddy_php_sites:
|
126 |
+
test_url = f"{site}{folder_name}/mono.m3u8"
|
127 |
+
print(f"Tentativo canale Daddy: {test_url}")
|
128 |
+
try:
|
129 |
+
response = requests.head(test_url, headers=newkso_headers_for_php_resolution, timeout=2.5, allow_redirects=True)
|
130 |
+
if response.status_code == 200:
|
131 |
+
print(f"Stream Daddy trovato: {test_url}")
|
132 |
+
return {"resolved_url": test_url, "headers": newkso_headers_for_php_resolution}
|
133 |
+
except requests.RequestException as e:
|
134 |
+
print(f"Errore HEAD per Daddy stream {test_url}: {e}")
|
135 |
+
|
136 |
+
print(f"Nessuno stream diretto .m3u8 trovato nei siti newkso.ru per {clean_url}. Si procederà con la logica di fallback se applicabile.")
|
137 |
+
# If no specific newkso.ru stream is found for the .php URL,
|
138 |
+
# we will let it fall through to the generic M3U8 resolution logic below.
|
139 |
+
# The generic logic will attempt to fetch clean_url (the .php URL).
|
140 |
+
# If that .php page itself returns M3U8 content, it will be processed.
|
141 |
+
# Otherwise, it will likely be treated as non-M3U8 content by proxy_m3u.
|
142 |
+
|
143 |
+
initial_response_text = None
|
144 |
+
final_url_after_redirects = None
|
145 |
+
|
146 |
+
# La logica iframe è stata rimossa come richiesto.
|
147 |
+
|
148 |
+
try:
|
149 |
+
with requests.Session() as session:
|
150 |
+
print(f"Passo 1: Richiesta a {clean_url}")
|
151 |
+
response = session.get(clean_url, headers=current_headers, allow_redirects=True, timeout=(5, 15))
|
152 |
+
response.raise_for_status()
|
153 |
+
initial_response_text = response.text
|
154 |
+
final_url_after_redirects = response.url
|
155 |
+
print(f"Passo 1 completato. URL finale dopo redirect: {final_url_after_redirects}")
|
156 |
+
|
157 |
+
# Verifica se la risposta iniziale è un file M3U8 diretto
|
158 |
+
if initial_response_text and initial_response_text.strip().startswith('#EXTM3U'):
|
159 |
+
print("Trovato file M3U8 diretto.")
|
160 |
+
return {
|
161 |
+
"resolved_url": final_url_after_redirects,
|
162 |
+
"headers": current_headers
|
163 |
+
}
|
164 |
+
else:
|
165 |
+
print("La risposta iniziale non era un M3U8 diretto.")
|
166 |
+
return {
|
167 |
+
"resolved_url": clean_url,
|
168 |
+
"headers": current_headers
|
169 |
+
}
|
170 |
+
|
171 |
+
except requests.exceptions.RequestException as e:
|
172 |
+
print(f"Errore durante la richiesta HTTP iniziale: {e}")
|
173 |
+
return {"resolved_url": clean_url, "headers": current_headers}
|
174 |
+
except Exception as e:
|
175 |
+
print(f"Errore generico durante la risoluzione: {e}")
|
176 |
+
return {"resolved_url": clean_url, "headers": current_headers}
|
177 |
+
|
178 |
+
@app.route('/proxy')
|
179 |
+
def proxy():
|
180 |
+
"""Proxy per liste M3U che aggiunge automaticamente /proxy/m3u?url= con IP prima dei link"""
|
181 |
+
m3u_url = request.args.get('url', '').strip()
|
182 |
+
if not m3u_url:
|
183 |
+
return "Errore: Parametro 'url' mancante", 400
|
184 |
+
|
185 |
+
try:
|
186 |
+
# Ottieni l'IP del server
|
187 |
+
server_ip = request.host
|
188 |
+
|
189 |
+
# Scarica la lista M3U originale
|
190 |
+
response = requests.get(m3u_url, timeout=(10, 30)) # Timeout connessione 10s, lettura 30s
|
191 |
+
response.raise_for_status()
|
192 |
+
m3u_content = response.text
|
193 |
+
|
194 |
+
modified_lines = []
|
195 |
+
exthttp_headers_query_params = "" # Stringa per conservare gli header da #EXTHTTP
|
196 |
+
|
197 |
+
for line in m3u_content.splitlines():
|
198 |
+
line = line.strip()
|
199 |
+
if line.startswith('#EXTHTTP:'):
|
200 |
+
try:
|
201 |
+
# Estrai la parte JSON dalla riga #EXTHTTP:
|
202 |
+
json_str = line.split(':', 1)[1].strip()
|
203 |
+
headers_dict = json.loads(json_str)
|
204 |
+
|
205 |
+
# Costruisci la stringa dei parametri di query per gli header con doppia codifica
|
206 |
+
temp_params = []
|
207 |
+
for key, value in headers_dict.items():
|
208 |
+
# Doppia codifica: prima codifica normale, poi codifica di nuovo
|
209 |
+
encoded_key = quote(quote(key))
|
210 |
+
encoded_value = quote(quote(str(value)))
|
211 |
+
temp_params.append(f"h_{encoded_key}={encoded_value}")
|
212 |
+
|
213 |
+
if temp_params:
|
214 |
+
# Usa %26 invece di & come separatore per gli header
|
215 |
+
exthttp_headers_query_params = "%26" + "%26".join(temp_params)
|
216 |
+
else:
|
217 |
+
exthttp_headers_query_params = ""
|
218 |
+
except Exception as e:
|
219 |
+
print(f"Errore nel parsing di #EXTHTTP '{line}': {e}")
|
220 |
+
exthttp_headers_query_params = "" # Resetta in caso di errore
|
221 |
+
modified_lines.append(line) # Mantieni la riga #EXTHTTP originale
|
222 |
+
elif line and not line.startswith('#'):
|
223 |
+
# Questa è una riga di URL del flusso
|
224 |
+
# Verifica se è un URL di Pluto.tv e saltalo
|
225 |
+
if 'pluto.tv' in line.lower():
|
226 |
+
modified_lines.append(line) # Mantieni l'URL originale senza proxy
|
227 |
+
exthttp_headers_query_params = "" # Resetta gli header
|
228 |
+
else:
|
229 |
+
# Applica gli header #EXTHTTP se presenti e poi resettali
|
230 |
+
# Assicurati che l'URL sia completamente codificato, inclusi gli slash
|
231 |
+
encoded_line = quote(line, safe='')
|
232 |
+
modified_line = f"http://{server_ip}/proxy/m3u?url={encoded_line}{exthttp_headers_query_params}"
|
233 |
+
modified_lines.append(modified_line)
|
234 |
+
exthttp_headers_query_params = "" # Resetta gli header dopo averli usati
|
235 |
+
else:
|
236 |
+
# Mantieni invariate le altre righe di metadati o righe vuote
|
237 |
+
modified_lines.append(line)
|
238 |
+
|
239 |
+
modified_content = '\n'.join(modified_lines)
|
240 |
+
|
241 |
+
# Estrai il nome del file dall'URL originale
|
242 |
+
parsed_m3u_url = urlparse(m3u_url)
|
243 |
+
original_filename = os.path.basename(parsed_m3u_url.path)
|
244 |
+
|
245 |
+
return Response(modified_content, content_type="application/vnd.apple.mpegurl", headers={'Content-Disposition': f'attachment; filename="{original_filename}"'})
|
246 |
+
|
247 |
+
except requests.RequestException as e:
|
248 |
+
return f"Errore durante il download della lista M3U: {str(e)}", 500
|
249 |
+
except Exception as e:
|
250 |
+
return f"Errore generico: {str(e)}", 500
|
251 |
+
|
252 |
+
@app.route('/proxy/m3u')
|
253 |
+
def proxy_m3u():
|
254 |
+
"""Proxy per file M3U e M3U8 con supporto per entrambe le versioni di URL"""
|
255 |
+
m3u_url = request.args.get('url', '').strip()
|
256 |
+
if not m3u_url:
|
257 |
+
return "Errore: Parametro 'url' mancante", 400
|
258 |
+
|
259 |
+
default_headers = {
|
260 |
+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15",
|
261 |
+
"Referer": "https://vavoo.to/",
|
262 |
+
"Origin": "https://vavoo.to"
|
263 |
+
}
|
264 |
+
|
265 |
+
# Estrai gli header dalla richiesta (versione parametri query)
|
266 |
+
request_headers = {
|
267 |
+
unquote(key[2:]).replace("_", "-"): unquote(value).strip()
|
268 |
+
for key, value in request.args.items()
|
269 |
+
if key.lower().startswith("h_")
|
270 |
+
}
|
271 |
+
|
272 |
+
# Combina header di default con quelli della richiesta
|
273 |
+
headers = {**default_headers, **request_headers}
|
274 |
+
|
275 |
+
# --- Logica per trasformare l'URL se necessario ---
|
276 |
+
processed_url = m3u_url
|
277 |
+
|
278 |
+
# La logica specifica per thedaddy.click e URL premium è stata rimossa.
|
279 |
+
print(f"URL {processed_url} processato per la risoluzione.")
|
280 |
+
|
281 |
+
try:
|
282 |
+
print(f"Chiamata a resolve_m3u8_link per URL processato: {processed_url}")
|
283 |
+
result = resolve_m3u8_link(processed_url, headers)
|
284 |
+
|
285 |
+
if not result["resolved_url"]:
|
286 |
+
return "Errore: Impossibile risolvere l'URL in un M3U8 valido.", 500
|
287 |
+
|
288 |
+
resolved_url = result["resolved_url"]
|
289 |
+
current_headers_for_proxy = result["headers"]
|
290 |
+
|
291 |
+
print(f"Risoluzione completata. URL M3U8 finale: {resolved_url}")
|
292 |
+
|
293 |
+
# Fetchare il contenuto M3U8 effettivo dall'URL risolto
|
294 |
+
print(f"Fetching M3U8 content from resolved URL: {resolved_url}")
|
295 |
+
m3u_response = requests.get(resolved_url, headers=current_headers_for_proxy, allow_redirects=True, timeout=(10, 20)) # Timeout connessione 10s, lettura 20s
|
296 |
+
m3u_response.raise_for_status()
|
297 |
+
# Applica la codifica corretta
|
298 |
+
m3u_response.encoding = m3u_response.apparent_encoding or 'utf-8'
|
299 |
+
m3u_content = m3u_response.text
|
300 |
+
final_url = m3u_response.url
|
301 |
+
|
302 |
+
# Processa il contenuto M3U8
|
303 |
+
file_type = detect_m3u_type(m3u_content)
|
304 |
+
|
305 |
+
if file_type == "m3u":
|
306 |
+
return Response(m3u_content, content_type="application/vnd.apple.mpegurl; charset=utf-8")
|
307 |
+
|
308 |
+
# Processa contenuto M3U8
|
309 |
+
parsed_url = urlparse(final_url)
|
310 |
+
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path.rsplit('/', 1)[0]}/"
|
311 |
+
|
312 |
+
# Prepara la query degli header per segmenti/chiavi proxati
|
313 |
+
headers_query = "&".join([f"h_{quote(k)}={quote(v)}" for k, v in current_headers_for_proxy.items()])
|
314 |
+
|
315 |
+
modified_m3u8 = []
|
316 |
+
for line in m3u_content.splitlines():
|
317 |
+
line = line.strip()
|
318 |
+
if line.startswith("#EXT-X-KEY") and 'URI="' in line:
|
319 |
+
line = replace_key_uri(line, headers_query)
|
320 |
+
elif line and not line.startswith("#"):
|
321 |
+
segment_url = urljoin(base_url, line)
|
322 |
+
line = f"/proxy/ts?url={quote(segment_url)}&{headers_query}"
|
323 |
+
modified_m3u8.append(line)
|
324 |
+
|
325 |
+
modified_m3u8_content = "\n".join(modified_m3u8)
|
326 |
+
return Response(modified_m3u8_content, content_type="application/vnd.apple.mpegurl; charset=utf-8")
|
327 |
+
|
328 |
+
except requests.RequestException as e:
|
329 |
+
print(f"Errore durante il download o la risoluzione del file: {str(e)}")
|
330 |
+
return f"Errore durante il download o la risoluzione del file M3U/M3U8: {str(e)}", 500
|
331 |
+
except Exception as e:
|
332 |
+
print(f"Errore generico nella funzione proxy_m3u: {str(e)}")
|
333 |
+
return f"Errore generico durante l'elaborazione: {str(e)}", 500
|
334 |
+
|
335 |
+
@app.route('/proxy/ts')
|
336 |
+
def proxy_ts():
|
337 |
+
"""Proxy per segmenti .TS con headers personalizzati - SENZA CACHE"""
|
338 |
+
ts_url = request.args.get('url', '').strip()
|
339 |
+
if not ts_url:
|
340 |
+
return "Errore: Parametro 'url' mancante", 400
|
341 |
+
|
342 |
+
headers = {
|
343 |
+
unquote(key[2:]).replace("_", "-"): unquote(value).strip()
|
344 |
+
for key, value in request.args.items()
|
345 |
+
if key.lower().startswith("h_")
|
346 |
+
}
|
347 |
+
|
348 |
+
try:
|
349 |
+
# Stream diretto senza cache per evitare freezing
|
350 |
+
response = requests.get(ts_url, headers=headers, stream=True, allow_redirects=True, timeout=(10, 30)) # Timeout di connessione 10s, lettura 30s
|
351 |
+
response.raise_for_status()
|
352 |
+
|
353 |
+
def generate():
|
354 |
+
for chunk in response.iter_content(chunk_size=8192):
|
355 |
+
if chunk:
|
356 |
+
yield chunk
|
357 |
+
|
358 |
+
return Response(generate(), content_type="video/mp2t")
|
359 |
+
|
360 |
+
except requests.RequestException as e:
|
361 |
+
return f"Errore durante il download del segmento TS: {str(e)}", 500
|
362 |
+
|
363 |
+
@app.route('/proxy/key')
|
364 |
+
def proxy_key():
|
365 |
+
"""Proxy per la chiave AES-128 con header personalizzati"""
|
366 |
+
key_url = request.args.get('url', '').strip()
|
367 |
+
if not key_url:
|
368 |
+
return "Errore: Parametro 'url' mancante per la chiave", 400
|
369 |
+
|
370 |
+
headers = {
|
371 |
+
unquote(key[2:]).replace("_", "-"): unquote(value).strip()
|
372 |
+
for key, value in request.args.items()
|
373 |
+
if key.lower().startswith("h_")
|
374 |
+
}
|
375 |
+
|
376 |
+
try:
|
377 |
+
response = requests.get(key_url, headers=headers, allow_redirects=True, timeout=(5, 15)) # Timeout connessione 5s, lettura 15s
|
378 |
+
response.raise_for_status()
|
379 |
+
|
380 |
+
return Response(response.content, content_type="application/octet-stream")
|
381 |
+
|
382 |
+
except requests.RequestException as e:
|
383 |
+
return f"Errore durante il download della chiave: {str(e)}", 500
|
384 |
+
|
385 |
+
@app.route('/')
|
386 |
+
def index():
|
387 |
+
"""Pagina principale che mostra un messaggio di benvenuto"""
|
388 |
+
return "Proxy started!"
|
389 |
+
|
390 |
+
if __name__ == '__main__':
|
391 |
+
app.run(host="0.0.0.0", port=7860, debug=False)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
flask
|
2 |
+
requests
|
3 |
+
gunicorn[gevent]
|