352 lines
11 KiB
Python
352 lines
11 KiB
Python
"""
|
|
Script de test pour vérifier que le proxy fonctionne correctement
|
|
"""
|
|
import requests
|
|
import sys
|
|
import time
|
|
from urllib.parse import quote
|
|
|
|
# Configuration
|
|
PROXY_URL = "http://localhost:8080"
|
|
VIDEO_URL = "https://17.mugiwara.xyz/op/saga-7/hd/527.mp4"
|
|
|
|
|
|
def test_health():
|
|
"""Test 1: Vérifier que le serveur est démarré"""
|
|
print("\n" + "="*80)
|
|
print("TEST 1: Health Check")
|
|
print("="*80)
|
|
|
|
try:
|
|
response = requests.get(f"{PROXY_URL}/health", timeout=5)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print(f"✓ Serveur actif")
|
|
print(f" Service: {data.get('service')}")
|
|
print(f" Version: {data.get('version')}")
|
|
return True
|
|
else:
|
|
print(f"✗ Erreur: Status {response.status_code}")
|
|
return False
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print(f"✗ ERREUR: Impossible de se connecter au serveur")
|
|
print(f" Démarrez le serveur avec: python video_proxy_server.py")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Erreur: {str(e)}")
|
|
return False
|
|
|
|
|
|
def test_info():
|
|
"""Test 2: Récupérer les informations de la vidéo"""
|
|
print("\n" + "="*80)
|
|
print("TEST 2: Video Info")
|
|
print("="*80)
|
|
|
|
try:
|
|
url = f"{PROXY_URL}/info?url={quote(VIDEO_URL)}"
|
|
print(f"Requête: {url}")
|
|
|
|
response = requests.get(url, timeout=10)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
|
|
print(f"\n✓ Informations récupérées:")
|
|
print(f" URL : {data.get('url')}")
|
|
print(f" Accessible : {data.get('accessible')}")
|
|
print(f" Status Code : {data.get('status_code')}")
|
|
print(f" Content-Type : {data.get('content_type')}")
|
|
print(f" Taille : {data.get('content_length_mb')} MB")
|
|
print(f" Serveur : {data.get('server')}")
|
|
|
|
return data.get('accessible', False)
|
|
else:
|
|
print(f"✗ Erreur: Status {response.status_code}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Erreur: {str(e)}")
|
|
return False
|
|
|
|
|
|
def test_streaming():
|
|
"""Test 3: Tester le streaming (premiers bytes)"""
|
|
print("\n" + "="*80)
|
|
print("TEST 3: Video Streaming")
|
|
print("="*80)
|
|
|
|
try:
|
|
url = f"{PROXY_URL}/proxy?url={quote(VIDEO_URL)}"
|
|
print(f"Requête: {url}")
|
|
print(f"Téléchargement des premiers 1 MB...")
|
|
|
|
response = requests.get(url, stream=True, timeout=30)
|
|
|
|
if response.status_code in [200, 206]:
|
|
# Télécharger seulement 1 MB pour tester
|
|
chunk_count = 0
|
|
max_chunks = 128 # 128 chunks de 8KB = 1 MB
|
|
|
|
start_time = time.time()
|
|
|
|
for chunk in response.iter_content(chunk_size=8192):
|
|
if chunk:
|
|
chunk_count += 1
|
|
if chunk_count >= max_chunks:
|
|
break
|
|
|
|
elapsed = time.time() - start_time
|
|
downloaded_mb = (chunk_count * 8192) / (1024 * 1024)
|
|
speed_mbps = (downloaded_mb / elapsed) if elapsed > 0 else 0
|
|
|
|
print(f"\n✓ Streaming fonctionne!")
|
|
print(f" Téléchargé : {downloaded_mb:.2f} MB")
|
|
print(f" Temps : {elapsed:.2f} secondes")
|
|
print(f" Vitesse : {speed_mbps:.2f} MB/s")
|
|
print(f" Status : {response.status_code}")
|
|
print(f" Content-Type : {response.headers.get('Content-Type')}")
|
|
|
|
return True
|
|
else:
|
|
print(f"✗ Erreur: Status {response.status_code}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Erreur: {str(e)}")
|
|
return False
|
|
|
|
|
|
def test_range_request():
|
|
"""Test 4: Tester les Range requests (seeking)"""
|
|
print("\n" + "="*80)
|
|
print("TEST 4: Range Request (Seeking)")
|
|
print("="*80)
|
|
|
|
try:
|
|
url = f"{PROXY_URL}/proxy?url={quote(VIDEO_URL)}"
|
|
|
|
# Demander seulement 100KB depuis le milieu de la vidéo
|
|
headers = {
|
|
'Range': 'bytes=10000000-10100000'
|
|
}
|
|
|
|
print(f"Requête avec Range: {headers['Range']}")
|
|
|
|
response = requests.get(url, headers=headers, timeout=10)
|
|
|
|
if response.status_code == 206: # 206 Partial Content
|
|
content_range = response.headers.get('Content-Range')
|
|
content_length = len(response.content)
|
|
|
|
print(f"\n✓ Range request fonctionne!")
|
|
print(f" Status : {response.status_code} Partial Content")
|
|
print(f" Content-Range : {content_range}")
|
|
print(f" Taille reçue : {content_length / 1024:.2f} KB")
|
|
|
|
return True
|
|
else:
|
|
print(f"⚠️ Range request non supporté (Status: {response.status_code})")
|
|
print(f" Le seeking dans la vidéo peut ne pas fonctionner")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Erreur: {str(e)}")
|
|
return False
|
|
|
|
|
|
def test_direct_access():
|
|
"""Test 5: Vérifier que l'accès direct échoue toujours"""
|
|
print("\n" + "="*80)
|
|
print("TEST 5: Direct Access (doit échouer)")
|
|
print("="*80)
|
|
|
|
try:
|
|
print(f"Tentative d'accès direct à: {VIDEO_URL}")
|
|
|
|
# Accès sans le Referer correct
|
|
response = requests.head(VIDEO_URL, timeout=10)
|
|
|
|
if response.status_code == 403:
|
|
print(f"\n✓ Comportement attendu: 403 Forbidden")
|
|
print(f" Le serveur protège bien ses vidéos")
|
|
return True
|
|
else:
|
|
print(f"⚠️ Status inattendu: {response.status_code}")
|
|
print(f" La protection peut avoir changé")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Erreur: {str(e)}")
|
|
return False
|
|
|
|
|
|
def generate_test_html():
|
|
"""Génère une page HTML de test"""
|
|
print("\n" + "="*80)
|
|
print("GÉNÉRATION DE LA PAGE DE TEST")
|
|
print("="*80)
|
|
|
|
proxy_url = f"{PROXY_URL}/proxy?url={quote(VIDEO_URL)}"
|
|
|
|
html = f"""<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Test Proxy Vidéo - One Piece 527</title>
|
|
<meta charset="UTF-8">
|
|
<style>
|
|
body {{
|
|
font-family: Arial, sans-serif;
|
|
max-width: 1200px;
|
|
margin: 50px auto;
|
|
padding: 20px;
|
|
background: #f5f5f5;
|
|
}}
|
|
h1 {{
|
|
color: #333;
|
|
text-align: center;
|
|
}}
|
|
.video-container {{
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
margin: 30px 0;
|
|
}}
|
|
video {{
|
|
width: 100%;
|
|
max-width: 1280px;
|
|
height: auto;
|
|
border-radius: 5px;
|
|
}}
|
|
.info {{
|
|
background: #e8f4f8;
|
|
padding: 15px;
|
|
border-left: 4px solid #0066cc;
|
|
margin: 20px 0;
|
|
}}
|
|
code {{
|
|
background: #f4f4f4;
|
|
padding: 2px 6px;
|
|
border-radius: 3px;
|
|
font-family: 'Courier New', monospace;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>🎬 Test Proxy Vidéo - One Piece Episode 527</h1>
|
|
|
|
<div class="video-container">
|
|
<video controls preload="metadata">
|
|
<source src="{proxy_url}" type="video/mp4">
|
|
Votre navigateur ne supporte pas la balise vidéo HTML5.
|
|
</video>
|
|
</div>
|
|
|
|
<div class="info">
|
|
<strong>URL Proxy:</strong><br>
|
|
<code>{proxy_url}</code>
|
|
</div>
|
|
|
|
<div class="info">
|
|
<strong>URL Vidéo Originale:</strong><br>
|
|
<code>{VIDEO_URL}</code>
|
|
</div>
|
|
|
|
<div class="info">
|
|
<strong>📝 Instructions:</strong>
|
|
<ul>
|
|
<li>La vidéo devrait se charger et être lisible</li>
|
|
<li>Vous devriez pouvoir seek (avancer/reculer)</li>
|
|
<li>Le volume et les contrôles devraient fonctionner</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="info">
|
|
<strong>🔧 Si la vidéo ne se charge pas:</strong>
|
|
<ol>
|
|
<li>Vérifiez que le serveur proxy est démarré</li>
|
|
<li>Ouvrez la console développeur (F12) pour voir les erreurs</li>
|
|
<li>Testez l'URL proxy directement dans un nouvel onglet</li>
|
|
</ol>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
with open("test_video_player.html", "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
|
|
print(f"\n✓ Page HTML générée: test_video_player.html")
|
|
print(f"\n🌐 Ouvrez ce fichier dans votre navigateur pour tester la lecture!")
|
|
print(f" Ou visitez: http://localhost:8080/ pour la page d'accueil du proxy")
|
|
|
|
|
|
def main():
|
|
"""Exécuter tous les tests"""
|
|
print("\n")
|
|
print("╔" + "="*78 + "╗")
|
|
print("║" + " "*25 + "TESTS DU PROXY VIDÉO" + " "*33 + "║")
|
|
print("╚" + "="*78 + "╝")
|
|
|
|
tests = [
|
|
("Health Check", test_health),
|
|
("Video Info", test_info),
|
|
("Streaming", test_streaming),
|
|
("Range Request", test_range_request),
|
|
("Direct Access", test_direct_access),
|
|
]
|
|
|
|
results = []
|
|
|
|
for test_name, test_func in tests:
|
|
try:
|
|
result = test_func()
|
|
results.append((test_name, result))
|
|
except Exception as e:
|
|
print(f"\n✗ Erreur inattendue: {str(e)}")
|
|
results.append((test_name, False))
|
|
|
|
# Générer la page HTML de test
|
|
generate_test_html()
|
|
|
|
# Résumé
|
|
print("\n" + "="*80)
|
|
print("RÉSUMÉ DES TESTS")
|
|
print("="*80)
|
|
|
|
passed = sum(1 for _, result in results if result)
|
|
total = len(results)
|
|
|
|
for test_name, result in results:
|
|
status = "✓ PASS" if result else "✗ FAIL"
|
|
print(f" {status} {test_name}")
|
|
|
|
print(f"\nRésultat: {passed}/{total} tests réussis")
|
|
|
|
if passed == total:
|
|
print("\n🎉 Tous les tests sont passés! Le proxy fonctionne parfaitement.")
|
|
print("\n📝 Prochaines étapes:")
|
|
print(" 1. Ouvrir test_video_player.html dans votre navigateur")
|
|
print(" 2. Vérifier que la vidéo se lit correctement")
|
|
print(" 3. Déployer sur votre VPS si nécessaire (voir PROXY_GUIDE.md)")
|
|
else:
|
|
print("\n⚠️ Certains tests ont échoué. Vérifiez les erreurs ci-dessus.")
|
|
print("\n💡 Conseils:")
|
|
if not results[0][1]: # Health check failed
|
|
print(" - Le serveur n'est pas démarré: python video_proxy_server.py")
|
|
else:
|
|
print(" - Consultez les logs dans logs/")
|
|
print(" - Vérifiez que l'URL de la vidéo est correcte")
|
|
|
|
print("\n" + "="*80 + "\n")
|
|
|
|
sys.exit(0 if passed == total else 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|