Spaces:
Building
Building
<!-- index.html --> | |
<html> | |
<head> | |
<title>TorrentGalaxy Streamer</title> | |
<style> | |
body { font-family: Arial, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; } | |
.search-section, .player-section { margin-bottom: 30px; } | |
#results { margin-top: 20px; } | |
.torrent-item { padding: 10px; border-bottom: 1px solid #ddd; cursor: pointer; } | |
.torrent-item:hover { background: #f5f5f5; } | |
#player { width: 100%; height: 500px; } | |
</style> | |
</head> | |
<body> | |
<div class="search-section"> | |
<h1>TorrentGalaxy Streamer</h1> | |
<input type="text" id="searchInput" placeholder="Search TorrentGalaxy..."> | |
<button onclick="searchTorrents()">Search</button> | |
<div id="results"></div> | |
</div> | |
<div class="player-section"> | |
<video id="player" controls></video> | |
</div> | |
<script> | |
async function searchTorrents() { | |
const query = document.getElementById('searchInput').value; | |
const results = document.getElementById('results'); | |
results.innerHTML = 'Loading...'; | |
try { | |
const response = await fetch(`/search?q=${encodeURIComponent(query)}`); | |
const torrents = await response.json(); | |
results.innerHTML = torrents.map(t => ` | |
<div class="torrent-item" onclick="startStream('${t.magnet}')"> | |
<strong>${t.title}</strong><br> | |
<small>Size: ${t.size} | Seeds: ${t.seeds}</small> | |
</div> | |
`).join(''); | |
} catch (error) { | |
results.innerHTML = 'Error loading results'; | |
} | |
} | |
async function startStream(magnet) { | |
try { | |
// Start the stream | |
const startResp = await fetch('/start_stream', { | |
method: 'POST', | |
headers: {'Content-Type': 'application/json'}, | |
body: JSON.stringify({ magnet_link: magnet }) | |
}); | |
const { stream_url } = await startResp.json(); | |
// Get MIME type and set up player | |
const mimeResp = await fetch(`${stream_url}/mime`); | |
const { mime_type } = await mimeResp.json(); | |
// Set up video player | |
const player = document.getElementById('player'); | |
player.src = stream_url; | |
player.type = mime_type; | |
player.load(); | |
player.play(); | |
} catch (error) { | |
alert('Error starting stream: ' + error.message); | |
} | |
} | |
</script> | |
</body> | |
</html> |