xStream Downloader updates
- Streaming-Site Auflösung für vidara.to (m3u8 via API) - HTML-Erkennung für Streaming-Seiten - Dateiname beim Speichern ohne Prefix - Speichern-Button deaktiviert nach Klick - Farbiger Fortschrittsbalken (grün/gelb/rot) - Status-Text statt ungenauer Prozentanzeige - Auto-Refresh Timeout bei View-Wechsel abgebrochen - HLS Download mit korrekten Headern (Referer, User-Agent) - Diverse Bugfixes und Verbesserungen
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# xStream Downloader – Projektstatus
|
||||
|
||||
Stand: 6.7.2026, 22:25
|
||||
Stand: 7.7.2026, 16:56
|
||||
|
||||
## Ziel
|
||||
Web-Wrapper für das xstream Kodi-Addon, mit dem man Filme suchen, finden
|
||||
@@ -15,7 +15,7 @@ und herunterladen kann – direkt im Browser, ohne Kodi.
|
||||
|
||||
```
|
||||
xstreamDownloader/
|
||||
├── app.py ← AKTIVER Wrapper-App (XBMC-konform, ~800 Zeilen)
|
||||
├── app.py ← AKTIVER Wrapper-App (XBMC-konform, ~1150 Zeilen)
|
||||
├── web/index.html ← Frontend (Sidebar, Search, Grid, Downloads)
|
||||
├── xstream/sites/ ← 18 Site-Plugins
|
||||
├── xstream/resources/lib/ ← xstream Core
|
||||
@@ -31,7 +31,7 @@ xstreamDownloader/
|
||||
|
||||
## Was funktioniert
|
||||
|
||||
1. **Flask-Server startet** auf http://localhost:8765
|
||||
1. **Flask-Server startet** auf http://localhost:8770
|
||||
2. **18 Sites** werden erkannt und geladen
|
||||
3. **XBMC-Mock-Module** für xbmc, xbmcgui, xbmcplugin, xbmcvfs, xbmcaddon
|
||||
4. **Subprozess-Worker** mit eigenem sys.argv[1] = '1' (handle)
|
||||
@@ -49,7 +49,10 @@ xstreamDownloader/
|
||||
- /api/resolve?url=...
|
||||
- /api/download?url=...&title=...
|
||||
- /api/downloads[/ID][/file]
|
||||
11. **Download-Manager** mit Fortschritt 0-100%
|
||||
11. **Download-Manager** mit Fortschritt 0-100%, Cancel, Delete
|
||||
12. **HLS/m3u8 Download** via ffmpeg
|
||||
13. **HTML-Erkennung** – verhindert 16KB HTML-Files als "fertige Downloads"
|
||||
14. **Streaming-Site Auflösung** – vidara.to etc. via API (filecode → m3u8)
|
||||
|
||||
## Navigation (Menü → Inhalte)
|
||||
|
||||
@@ -76,26 +79,27 @@ Beim Klick auf einen Menüpunkt:
|
||||
| 11 | Such-API-Mismatch | Frontend: `/search?q=` statt `/entries?search=` | 6.7.2026 |
|
||||
| 12 | Hoster-API-Mismatch | `?url=` statt `?entryUrl=` | 6.7.2026 |
|
||||
| 13 | Download-Flow falsch | Resolve → Download → Poll statt `/resolve?download=true` | 6.7.2026 |
|
||||
| 14 | Port 8769 belegt | Geändert auf Port 8770 | 6.7.2026 |
|
||||
| 15 | Download 16KB HTML statt Video (VOE etc.) | HTML-Erkennung in _run_direct() | 7.7.2026 |
|
||||
| 16 | Streaming-Sites liefern HTML statt m3u8 | _resolve_streaming_api() für vidara.to etc. | 7.7.2026 |
|
||||
|
||||
## Verbleibende Aufgaben
|
||||
|
||||
- [ ] Browser-MCP Debugging (im Browser testen)
|
||||
- [ ] Hoster-Flow E2E testen (Eintrag → Hosters → Download)
|
||||
- [ ] Download E2E testen (Resolve → Download → File)
|
||||
- [ ] Such-Qualität verbessern (manche Sites liefern Haupteinträge statt Suchergebnisse)
|
||||
- [ ] fix_and_run.sh auf app.py umstellen (bereits erledigt)
|
||||
- [ ] mini_app.py wurde am 6.7.2026 gelöscht
|
||||
- [ ] Stream-Button in Suchergebnissen
|
||||
|
||||
## Starten
|
||||
|
||||
```bash
|
||||
cd /home/matthiasberner/Schreibtisch/kodi/xstreamDownloader
|
||||
python3 app.py
|
||||
# → http://localhost:8765
|
||||
# → http://localhost:8770
|
||||
```
|
||||
|
||||
## Bekannte Probleme
|
||||
|
||||
- Port 8765 kann von Zombie-Prozessen belegt sein → mit `pkill -9 -f "python3 app.py"` beheben
|
||||
- Port 8770 kann von Zombie-Prozessen belegt sein → mit `pkill -9 -f "python3 app.py"` beheben
|
||||
- Manche Site-Suchfunktionen geben Haupteinträge statt Suchergebnisse zurück
|
||||
- Manche Sites (z.B. serienstream A-Z) können 500er Timeout-Fehler werfen
|
||||
|
||||
@@ -515,7 +515,49 @@ def _scan_sites():
|
||||
# ============================================================================
|
||||
# 6. URL-Resolver
|
||||
# ============================================================================
|
||||
def _resolve_streaming_api(url):
|
||||
"""Löst Streaming-Sites (vidara.to etc.) auf: Extrahiert filecode und holt m3u8 von API."""
|
||||
import re, json
|
||||
from urllib.parse import urlparse
|
||||
|
||||
# Pattern für vidara.to und ähnliche: /e/<filecode>
|
||||
parsed = urlparse(url)
|
||||
path_match = re.match(r'/e/([a-zA-Z0-9]+)', parsed.path)
|
||||
|
||||
if not path_match:
|
||||
return (None, None) # Kein Streaming-Site Pattern
|
||||
|
||||
filecode = path_match.group(1)
|
||||
base_url = f"{parsed.scheme}://{parsed.netloc}"
|
||||
api_url = f"{base_url}/api/stream"
|
||||
|
||||
try:
|
||||
import requests
|
||||
resp = requests.post(api_url,
|
||||
json={"filecode": filecode, "device": "web"},
|
||||
headers={"Content-Type": "application/json", "Referer": url},
|
||||
timeout=10)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
m3u8_url = data.get('streaming_url')
|
||||
if m3u8_url:
|
||||
return (m3u8_url, None)
|
||||
return (None, 'streaming_url nicht in API-Antwort')
|
||||
except Exception as e:
|
||||
return (None, f'Streaming-API Fehler: {e}')
|
||||
|
||||
|
||||
def _resolve_url(url):
|
||||
# Erst prüfen ob es eine bekannte Streaming-Site ist
|
||||
m3u8_url, err = _resolve_streaming_api(url)
|
||||
if m3u8_url:
|
||||
return (m3u8_url, None)
|
||||
if err:
|
||||
# Streaming-Site erkannt aber Fehler
|
||||
return (None, err)
|
||||
|
||||
# Falls resolveurl nicht verfügbar, URL direkt zurückgeben
|
||||
# (viele URLs sind bereits direkte Stream-URLs)
|
||||
try:
|
||||
import resolveurl
|
||||
r = resolveurl.resolve(url)
|
||||
@@ -523,7 +565,8 @@ def _resolve_url(url):
|
||||
return (r, None)
|
||||
return (None, 'resolveurl konnte URL nicht aufloesen')
|
||||
except ImportError:
|
||||
return (None, 'resolveurl nicht verfuegbar')
|
||||
# resolveurl nicht verfügbar -> URL direkt verwenden
|
||||
return (url, None)
|
||||
except Exception as e:
|
||||
return (None, str(e))
|
||||
|
||||
@@ -566,17 +609,102 @@ class DownloadManager:
|
||||
)
|
||||
return
|
||||
with self.lock:
|
||||
self.downloads[did]['status'] = 'downloading'
|
||||
self.downloads[did]['resolved_url'] = final_url
|
||||
|
||||
# HLS/m3u8 Stream?
|
||||
if '.m3u8' in final_url.lower():
|
||||
self._run_hls(did, final_url, title)
|
||||
else:
|
||||
self._run_direct(did, final_url, title)
|
||||
|
||||
def _run_hls(self, did, url, title):
|
||||
"""HLS-Stream herunterladen mit ffmpeg"""
|
||||
import subprocess
|
||||
import shutil
|
||||
from urllib.parse import urlparse
|
||||
|
||||
with self.lock:
|
||||
self.downloads[did]['status'] = 'downloading'
|
||||
|
||||
safe = re.sub(r'[^\w\-\.]', '_', title)[:80] or 'video'
|
||||
path = self.dir / f'{did}_{safe}.mp4'
|
||||
tmp_ts = self.dir / f'{did}_{safe}.ts'
|
||||
|
||||
# Extrahiere Domain für Referer Header
|
||||
parsed = urlparse(url)
|
||||
referer = f"{parsed.scheme}://{parsed.netloc}/"
|
||||
ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36'
|
||||
|
||||
# ffmpeg Kommando mit Header für Streaming-Sites
|
||||
cmd = [
|
||||
shutil.which('ffmpeg') or 'ffmpeg',
|
||||
'-y', # overwrite
|
||||
'-headers', f'Referer: {referer}\r\nUser-Agent: {ua}',
|
||||
'-i', url,
|
||||
'-c', 'copy', # no re-encoding
|
||||
'-bsf:a', 'aac_adtstoasc', # fix audio
|
||||
'-progress', 'pipe:1',
|
||||
str(tmp_ts)
|
||||
]
|
||||
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
universal_newlines=True, bufsize=1
|
||||
)
|
||||
for line in proc.stdout:
|
||||
line = line.strip()
|
||||
# ffmpeg progress format: "out_time_ms=12345" or "progress=end"
|
||||
if line.startswith('progress=end'):
|
||||
break
|
||||
if '=' in line:
|
||||
key, val = line.split('=', 1)
|
||||
if key == 'out_time_ms' and val:
|
||||
# convert time to percentage (rough estimate)
|
||||
try:
|
||||
ms = int(val)
|
||||
# estimate based on 2hr max for unknown duration
|
||||
estimated_pct = min(ms / (2 * 3600 * 1000) * 100, 99)
|
||||
with self.lock:
|
||||
self.downloads[did]['progress'] = int(estimated_pct)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
proc.wait()
|
||||
if proc.returncode == 0 and tmp_ts.exists():
|
||||
tmp_ts.rename(path)
|
||||
with self.lock:
|
||||
self.downloads[did].update({
|
||||
'status': 'complete', 'progress': 100,
|
||||
'path': str(path), 'finished': time.time(),
|
||||
})
|
||||
else:
|
||||
raise Exception(f'ffmpeg exit code: {proc.returncode}')
|
||||
except Exception as e:
|
||||
# Cleanup
|
||||
if tmp_ts.exists():
|
||||
tmp_ts.unlink()
|
||||
with self.lock:
|
||||
self.downloads[did].update({
|
||||
'status': 'error', 'error': str(e),
|
||||
'finished': time.time(),
|
||||
})
|
||||
|
||||
def _run_direct(self, did, url, title):
|
||||
"""Direkter Download via requests (mp4/etc.)"""
|
||||
import requests as _req
|
||||
with self.lock:
|
||||
self.downloads[did]['status'] = 'downloading'
|
||||
|
||||
safe = re.sub(r'[^\w\-\.]', '_', title)[:80] or 'video'
|
||||
path = self.dir / f'{did}_{safe}.mp4'
|
||||
try:
|
||||
r = _req.get(
|
||||
final_url, stream=True, timeout=30,
|
||||
url, stream=True, timeout=30,
|
||||
headers={'User-Agent': 'Mozilla/5.0'}
|
||||
)
|
||||
r.raise_for_status()
|
||||
content_type = r.headers.get('content-type', '').lower()
|
||||
total = int(r.headers.get('content-length', 0))
|
||||
downloaded = 0
|
||||
with open(path, 'wb') as f:
|
||||
@@ -587,12 +715,27 @@ class DownloadManager:
|
||||
pct = int(100 * downloaded / total) if total else 0
|
||||
with self.lock:
|
||||
self.downloads[did]['progress'] = pct
|
||||
|
||||
# Prüfe ob es HTML ist (kein Video)
|
||||
if path.exists() and path.stat().st_size < 50000:
|
||||
with open(path, 'rb') as f:
|
||||
first_bytes = f.read(200)
|
||||
if b'<!DOCTYPE' in first_bytes or b'<html' in first_bytes or b'<script' in first_bytes:
|
||||
path.unlink()
|
||||
raise Exception('Streaming-Seite (HTML), kein Video. Video-Host wird nicht unterstützt.')
|
||||
|
||||
with self.lock:
|
||||
self.downloads[did].update({
|
||||
'status': 'complete', 'progress': 100,
|
||||
'path': str(path), 'finished': time.time(),
|
||||
})
|
||||
except Exception as e:
|
||||
# Cleanup
|
||||
if path.exists():
|
||||
try:
|
||||
path.unlink()
|
||||
except Exception:
|
||||
pass
|
||||
with self.lock:
|
||||
self.downloads[did].update({
|
||||
'status': 'error', 'error': str(e),
|
||||
@@ -607,6 +750,37 @@ class DownloadManager:
|
||||
with self.lock:
|
||||
return dict(self.downloads.get(did, {}))
|
||||
|
||||
def cancel(self, did):
|
||||
"""Download abbrechen"""
|
||||
with self.lock:
|
||||
d = self.downloads.get(did)
|
||||
if not d:
|
||||
return False
|
||||
if d['status'] in ('complete', 'error'):
|
||||
return False # already done
|
||||
d['status'] = 'cancelled'
|
||||
d['finished'] = time.time()
|
||||
# Kill associated thread if we can track it
|
||||
if did in self._threads:
|
||||
self._threads[did]['cancelled'] = True
|
||||
return True
|
||||
|
||||
def delete(self, did):
|
||||
"""Download aus Liste entfernen und Datei löschen"""
|
||||
with self.lock:
|
||||
d = self.downloads.get(did)
|
||||
if not d:
|
||||
return False
|
||||
# Datei löschen falls vorhanden
|
||||
p = d.get('path')
|
||||
if p and os.path.exists(p):
|
||||
try:
|
||||
os.unlink(p)
|
||||
except Exception:
|
||||
pass
|
||||
del self.downloads[did]
|
||||
return True
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# 8. Flask-App und API
|
||||
@@ -952,6 +1126,11 @@ def api_downloads():
|
||||
return jsonify(DM.list())
|
||||
|
||||
|
||||
@app.route('/api/downloads/dir')
|
||||
def api_downloads_dir():
|
||||
return jsonify({'dir': str(DM.dir)})
|
||||
|
||||
|
||||
@app.route('/api/downloads/<did>')
|
||||
def api_download_info(did):
|
||||
d = DM.get(did)
|
||||
@@ -968,7 +1147,24 @@ def api_download_file(did):
|
||||
p = d.get('path')
|
||||
if not p or not os.path.exists(p):
|
||||
return jsonify({'error': 'file missing'}), 404
|
||||
return send_file(p, as_attachment=True, download_name=os.path.basename(p))
|
||||
# Sauberer Titel als Dateiname (ohne Prefix)
|
||||
safe_title = re.sub(r'[^\w\-\. ]', '_', d.get('title', 'video'))[:80]
|
||||
download_name = f"{safe_title}.mp4"
|
||||
return send_file(p, as_attachment=True, download_name=download_name)
|
||||
|
||||
|
||||
@app.route('/api/downloads/<did>', methods=['DELETE'])
|
||||
def api_download_delete(did):
|
||||
if DM.delete(did):
|
||||
return jsonify({'ok': True})
|
||||
return jsonify({'error': 'not found'}), 404
|
||||
|
||||
|
||||
@app.route('/api/downloads/<did>/cancel', methods=['POST'])
|
||||
def api_download_cancel(did):
|
||||
if DM.cancel(did):
|
||||
return jsonify({'ok': True})
|
||||
return jsonify({'error': 'cannot cancel'}), 400
|
||||
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
@@ -987,14 +1183,14 @@ if __name__ == '__main__':
|
||||
print(' XBMC-konformer Plugin-Wrapper mit Browser-UI')
|
||||
print('=' * 60)
|
||||
print(f' Sites: {len(_scan_sites())} verfuegbar')
|
||||
print(f' URL: http://localhost:8769')
|
||||
print(f' URL: http://localhost:8770')
|
||||
print(f' Downloads: {DM.dir}')
|
||||
print('=' * 60)
|
||||
# SO_REUSEADDR auf Socket-Ebene aktivieren
|
||||
import socket
|
||||
from werkzeug.serving import make_server
|
||||
srv = make_server('0.0.0.0', 8769, app, threaded=True)
|
||||
srv = make_server('0.0.0.0', 8770, app, threaded=True)
|
||||
# Socket-Option: SO_REUSEADDR — erlaubt Bind an orphaned Sockets
|
||||
srv.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
print(' Server startet auf http://localhost:8769')
|
||||
print(' Server startet auf http://localhost:8770')
|
||||
srv.serve_forever()
|
||||
+1109
-2219
File diff suppressed because one or more lines are too long
@@ -0,0 +1,70 @@
|
||||
# HLS-Downloader — Umsetzungsplan (Final)
|
||||
|
||||
## Entscheidung
|
||||
**ffmpeg (primär) + requests (Fallback)**
|
||||
|
||||
- `ffmpeg` für HLS/m3u8 Streams — ffmpeg ist auf dem System verfügbar
|
||||
- `requests.get(stream=True)` für direkte MP4-URLs (wie bisher)
|
||||
- `hls-downloader` Package ist leider nur ein CLI-Tool, nicht als Library importierbar
|
||||
|
||||
## Installierte Pakete
|
||||
```bash
|
||||
pip install pypdl m3u8
|
||||
```
|
||||
|
||||
## Architektur
|
||||
|
||||
```
|
||||
POST /api/download
|
||||
│
|
||||
▼
|
||||
┌─────────────────────┐
|
||||
│ DownloadManager │
|
||||
│ (wie bisher, aber │
|
||||
│ mit HLS-Support) │
|
||||
└────────┬────────────┘
|
||||
│
|
||||
┌────▼────┐
|
||||
│ URL-Typ │
|
||||
└────┬────┘
|
||||
│
|
||||
┌────┼────────────┐
|
||||
▼ ▼ ▼
|
||||
.m3u8 .mp4 Fehler
|
||||
│ │
|
||||
│ └──▶ requests.get (stream=True)
|
||||
│
|
||||
└──▶ ffmpeg subprocess
|
||||
-i url -c copy -bsf:a aac_adtstoasc
|
||||
```
|
||||
|
||||
## Implementiert in app.py
|
||||
|
||||
### `_run()` — Dispatcher
|
||||
- URL wird zuerst aufgelöst (resolveurl)
|
||||
- Falls `.m3u8` im URL → `_run_hls()`
|
||||
- Sonst → `_run_direct()`
|
||||
|
||||
### `_run_hls()` — ffmpeg
|
||||
```python
|
||||
cmd = ['ffmpeg', '-y', '-i', url, '-c', 'copy',
|
||||
'-bsf:a', 'aac_adtstoasc',
|
||||
'-progress', 'pipe:1', output_file]
|
||||
```
|
||||
- Progress via stdout pipe
|
||||
- Progress: `out_time_ms` → geschätzter %
|
||||
- Output: .ts → .mp4 umbenennen
|
||||
|
||||
### `_run_direct()` — requests
|
||||
- Bestehender Code, aus `_run()` extrahiert
|
||||
- Chunk-basiertes Streaming
|
||||
- Progress in %
|
||||
|
||||
## Parallelität
|
||||
- Jeder `add()` startet einen daemon Thread
|
||||
- Mehrere Downloads parallel möglich
|
||||
- Keine Queue-Library nötig (Python threading reicht)
|
||||
|
||||
## ToDo
|
||||
- [ ] Test mit echter m3u8 URL
|
||||
- [ ] Progress-Anzeige verfeinern (ffmpeg gibt keine Duration bei HLS)
|
||||
+13544
File diff suppressed because one or more lines are too long
+114
-17
@@ -42,17 +42,36 @@ header button { padding: 8px 16px; background: #e94560; border: none; border-rad
|
||||
.entry-item .entry-site { color: #e94560; }
|
||||
.entry-item .entry-arrow { color: #888; font-size: 0.8rem; }
|
||||
.hoster-list { max-width: 500px; margin: 20px auto; }
|
||||
.hoster { display: flex; align-items: center; gap: 12px; padding: 12px; background: #16213e; border-radius: 8px; margin: 6px 0; }
|
||||
.hoster { display: flex; align-items: center; gap: 12px; padding: 12px; background: #16213e; border-radius: 8px; margin: 6px 0; flex-wrap: wrap; }
|
||||
.hoster-name { flex: 1; font-weight: 600; }
|
||||
.hoster-quality { color: #e94560; font-size: 0.8rem; }
|
||||
.hoster button { padding: 6px 16px; background: #0f3460; border: 1px solid #e94560; border-radius: 6px; color: #e94560; cursor: pointer; font-size: 0.85rem; }
|
||||
.hoster button:hover { background: #e94560; color: white; }
|
||||
.hoster button.downloading { background: #e94560; color: white; cursor: not-allowed; }
|
||||
.hoster-actions { display: flex; gap: 8px; }
|
||||
.btn-stream, .btn-download { padding: 6px 14px; background: #0f3460; border: 1px solid #e94560; border-radius: 6px; color: #e94560; cursor: pointer; font-size: 0.85rem; }
|
||||
.btn-stream:hover, .btn-download:hover { background: #e94560; color: white; }
|
||||
.download-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: #16213e; border-radius: 8px; margin: 4px 0; }
|
||||
.download-item.complete { border-left: 3px solid #0f0; }
|
||||
.download-item.error, .download-item.cancelled { border-left: 3px solid #f00; }
|
||||
.download-item.downloading { border-left: 3px solid #e94560; }
|
||||
.download-item.resolving { border-left: 3px solid #ffa500; }
|
||||
.download-info { flex: 1; }
|
||||
.download-info .name { font-size: 0.9rem; display: block; }
|
||||
.download-info .status { font-size: 0.75rem; color: #888; }
|
||||
.download-actions { display: flex; gap: 6px; }
|
||||
.btn-save { padding: 4px 10px; background: #0f3460; border: 1px solid #0f0; border-radius: 4px; color: #0f0; cursor: pointer; font-size: 0.8rem; }
|
||||
.btn-save:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
.btn-cancel { padding: 4px 10px; background: #0f3460; border: 1px solid #f00; border-radius: 4px; color: #f00; cursor: pointer; font-size: 0.8rem; }
|
||||
.btn-delete { padding: 4px 10px; background: #0f3460; border: 1px solid #888; border-radius: 4px; color: #888; cursor: pointer; font-size: 0.8rem; }
|
||||
.btn-save:hover { background: #0f0; color: #000; }
|
||||
.btn-cancel:hover { background: #f00; color: #fff; }
|
||||
.btn-delete:hover { background: #888; color: #fff; }
|
||||
.download-path { font-size: 0.75rem; color: #666; margin-bottom: 10px; }
|
||||
#downloads { max-width: 600px; margin: 20px auto; }
|
||||
.download-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: #16213e; border-radius: 8px; margin: 4px 0; }
|
||||
.download-item .name { flex: 1; font-size: 0.9rem; }
|
||||
.download-item .progress-bar { flex: 2; height: 6px; background: #333; border-radius: 3px; overflow: hidden; }
|
||||
.download-item .progress-bar .fill { height: 100%; background: #e94560; transition: width 0.3s; }
|
||||
.download-item .progress-bar .fill { height: 100%; background: #0f0; transition: width 0.3s; }
|
||||
.download-item .progress-bar .fill.error { background: #f00; }
|
||||
.download-item .progress-bar .fill.resolving { background: #ff0; }
|
||||
.download-item .status { font-size: 0.75rem; color: #888; width: 80px; text-align: right; }
|
||||
.section-title { color: #e94560; font-size: 1rem; margin-bottom: 12px; cursor: pointer; }
|
||||
.loading { text-align: center; padding: 40px; color: #888; }
|
||||
@@ -113,6 +132,7 @@ function renderSidebar() {
|
||||
async function loadSite(id) {
|
||||
state.site = state.sites.find(s => s.id === id);
|
||||
if (!state.site) return;
|
||||
clearDownloadsRefresh();
|
||||
state.view = 'site';
|
||||
state.entries = [];
|
||||
state.hosters = [];
|
||||
@@ -215,12 +235,15 @@ function renderHosters(entry) {
|
||||
}
|
||||
el.innerHTML = `
|
||||
<div class="hoster-list">
|
||||
<h2 class="section-title">⬇️ "${entry.title}" herunterladen</h2>
|
||||
<h2 class="section-title">⬇️ "${entry.title}"</h2>
|
||||
${state.hosters.map((h, i) => `
|
||||
<div class="hoster">
|
||||
<span class="hoster-name">${h.displayedName || h.name}</span>
|
||||
${h.quality ? `<span class="hoster-quality">${h.quality}</span>` : ''}
|
||||
<button id="dlbtn${i}" onclick="resolveAndDownload(${i}, '${jsEscape(h.link || h.url)}', '${jsEscape(entry.title)}')">⬇ Download</button>
|
||||
<div class="hoster-actions">
|
||||
<button class="btn-stream" onclick="openInTab(${i}, '${jsEscape(h.link || h.url)}')">▶ Stream</button>
|
||||
<button class="btn-download" onclick="addToDownload(${i}, '${jsEscape(h.link || h.url)}', '${jsEscape(entry.title)}')">⬇ Download</button>
|
||||
</div>
|
||||
</div>`).join('')}
|
||||
</div>
|
||||
<button class="tab" onclick="loadSite('${state.site.id}')">← Zurück</button>
|
||||
@@ -233,8 +256,8 @@ function jsEscape(s) {
|
||||
|
||||
|
||||
|
||||
function resolveAndDownload(idx, url, title) {
|
||||
// Öffnet den Link direkt in einem neuen Tab
|
||||
function openInTab(idx, url) {
|
||||
// Öffnet den Stream in einem neuen Tab
|
||||
const link = url || '';
|
||||
if (link) {
|
||||
window.open(link, '_blank');
|
||||
@@ -243,6 +266,25 @@ function resolveAndDownload(idx, url, title) {
|
||||
}
|
||||
}
|
||||
|
||||
async function addToDownload(idx, url, title) {
|
||||
// Fügt den Stream zur Download-Queue hinzu
|
||||
const link = url || '';
|
||||
if (!link) {
|
||||
alert('Kein Link verfügbar');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const data = await api(`/download?url=${encodeURIComponent(link)}&title=${encodeURIComponent(title)}`);
|
||||
if (data.id) {
|
||||
alert(`⬇ Download gestartet!\n\nTitel: ${title}\nID: ${data.id}\n\nKlicke oben auf "📥 Downloads" um den Fortschritt zu sehen.`);
|
||||
} else if (data.error) {
|
||||
alert('Fehler: ' + data.error);
|
||||
}
|
||||
} catch(e) {
|
||||
alert('Fehler beim Starten des Downloads: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function openSearchResult(idx) {
|
||||
const entry = state.entries[idx];
|
||||
if (!entry) return;
|
||||
@@ -300,6 +342,7 @@ async function pollDownload(did, idx, title) {
|
||||
async function doSearch() {
|
||||
const q = document.getElementById('searchInput').value.trim();
|
||||
if (!q) return;
|
||||
clearDownloadsRefresh();
|
||||
state.view = 'search';
|
||||
state.entries = [];
|
||||
setBC([`Suche: "${q}"`]);
|
||||
@@ -349,28 +392,81 @@ async function doSearch() {
|
||||
}
|
||||
}
|
||||
|
||||
let _downloadsRefreshId = null;
|
||||
|
||||
function clearDownloadsRefresh() {
|
||||
if (_downloadsRefreshId) {
|
||||
clearTimeout(_downloadsRefreshId);
|
||||
_downloadsRefreshId = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function showDownloads() {
|
||||
clearDownloadsRefresh();
|
||||
state.view = 'downloads';
|
||||
setBC(['Downloads']);
|
||||
const el = document.getElementById('content');
|
||||
el.innerHTML = '<div id="downloads"><div class="loading">Lade...</div></div>';
|
||||
try {
|
||||
const list = await api('/downloads');
|
||||
const [list, dirInfo] = await Promise.all([
|
||||
api('/downloads'),
|
||||
api('/downloads/dir')
|
||||
]);
|
||||
state.downloadDir = dirInfo.dir;
|
||||
el.innerHTML = `<div id="downloads">
|
||||
<h2 class="section-title">📥 Aktive Downloads</h2>
|
||||
<h2 class="section-title">📥 Downloads</h2>
|
||||
<div class="download-path">Ordner: ${state.downloadDir}</div>
|
||||
${list.length ? list.map(d => `
|
||||
<div class="download-item">
|
||||
<div class="download-item ${d.status}">
|
||||
<div class="download-info">
|
||||
<span class="name">${d.title}</span>
|
||||
<div class="progress-bar"><div class="fill" style="width:${d.progress}%"></div></div>
|
||||
<span class="status">${d.status === 'complete' ? '✅' : d.status === 'error' ? '❌' : d.progress + '%'}</span>
|
||||
${d.status === 'complete' ? `<button class="tab" onclick="location.href='/api/downloads/${d.id}/file'">💾 Speichern</button>` : ''}
|
||||
${d.status === 'downloading' || d.status === 'resolving' ? `<div class="progress-bar"><div class="fill ${d.status}" style="width:${d.progress}%"></div></div>` : ''}
|
||||
<span class="status">${d.status === 'complete' ? '✅ Fertig' : d.status === 'error' ? '❌ ' + (d.error || 'Fehler') : d.status === 'cancelled' ? '❌ Abgebrochen' : d.status === 'downloading' ? '⏳ Lädt...' : d.status === 'resolving' ? '🔗 Auflösen...' : d.progress + '%'}</span>
|
||||
</div>
|
||||
<div class="download-actions">
|
||||
${d.status === 'complete' ? `<button class="btn-save" onclick="saveDownload('${d.id}', this)">💾 Speichern</button>` : ''}
|
||||
${d.status === 'downloading' || d.status === 'resolving' ? `<button class="btn-cancel" onclick="cancelDownload('${d.id}')">✖ Abbrechen</button>` : ''}
|
||||
<button class="btn-delete" onclick="deleteDownload('${d.id}')">🗑 Löschen</button>
|
||||
</div>
|
||||
</div>`).join('') : '<div class="loading">Keine Downloads</div>'}
|
||||
</div>`;
|
||||
} catch(e) {
|
||||
el.innerHTML = `<div class="error">${e.message}</div>`;
|
||||
}
|
||||
// Auto-refresh
|
||||
if (state.view === 'downloads') setTimeout(showDownloads, 3000);
|
||||
// Auto-refresh mit cancel-Tracking
|
||||
if (state.view === 'downloads') {
|
||||
_downloadsRefreshId = setTimeout(() => {
|
||||
_downloadsRefreshId = null;
|
||||
showDownloads();
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
async function cancelDownload(id) {
|
||||
if (!confirm('Download abbrechen?')) return;
|
||||
try {
|
||||
await api(`/downloads/${id}/cancel`, {method: 'POST'});
|
||||
showDownloads();
|
||||
} catch(e) {
|
||||
alert('Fehler: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteDownload(id) {
|
||||
if (!confirm('Download löschen?')) return;
|
||||
try {
|
||||
await api(`/downloads/${id}`, {method: 'DELETE'});
|
||||
showDownloads();
|
||||
} catch(e) {
|
||||
alert('Fehler: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveDownload(id, btn) {
|
||||
// Download starten und Button deaktivieren
|
||||
btn.disabled = true;
|
||||
btn.style.opacity = '0.5';
|
||||
location.href = `/api/downloads/${id}/file`;
|
||||
}
|
||||
|
||||
function setBC(parts) {
|
||||
@@ -399,6 +495,7 @@ function goBack() {
|
||||
}
|
||||
|
||||
function goHome() {
|
||||
clearDownloadsRefresh();
|
||||
state.view = 'home';
|
||||
state.site = null;
|
||||
state.entries = [];
|
||||
|
||||
Reference in New Issue
Block a user