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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
html_content = """<!DOCTYPE html>
|
| 2 |
+
<html lang='en'>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset='UTF-8'>
|
| 5 |
+
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
| 6 |
+
<title>WebTorrent Client</title>
|
| 7 |
+
<script src='https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js'></script>
|
| 8 |
+
<style>
|
| 9 |
+
body {
|
| 10 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 11 |
+
background-color: #f4f7f6;
|
| 12 |
+
margin: 0;
|
| 13 |
+
padding: 20px;
|
| 14 |
+
display: flex;
|
| 15 |
+
flex-direction: column;
|
| 16 |
+
align-items: center;
|
| 17 |
+
}
|
| 18 |
+
.container {
|
| 19 |
+
background-color: white;
|
| 20 |
+
padding: 30px;
|
| 21 |
+
border-radius: 10px;
|
| 22 |
+
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
| 23 |
+
max-width: 600px;
|
| 24 |
+
width: 100%;
|
| 25 |
+
}
|
| 26 |
+
h1 {
|
| 27 |
+
color: #2c3e50;
|
| 28 |
+
text-align: center;
|
| 29 |
+
margin-top: 0;
|
| 30 |
+
}
|
| 31 |
+
.drop-zone {
|
| 32 |
+
border: 2px dashed #3498db;
|
| 33 |
+
padding: 30px;
|
| 34 |
+
text-align: center;
|
| 35 |
+
border-radius: 5px;
|
| 36 |
+
cursor: pointer;
|
| 37 |
+
background-color: #ecf0f1;
|
| 38 |
+
transition: background 0.3s;
|
| 39 |
+
margin-bottom: 20px;
|
| 40 |
+
}
|
| 41 |
+
.drop-zone:hover {
|
| 42 |
+
background-color: #e2e7e9;
|
| 43 |
+
}
|
| 44 |
+
#status {
|
| 45 |
+
font-weight: bold;
|
| 46 |
+
margin-bottom: 10px;
|
| 47 |
+
color: #7f8c8d;
|
| 48 |
+
}
|
| 49 |
+
.progress-bar {
|
| 50 |
+
width: 100%;
|
| 51 |
+
background-color: #e0e0e0;
|
| 52 |
+
border-radius: 25px;
|
| 53 |
+
overflow: hidden;
|
| 54 |
+
margin-bottom: 20px;
|
| 55 |
+
display: none;
|
| 56 |
+
}
|
| 57 |
+
.progress-fill {
|
| 58 |
+
height: 20px;
|
| 59 |
+
width: 0%;
|
| 60 |
+
background-color: #2ecc71;
|
| 61 |
+
transition: width 0.1s;
|
| 62 |
+
}
|
| 63 |
+
#file-list {
|
| 64 |
+
list-style-type: none;
|
| 65 |
+
padding: 0;
|
| 66 |
+
}
|
| 67 |
+
#file-list li {
|
| 68 |
+
padding: 10px;
|
| 69 |
+
background-color: #f9f9f9;
|
| 70 |
+
border: 1px solid #eee;
|
| 71 |
+
margin-bottom: 5px;
|
| 72 |
+
border-radius: 3px;
|
| 73 |
+
display: flex;
|
| 74 |
+
justify-content: space-between;
|
| 75 |
+
align-items: center;
|
| 76 |
+
}
|
| 77 |
+
.download-btn {
|
| 78 |
+
background-color: #3498db;
|
| 79 |
+
color: white;
|
| 80 |
+
border: none;
|
| 81 |
+
padding: 5px 10px;
|
| 82 |
+
border-radius: 3px;
|
| 83 |
+
cursor: pointer;
|
| 84 |
+
text-decoration: none;
|
| 85 |
+
}
|
| 86 |
+
</style>
|
| 87 |
+
</head>
|
| 88 |
+
<body>
|
| 89 |
+
<div class='container'>
|
| 90 |
+
<h1>HTML5 Torrent Downloader</h1>
|
| 91 |
+
<div class='drop-zone' id='drop-zone'>
|
| 92 |
+
Drop your <b>.torrent</b> file here, or click to upload.
|
| 93 |
+
<input type='file' id='file-input' style='display: none;'>
|
| 94 |
+
</div>
|
| 95 |
+
<div id='status'>Waiting for torrent file...</div>
|
| 96 |
+
<div class='progress-bar' id='progress-bar'>
|
| 97 |
+
<div class='progress-fill' id='progress-fill'></div>
|
| 98 |
+
</div>
|
| 99 |
+
<ul id='file-list'></ul>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
<script>
|
| 103 |
+
const client = new WebTorrent();
|
| 104 |
+
const dropZone = document.getElementById('drop-zone');
|
| 105 |
+
const fileInput = document.getElementById('file-input');
|
| 106 |
+
const statusText = document.getElementById('status');
|
| 107 |
+
const progressBar = document.getElementById('progress-bar');
|
| 108 |
+
const progressFill = document.getElementById('progress-fill');
|
| 109 |
+
const fileList = document.getElementById('file-list');
|
| 110 |
+
|
| 111 |
+
dropZone.addEventListener('click', () => fileInput.click());
|
| 112 |
+
|
| 113 |
+
fileInput.addEventListener('change', (e) => {
|
| 114 |
+
if (e.target.files.length) handleTorrent(e.target.files[0]);
|
| 115 |
+
});
|
| 116 |
+
|
| 117 |
+
dropZone.addEventListener('dragover', (e) => {
|
| 118 |
+
e.preventDefault();
|
| 119 |
+
dropZone.style.backgroundColor = '#d5dbdb';
|
| 120 |
+
});
|
| 121 |
+
|
| 122 |
+
dropZone.addEventListener('dragleave', () => {
|
| 123 |
+
dropZone.style.backgroundColor = '#ecf0f1';
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
dropZone.addEventListener('drop', (e) => {
|
| 127 |
+
e.preventDefault();
|
| 128 |
+
dropZone.style.backgroundColor = '#ecf0f1';
|
| 129 |
+
if (e.dataTransfer.files.length) handleTorrent(e.dataTransfer.files[0]);
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
function handleTorrent(file) {
|
| 133 |
+
statusText.innerText = 'Starting download...';
|
| 134 |
+
progressBar.style.display = 'block';
|
| 135 |
+
|
| 136 |
+
client.add(file, (torrent) => {
|
| 137 |
+
statusText.innerText = `Downloading: ${torrent.name}`;
|
| 138 |
+
|
| 139 |
+
torrent.files.forEach((file) => {
|
| 140 |
+
const li = document.createElement('li');
|
| 141 |
+
li.innerHTML = `<span>${file.name}</span>`;
|
| 142 |
+
fileList.appendChild(li);
|
| 143 |
+
|
| 144 |
+
file.getBlobURL((err, url) => {
|
| 145 |
+
if (err) return;
|
| 146 |
+
const a = document.createElement('a');
|
| 147 |
+
a.href = url;
|
| 148 |
+
a.download = file.name;
|
| 149 |
+
a.innerText = 'Save to Device';
|
| 150 |
+
a.className = 'download-btn';
|
| 151 |
+
li.appendChild(a);
|
| 152 |
+
});
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
torrent.on('download', (bytes) => {
|
| 156 |
+
const progress = (torrent.progress * 100).toFixed(1);
|
| 157 |
+
progressFill.style.width = progress + '%';
|
| 158 |
+
statusText.innerText = `Progress: ${progress}% | Speed: ${(torrent.downloadSpeed / 1024 / 1024).toFixed(2)} MB/s`;
|
| 159 |
+
});
|
| 160 |
+
|
| 161 |
+
torrent.on('done', () => {
|
| 162 |
+
statusText.innerText = 'Download complete! You can now save individual files below.';
|
| 163 |
+
});
|
| 164 |
+
});
|
| 165 |
+
}
|
| 166 |
+
</script>
|
| 167 |
+
</body>
|
| 168 |
+
</html>
|