|
|
|
@@ -3,10 +3,14 @@ from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
import base64
|
|
|
|
import base64
|
|
|
|
import hashlib
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
import hmac
|
|
|
|
|
|
|
|
import html as html_mod
|
|
|
|
|
|
|
|
import ipaddress
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import shlex
|
|
|
|
import shlex
|
|
|
|
|
|
|
|
import socket
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
import threading
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
@@ -18,7 +22,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
|
|
|
from myjdapi import Myjdapi
|
|
|
|
from myjdapi import Myjdapi
|
|
|
|
import paramiko
|
|
|
|
import paramiko
|
|
|
|
from fastapi import FastAPI, Form, Request
|
|
|
|
from fastapi import FastAPI, Form, Request
|
|
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
|
|
from fastapi.responses import HTMLResponse, PlainTextResponse, RedirectResponse
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
# ============================================================
|
|
|
|
@@ -57,9 +61,22 @@ POLL_SECONDS = float(os.environ.get("POLL_SECONDS", "5"))
|
|
|
|
# JDownloader writes here inside container
|
|
|
|
# JDownloader writes here inside container
|
|
|
|
JD_OUTPUT_PATH = "/output"
|
|
|
|
JD_OUTPUT_PATH = "/output"
|
|
|
|
PROXY_EXPORT_PATH = os.environ.get("PROXY_EXPORT_PATH", "/output/jd-proxies.jdproxies")
|
|
|
|
PROXY_EXPORT_PATH = os.environ.get("PROXY_EXPORT_PATH", "/output/jd-proxies.jdproxies")
|
|
|
|
|
|
|
|
LOG_BUFFER_LIMIT = int(os.environ.get("LOG_BUFFER_LIMIT", "500"))
|
|
|
|
|
|
|
|
|
|
|
|
URL_RE = re.compile(r"^https?://", re.I)
|
|
|
|
URL_RE = re.compile(r"^https?://", re.I)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NO_PROXY_OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def esc(s: str) -> str:
|
|
|
|
|
|
|
|
"""HTML-escape a string to prevent XSS."""
|
|
|
|
|
|
|
|
return html_mod.escape(str(s), quote=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mask_secret(value: str, visible: int = 4) -> str:
|
|
|
|
|
|
|
|
"""Mask a secret string, showing only the last `visible` characters."""
|
|
|
|
|
|
|
|
if len(value) <= visible:
|
|
|
|
|
|
|
|
return "***"
|
|
|
|
|
|
|
|
return "***" + value[-visible:]
|
|
|
|
|
|
|
|
|
|
|
|
VIDEO_EXTS = {
|
|
|
|
VIDEO_EXTS = {
|
|
|
|
".mkv", ".mp4", ".m4v", ".avi", ".mov", ".wmv", ".flv", ".webm",
|
|
|
|
".mkv", ".mp4", ".m4v", ".avi", ".mov", ".wmv", ".flv", ".webm",
|
|
|
|
".ts", ".m2ts", ".mts", ".mpg", ".mpeg", ".vob", ".ogv",
|
|
|
|
".ts", ".m2ts", ".mts", ".mpg", ".mpeg", ".vob", ".ogv",
|
|
|
|
@@ -92,7 +109,7 @@ def _check_basic_auth(req: Request) -> bool:
|
|
|
|
if ":" not in raw:
|
|
|
|
if ":" not in raw:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
user, pw = raw.split(":", 1)
|
|
|
|
user, pw = raw.split(":", 1)
|
|
|
|
return user == BASIC_AUTH_USER and pw == BASIC_AUTH_PASS
|
|
|
|
return hmac.compare_digest(user, BASIC_AUTH_USER) and hmac.compare_digest(pw, BASIC_AUTH_PASS)
|
|
|
|
|
|
|
|
|
|
|
|
def _auth_challenge() -> HTMLResponse:
|
|
|
|
def _auth_challenge() -> HTMLResponse:
|
|
|
|
return HTMLResponse(
|
|
|
|
return HTMLResponse(
|
|
|
|
@@ -123,6 +140,21 @@ class Job:
|
|
|
|
|
|
|
|
|
|
|
|
jobs: Dict[str, Job] = {}
|
|
|
|
jobs: Dict[str, Job] = {}
|
|
|
|
lock = threading.Lock()
|
|
|
|
lock = threading.Lock()
|
|
|
|
|
|
|
|
log_lock = threading.Lock()
|
|
|
|
|
|
|
|
connection_logs: List[str] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def log_connection(message: str) -> None:
|
|
|
|
|
|
|
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
|
|
line = f"[{timestamp}] {message}"
|
|
|
|
|
|
|
|
with log_lock:
|
|
|
|
|
|
|
|
connection_logs.append(line)
|
|
|
|
|
|
|
|
if len(connection_logs) > LOG_BUFFER_LIMIT:
|
|
|
|
|
|
|
|
excess = len(connection_logs) - LOG_BUFFER_LIMIT
|
|
|
|
|
|
|
|
del connection_logs[:excess]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_connection_logs() -> str:
|
|
|
|
|
|
|
|
with log_lock:
|
|
|
|
|
|
|
|
return "\n".join(connection_logs)
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
# ============================================================
|
|
|
|
# Core helpers
|
|
|
|
# Core helpers
|
|
|
|
@@ -149,6 +181,7 @@ def ensure_env():
|
|
|
|
|
|
|
|
|
|
|
|
def get_device():
|
|
|
|
def get_device():
|
|
|
|
jd = Myjdapi()
|
|
|
|
jd = Myjdapi()
|
|
|
|
|
|
|
|
log_connection(f"MyJDownloader connect as {MYJD_EMAIL or 'unknown'}")
|
|
|
|
jd.connect(MYJD_EMAIL, MYJD_PASSWORD)
|
|
|
|
jd.connect(MYJD_EMAIL, MYJD_PASSWORD)
|
|
|
|
|
|
|
|
|
|
|
|
wanted = (MYJD_DEVICE or "").strip()
|
|
|
|
wanted = (MYJD_DEVICE or "").strip()
|
|
|
|
@@ -200,6 +233,47 @@ def is_video_file(path: str) -> bool:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
return ext in VIDEO_EXTS
|
|
|
|
return ext in VIDEO_EXTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEMO_PATTERNS = {"big_buck_bunny", "bigbuckbunny", "big buck bunny", "bbb_sunflower"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_demo_link(name: str) -> bool:
|
|
|
|
|
|
|
|
"""Detect JDownloader demo/fallback videos (e.g. Big Buck Bunny)."""
|
|
|
|
|
|
|
|
lower = name.lower().replace("-", "_").replace(".", " ")
|
|
|
|
|
|
|
|
return any(pat in lower for pat in DEMO_PATTERNS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _is_ssrf_target(url: str) -> bool:
|
|
|
|
|
|
|
|
"""Return True if the URL resolves to a private/loopback address (SSRF protection)."""
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
host = urllib.parse.urlparse(url).hostname or ""
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
addr = ipaddress.ip_address(host)
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
host = socket.gethostbyname(host)
|
|
|
|
|
|
|
|
addr = ipaddress.ip_address(host)
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return addr.is_private or addr.is_loopback or addr.is_link_local or addr.is_reserved
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_url_reachable(url: str) -> Optional[str]:
|
|
|
|
|
|
|
|
"""Try a HEAD request to verify the URL is reachable. Returns error string or None."""
|
|
|
|
|
|
|
|
if _is_ssrf_target(url):
|
|
|
|
|
|
|
|
return "URL zeigt auf eine interne/private Adresse (nicht erlaubt)"
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
req = urllib.request.Request(url, method="HEAD")
|
|
|
|
|
|
|
|
req.add_header("User-Agent", "Mozilla/5.0")
|
|
|
|
|
|
|
|
with urllib.request.urlopen(req, timeout=10) as resp:
|
|
|
|
|
|
|
|
if resp.status >= 400:
|
|
|
|
|
|
|
|
return f"URL antwortet mit HTTP {resp.status}"
|
|
|
|
|
|
|
|
except urllib.error.HTTPError as e:
|
|
|
|
|
|
|
|
return f"URL nicht erreichbar: HTTP {e.code}"
|
|
|
|
|
|
|
|
except urllib.error.URLError as e:
|
|
|
|
|
|
|
|
return f"URL nicht erreichbar: {e.reason}"
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
return f"URL-Check fehlgeschlagen: {e}"
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def md5_file(path: str) -> str:
|
|
|
|
def md5_file(path: str) -> str:
|
|
|
|
h = hashlib.md5()
|
|
|
|
h = hashlib.md5()
|
|
|
|
with open(path, "rb") as f:
|
|
|
|
with open(path, "rb") as f:
|
|
|
|
@@ -243,9 +317,17 @@ def ffprobe_ok(path: str) -> bool:
|
|
|
|
# ============================================================
|
|
|
|
# ============================================================
|
|
|
|
# SSH/SFTP
|
|
|
|
# SSH/SFTP
|
|
|
|
# ============================================================
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
SSH_KNOWN_HOSTS = os.environ.get("SSH_KNOWN_HOSTS", "/ssh/known_hosts")
|
|
|
|
|
|
|
|
|
|
|
|
def ssh_connect() -> paramiko.SSHClient:
|
|
|
|
def ssh_connect() -> paramiko.SSHClient:
|
|
|
|
ssh = paramiko.SSHClient()
|
|
|
|
ssh = paramiko.SSHClient()
|
|
|
|
|
|
|
|
if os.path.isfile(SSH_KNOWN_HOSTS):
|
|
|
|
|
|
|
|
ssh.load_host_keys(SSH_KNOWN_HOSTS)
|
|
|
|
|
|
|
|
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
|
|
|
|
|
|
|
log_connection(f"SSH connect {JELLYFIN_USER}@{JELLYFIN_HOST}:{JELLYFIN_PORT} (known_hosts verified)")
|
|
|
|
|
|
|
|
else:
|
|
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
|
|
|
|
|
|
log_connection(f"SSH connect {JELLYFIN_USER}@{JELLYFIN_HOST}:{JELLYFIN_PORT} (WARNING: no known_hosts, accepting any host key)")
|
|
|
|
ssh.connect(
|
|
|
|
ssh.connect(
|
|
|
|
hostname=JELLYFIN_HOST,
|
|
|
|
hostname=JELLYFIN_HOST,
|
|
|
|
port=JELLYFIN_PORT,
|
|
|
|
port=JELLYFIN_PORT,
|
|
|
|
@@ -268,6 +350,7 @@ def sftp_mkdirs(sftp: paramiko.SFTPClient, remote_dir: str):
|
|
|
|
def sftp_upload(ssh: paramiko.SSHClient, local_path: str, remote_path: str):
|
|
|
|
def sftp_upload(ssh: paramiko.SSHClient, local_path: str, remote_path: str):
|
|
|
|
sftp = ssh.open_sftp()
|
|
|
|
sftp = ssh.open_sftp()
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
log_connection(f"SFTP upload {local_path} -> {remote_path}")
|
|
|
|
sftp_mkdirs(sftp, os.path.dirname(remote_path))
|
|
|
|
sftp_mkdirs(sftp, os.path.dirname(remote_path))
|
|
|
|
sftp.put(local_path, remote_path)
|
|
|
|
sftp.put(local_path, remote_path)
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
@@ -276,6 +359,7 @@ def sftp_upload(ssh: paramiko.SSHClient, local_path: str, remote_path: str):
|
|
|
|
def remote_md5sum(ssh: paramiko.SSHClient, remote_path: str) -> str:
|
|
|
|
def remote_md5sum(ssh: paramiko.SSHClient, remote_path: str) -> str:
|
|
|
|
quoted = shlex.quote(remote_path)
|
|
|
|
quoted = shlex.quote(remote_path)
|
|
|
|
cmd = f"md5sum {quoted}"
|
|
|
|
cmd = f"md5sum {quoted}"
|
|
|
|
|
|
|
|
log_connection(f"SSH exec {cmd}")
|
|
|
|
stdin, stdout, stderr = ssh.exec_command(cmd, timeout=120)
|
|
|
|
stdin, stdout, stderr = ssh.exec_command(cmd, timeout=120)
|
|
|
|
out = stdout.read().decode("utf-8", "replace").strip()
|
|
|
|
out = stdout.read().decode("utf-8", "replace").strip()
|
|
|
|
err = stderr.read().decode("utf-8", "replace").strip()
|
|
|
|
err = stderr.read().decode("utf-8", "replace").strip()
|
|
|
|
@@ -288,9 +372,20 @@ def remote_md5sum(ssh: paramiko.SSHClient, remote_path: str) -> str:
|
|
|
|
# ============================================================
|
|
|
|
# ============================================================
|
|
|
|
# TMDB & naming
|
|
|
|
# TMDB & naming
|
|
|
|
# ============================================================
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
def _sanitize_url_for_log(url: str) -> str:
|
|
|
|
|
|
|
|
"""Remove sensitive query params (api_key) from URLs before logging."""
|
|
|
|
|
|
|
|
parsed = urllib.parse.urlparse(url)
|
|
|
|
|
|
|
|
params = urllib.parse.parse_qs(parsed.query, keep_blank_values=True)
|
|
|
|
|
|
|
|
for key in ("api_key", "apikey", "token"):
|
|
|
|
|
|
|
|
if key in params:
|
|
|
|
|
|
|
|
params[key] = ["***"]
|
|
|
|
|
|
|
|
safe_query = urllib.parse.urlencode(params, doseq=True)
|
|
|
|
|
|
|
|
return urllib.parse.urlunparse(parsed._replace(query=safe_query))
|
|
|
|
|
|
|
|
|
|
|
|
def _http_get_json(url: str, headers: Optional[Dict[str, str]] = None) -> Any:
|
|
|
|
def _http_get_json(url: str, headers: Optional[Dict[str, str]] = None) -> Any:
|
|
|
|
req = urllib.request.Request(url, headers=headers or {})
|
|
|
|
req = urllib.request.Request(url, headers=headers or {})
|
|
|
|
with urllib.request.urlopen(req, timeout=20) as r:
|
|
|
|
log_connection(f"HTTP GET {_sanitize_url_for_log(url)} (no-proxy)")
|
|
|
|
|
|
|
|
with NO_PROXY_OPENER.open(req, timeout=20) as r:
|
|
|
|
return json.loads(r.read().decode("utf-8", "replace"))
|
|
|
|
return json.loads(r.read().decode("utf-8", "replace"))
|
|
|
|
|
|
|
|
|
|
|
|
def tmdb_search_movie(query: str) -> Optional[Dict[str, Any]]:
|
|
|
|
def tmdb_search_movie(query: str) -> Optional[Dict[str, Any]]:
|
|
|
|
@@ -361,20 +456,92 @@ def format_proxy_lines(raw: str, scheme: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
return "\n".join(dedup)
|
|
|
|
return "\n".join(dedup)
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_proxy_list(url: str) -> str:
|
|
|
|
_PROXY_FETCH_LIMIT = 2 * 1024 * 1024 # 2 MB cap to prevent memory exhaustion
|
|
|
|
req = urllib.request.Request(url)
|
|
|
|
_proxy_cache: Dict[str, Tuple[float, str]] = {}
|
|
|
|
with urllib.request.urlopen(req, timeout=20) as resp:
|
|
|
|
_PROXY_CACHE_TTL = 300.0 # 5 minutes
|
|
|
|
return resp.read().decode("utf-8", "replace")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_proxy_export(text: str) -> str:
|
|
|
|
def fetch_proxy_list(url: str) -> str:
|
|
|
|
|
|
|
|
now = time.time()
|
|
|
|
|
|
|
|
cached_ts, cached_text = _proxy_cache.get(url, (0.0, ""))
|
|
|
|
|
|
|
|
if cached_text and now - cached_ts < _PROXY_CACHE_TTL:
|
|
|
|
|
|
|
|
return cached_text
|
|
|
|
|
|
|
|
req = urllib.request.Request(url)
|
|
|
|
|
|
|
|
log_connection(f"HTTP GET {url} (no-proxy)")
|
|
|
|
|
|
|
|
with NO_PROXY_OPENER.open(req, timeout=20) as resp:
|
|
|
|
|
|
|
|
text = resp.read(_PROXY_FETCH_LIMIT).decode("utf-8", "replace")
|
|
|
|
|
|
|
|
if "\n" not in text and re.search(r"\s", text):
|
|
|
|
|
|
|
|
text = re.sub(r"\s+", "\n", text.strip())
|
|
|
|
|
|
|
|
_proxy_cache[url] = (now, text)
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_jdproxies_payload(text: str) -> Dict[str, Any]:
|
|
|
|
if not text.strip():
|
|
|
|
if not text.strip():
|
|
|
|
raise ValueError("Keine Proxy-Einträge zum Speichern.")
|
|
|
|
raise ValueError("Keine Proxy-Einträge zum Speichern.")
|
|
|
|
|
|
|
|
entries: List[Dict[str, Any]] = []
|
|
|
|
|
|
|
|
type_map = {
|
|
|
|
|
|
|
|
"socks5": "SOCKS5",
|
|
|
|
|
|
|
|
"socks4": "SOCKS4",
|
|
|
|
|
|
|
|
"http": "HTTP",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
entries.append({
|
|
|
|
|
|
|
|
"filter": None,
|
|
|
|
|
|
|
|
"proxy": {
|
|
|
|
|
|
|
|
"address": None,
|
|
|
|
|
|
|
|
"password": None,
|
|
|
|
|
|
|
|
"port": 80,
|
|
|
|
|
|
|
|
"type": "NONE",
|
|
|
|
|
|
|
|
"username": None,
|
|
|
|
|
|
|
|
"connectMethodPrefered": False,
|
|
|
|
|
|
|
|
"preferNativeImplementation": False,
|
|
|
|
|
|
|
|
"resolveHostName": False,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"enabled": True,
|
|
|
|
|
|
|
|
"pac": False,
|
|
|
|
|
|
|
|
"rangeRequestsSupported": True,
|
|
|
|
|
|
|
|
"reconnectSupported": True,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
for line in text.splitlines():
|
|
|
|
|
|
|
|
s = line.strip()
|
|
|
|
|
|
|
|
if not s:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
parsed = urllib.parse.urlparse(s)
|
|
|
|
|
|
|
|
if not parsed.scheme or not parsed.hostname or parsed.port is None:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
proxy_type = type_map.get(parsed.scheme.lower())
|
|
|
|
|
|
|
|
if not proxy_type:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
entries.append({
|
|
|
|
|
|
|
|
"filter": None,
|
|
|
|
|
|
|
|
"proxy": {
|
|
|
|
|
|
|
|
"address": parsed.hostname,
|
|
|
|
|
|
|
|
"password": None,
|
|
|
|
|
|
|
|
"port": int(parsed.port),
|
|
|
|
|
|
|
|
"type": proxy_type,
|
|
|
|
|
|
|
|
"username": None,
|
|
|
|
|
|
|
|
"connectMethodPrefered": False,
|
|
|
|
|
|
|
|
"preferNativeImplementation": False,
|
|
|
|
|
|
|
|
"resolveHostName": False,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"enabled": True,
|
|
|
|
|
|
|
|
"pac": False,
|
|
|
|
|
|
|
|
"rangeRequestsSupported": True,
|
|
|
|
|
|
|
|
"reconnectSupported": False,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if not entries:
|
|
|
|
|
|
|
|
raise ValueError("Keine gültigen Proxy-Einträge gefunden.")
|
|
|
|
|
|
|
|
return {"customProxyList": entries}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_proxy_export(text: str) -> str:
|
|
|
|
|
|
|
|
payload = build_jdproxies_payload(text)
|
|
|
|
export_path = PROXY_EXPORT_PATH
|
|
|
|
export_path = PROXY_EXPORT_PATH
|
|
|
|
export_dir = os.path.dirname(export_path)
|
|
|
|
export_dir = os.path.dirname(export_path)
|
|
|
|
if export_dir:
|
|
|
|
if export_dir:
|
|
|
|
os.makedirs(export_dir, exist_ok=True)
|
|
|
|
os.makedirs(export_dir, exist_ok=True)
|
|
|
|
|
|
|
|
if os.path.exists(export_path):
|
|
|
|
|
|
|
|
os.remove(export_path)
|
|
|
|
with open(export_path, "w", encoding="utf-8") as handle:
|
|
|
|
with open(export_path, "w", encoding="utf-8") as handle:
|
|
|
|
handle.write(text.strip() + "\n")
|
|
|
|
handle.write(json.dumps(payload, indent=2))
|
|
|
|
|
|
|
|
handle.write("\n")
|
|
|
|
return export_path
|
|
|
|
return export_path
|
|
|
|
|
|
|
|
|
|
|
|
def pick_library_target(library_choice: str, filename: str, package_name: str) -> str:
|
|
|
|
def pick_library_target(library_choice: str, filename: str, package_name: str) -> str:
|
|
|
|
@@ -448,7 +615,8 @@ def jellyfin_refresh_library():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
url = JELLYFIN_API_BASE + path
|
|
|
|
url = JELLYFIN_API_BASE + path
|
|
|
|
req = urllib.request.Request(url, headers=headers, method="POST")
|
|
|
|
req = urllib.request.Request(url, headers=headers, method="POST")
|
|
|
|
with urllib.request.urlopen(req, timeout=20) as r:
|
|
|
|
log_connection(f"HTTP POST {url} (no-proxy)")
|
|
|
|
|
|
|
|
with NO_PROXY_OPENER.open(req, timeout=20) as r:
|
|
|
|
_ = r.read()
|
|
|
|
_ = r.read()
|
|
|
|
return
|
|
|
|
return
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
@@ -505,6 +673,31 @@ def local_paths_from_links(links: List[Dict[str, Any]], pkg_map: Dict[Any, Dict[
|
|
|
|
out.append(p)
|
|
|
|
out.append(p)
|
|
|
|
return out
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def call_raw_jd_api(dev, endpoints: List[str], payloads: List[Dict[str, Any]]) -> bool:
|
|
|
|
|
|
|
|
method_candidates = ["action", "call", "api", "request"]
|
|
|
|
|
|
|
|
for method_name in method_candidates:
|
|
|
|
|
|
|
|
method = getattr(dev, method_name, None)
|
|
|
|
|
|
|
|
if method is None:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
for endpoint in endpoints:
|
|
|
|
|
|
|
|
for payload in payloads:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
method(endpoint, payload)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
except TypeError:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
method(endpoint, params=payload)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
except TypeError:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
method(endpoint, data=payload)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def try_remove_from_jd(dev, links: List[Dict[str, Any]], pkg_map: Dict[Any, Dict[str, Any]]) -> Optional[str]:
|
|
|
|
def try_remove_from_jd(dev, links: List[Dict[str, Any]], pkg_map: Dict[Any, Dict[str, Any]]) -> Optional[str]:
|
|
|
|
link_ids = [l.get("uuid") for l in links if l.get("uuid") is not None]
|
|
|
|
link_ids = [l.get("uuid") for l in links if l.get("uuid") is not None]
|
|
|
|
pkg_ids = list(pkg_map.keys())
|
|
|
|
pkg_ids = list(pkg_map.keys())
|
|
|
|
@@ -539,6 +732,14 @@ def try_remove_from_jd(dev, links: List[Dict[str, Any]], pkg_map: Dict[Any, Dict
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
endpoint_candidates = [
|
|
|
|
|
|
|
|
"downloads/removeLinks",
|
|
|
|
|
|
|
|
"downloadsV2/removeLinks",
|
|
|
|
|
|
|
|
"downloadcontroller/removeLinks",
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
if call_raw_jd_api(dev, endpoint_candidates, payloads):
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
return "JDownloader-API: Paket/Links konnten nicht entfernt werden (Wrapper-Methoden nicht vorhanden)."
|
|
|
|
return "JDownloader-API: Paket/Links konnten nicht entfernt werden (Wrapper-Methoden nicht vorhanden)."
|
|
|
|
|
|
|
|
|
|
|
|
def try_cancel_from_jd(dev, links: List[Dict[str, Any]], pkg_map: Dict[Any, Dict[str, Any]]) -> Optional[str]:
|
|
|
|
def try_cancel_from_jd(dev, links: List[Dict[str, Any]], pkg_map: Dict[Any, Dict[str, Any]]) -> Optional[str]:
|
|
|
|
@@ -577,6 +778,14 @@ def try_cancel_from_jd(dev, links: List[Dict[str, Any]], pkg_map: Dict[Any, Dict
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
endpoint_candidates = [
|
|
|
|
|
|
|
|
"downloads/removeLinks",
|
|
|
|
|
|
|
|
"downloadsV2/removeLinks",
|
|
|
|
|
|
|
|
"downloadcontroller/removeLinks",
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
if call_raw_jd_api(dev, endpoint_candidates, payloads):
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
return "JDownloader-API: Abbrechen fehlgeschlagen (Wrapper-Methoden nicht vorhanden)."
|
|
|
|
return "JDownloader-API: Abbrechen fehlgeschlagen (Wrapper-Methoden nicht vorhanden)."
|
|
|
|
|
|
|
|
|
|
|
|
def cancel_job(dev, jobid: str) -> Optional[str]:
|
|
|
|
def cancel_job(dev, jobid: str) -> Optional[str]:
|
|
|
|
@@ -652,6 +861,16 @@ def worker(jobid: str):
|
|
|
|
time.sleep(POLL_SECONDS)
|
|
|
|
time.sleep(POLL_SECONDS)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
all_demo = all(is_demo_link(l.get("name", "")) for l in links)
|
|
|
|
|
|
|
|
if all_demo and not is_demo_link(job.url):
|
|
|
|
|
|
|
|
cancel_msg = cancel_job(dev, jobid)
|
|
|
|
|
|
|
|
with lock:
|
|
|
|
|
|
|
|
job.status = "failed"
|
|
|
|
|
|
|
|
base_msg = "JDownloader lieferte das Demo-Video Big Buck Bunny statt des gewünschten Links."
|
|
|
|
|
|
|
|
job.message = f"{base_msg} {cancel_msg}" if cancel_msg else base_msg
|
|
|
|
|
|
|
|
job.progress = 0.0
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
all_finished = all(bool(l.get("finished")) for l in links)
|
|
|
|
all_finished = all(bool(l.get("finished")) for l in links)
|
|
|
|
if not all_finished:
|
|
|
|
if not all_finished:
|
|
|
|
progress = calculate_progress(links)
|
|
|
|
progress = calculate_progress(links)
|
|
|
|
@@ -742,7 +961,19 @@ def worker(jobid: str):
|
|
|
|
def favicon():
|
|
|
|
def favicon():
|
|
|
|
return HTMLResponse(status_code=204)
|
|
|
|
return HTMLResponse(status_code=204)
|
|
|
|
|
|
|
|
|
|
|
|
def render_page(error: str = "") -> str:
|
|
|
|
@app.get("/jobs", response_class=HTMLResponse)
|
|
|
|
|
|
|
|
def jobs_get():
|
|
|
|
|
|
|
|
return HTMLResponse(render_job_rows())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/logs", response_class=HTMLResponse)
|
|
|
|
|
|
|
|
def logs_get():
|
|
|
|
|
|
|
|
return HTMLResponse(render_logs_page())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/logs/data", response_class=PlainTextResponse)
|
|
|
|
|
|
|
|
def logs_data():
|
|
|
|
|
|
|
|
return PlainTextResponse(get_connection_logs())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_job_rows() -> str:
|
|
|
|
rows = ""
|
|
|
|
rows = ""
|
|
|
|
with lock:
|
|
|
|
with lock:
|
|
|
|
job_list = list(jobs.values())[::-1]
|
|
|
|
job_list = list(jobs.values())[::-1]
|
|
|
|
@@ -758,21 +989,29 @@ def render_page(error: str = "") -> str:
|
|
|
|
cancel_html = ""
|
|
|
|
cancel_html = ""
|
|
|
|
if j.status not in {"finished", "failed", "canceled"}:
|
|
|
|
if j.status not in {"finished", "failed", "canceled"}:
|
|
|
|
cancel_html = (
|
|
|
|
cancel_html = (
|
|
|
|
f"<form method='post' action='/cancel/{j.id}' class='inline-form'>"
|
|
|
|
f"<form method='post' action='/cancel/{esc(j.id)}' class='inline-form'>"
|
|
|
|
f"<button type='submit' class='danger'>Abbrechen</button>"
|
|
|
|
f"<button type='submit' class='danger'>Abbrechen</button>"
|
|
|
|
f"</form>"
|
|
|
|
f"</form>"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
status_class = "error" if j.status == "failed" else ("success" if j.status == "finished" else "")
|
|
|
|
rows += (
|
|
|
|
rows += (
|
|
|
|
f"<tr>"
|
|
|
|
f"<tr>"
|
|
|
|
f"<td><code>{j.id}</code></td>"
|
|
|
|
f"<td><code>{esc(j.id)}</code></td>"
|
|
|
|
f"<td style='max-width:560px; word-break:break-all;'>{j.url}</td>"
|
|
|
|
f"<td style='max-width:560px; word-break:break-all;'>{esc(j.url)}</td>"
|
|
|
|
f"<td>{j.package_name}</td>"
|
|
|
|
f"<td>{esc(j.package_name)}</td>"
|
|
|
|
f"<td>{j.library}</td>"
|
|
|
|
f"<td>{esc(j.library)}</td>"
|
|
|
|
f"<td><b>{j.status}</b><br/><small>{j.message}</small>{progress_html}{cancel_html}</td>"
|
|
|
|
f"<td><b class='{status_class}'>{esc(j.status)}</b><br/><small>{esc(j.message)}</small>{progress_html}{cancel_html}</td>"
|
|
|
|
f"</tr>"
|
|
|
|
f"</tr>"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
err_html = f"<p class='error'>{error}</p>" if error else ""
|
|
|
|
if not rows:
|
|
|
|
|
|
|
|
rows = "<tr><td colspan='5'><em>No jobs yet.</em></td></tr>"
|
|
|
|
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_page(error: str = "") -> str:
|
|
|
|
|
|
|
|
rows = render_job_rows()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err_html = f"<p class='error'>{esc(error)}</p>" if error else ""
|
|
|
|
auth_note = "aktiv" if _auth_enabled() else "aus"
|
|
|
|
auth_note = "aktiv" if _auth_enabled() else "aus"
|
|
|
|
return f"""
|
|
|
|
return f"""
|
|
|
|
<html>
|
|
|
|
<html>
|
|
|
|
@@ -781,10 +1020,18 @@ def render_page(error: str = "") -> str:
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>JD → Jellyfin</title>
|
|
|
|
<title>JD → Jellyfin</title>
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
setInterval(() => {{
|
|
|
|
async function refreshJobs() {{
|
|
|
|
if (document.hidden) return;
|
|
|
|
if (document.hidden) return;
|
|
|
|
window.location.reload();
|
|
|
|
try {{
|
|
|
|
}}, 5000);
|
|
|
|
const resp = await fetch('/jobs');
|
|
|
|
|
|
|
|
if (!resp.ok) return;
|
|
|
|
|
|
|
|
const html = await resp.text();
|
|
|
|
|
|
|
|
const tbody = document.getElementById('jobs-body');
|
|
|
|
|
|
|
|
if (tbody) tbody.innerHTML = html;
|
|
|
|
|
|
|
|
}} catch (e) {{
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
setInterval(refreshJobs, 5000);
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<body>
|
|
|
|
@@ -822,10 +1069,14 @@ def render_page(error: str = "") -> str:
|
|
|
|
<thead>
|
|
|
|
<thead>
|
|
|
|
<tr><th>JobID</th><th>URL</th><th>Paket</th><th>Ziel</th><th>Status</th></tr>
|
|
|
|
<tr><th>JobID</th><th>URL</th><th>Paket</th><th>Ziel</th><th>Status</th></tr>
|
|
|
|
</thead>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tbody id="jobs-body">
|
|
|
|
{rows if rows else "<tr><td colspan='5'><em>No jobs yet.</em></td></tr>"}
|
|
|
|
{rows}
|
|
|
|
</tbody>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<form method="post" action="/clear-finished" style="margin-top:10px;">
|
|
|
|
|
|
|
|
<button type="submit" style="background:#666; color:#fff;">Erledigte Jobs entfernen</button>
|
|
|
|
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@@ -838,20 +1089,55 @@ def render_nav(active: str) -> str:
|
|
|
|
"<div style='margin: 8px 0 14px 0;'>"
|
|
|
|
"<div style='margin: 8px 0 14px 0;'>"
|
|
|
|
+ link("Downloads", "/", "downloads")
|
|
|
|
+ link("Downloads", "/", "downloads")
|
|
|
|
+ link("Proxies", "/proxies", "proxies")
|
|
|
|
+ link("Proxies", "/proxies", "proxies")
|
|
|
|
|
|
|
|
+ link("Logs", "/logs", "logs")
|
|
|
|
+ "</div>"
|
|
|
|
+ "</div>"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_logs_page() -> str:
|
|
|
|
|
|
|
|
return f"""
|
|
|
|
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="/static/style.css">
|
|
|
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
|
|
|
<title>JD → Jellyfin (Logs)</title>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
async function refreshLogs() {{
|
|
|
|
|
|
|
|
if (document.hidden) return;
|
|
|
|
|
|
|
|
try {{
|
|
|
|
|
|
|
|
const resp = await fetch('/logs/data');
|
|
|
|
|
|
|
|
if (!resp.ok) return;
|
|
|
|
|
|
|
|
const text = await resp.text();
|
|
|
|
|
|
|
|
const area = document.getElementById('log-body');
|
|
|
|
|
|
|
|
if (area) {{
|
|
|
|
|
|
|
|
area.value = text;
|
|
|
|
|
|
|
|
area.scrollTop = area.scrollHeight;
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
}} catch (e) {{
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
setInterval(refreshLogs, 2000);
|
|
|
|
|
|
|
|
window.addEventListener('load', refreshLogs);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h1>JD → Jellyfin</h1>
|
|
|
|
|
|
|
|
{render_nav("logs")}
|
|
|
|
|
|
|
|
<p class="hint">Verbindungs-Debugger (Echtzeit). Letzte {LOG_BUFFER_LIMIT} Einträge.</p>
|
|
|
|
|
|
|
|
<textarea id="log-body" class="log-area" rows="20" readonly></textarea>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def render_proxies_page(
|
|
|
|
def render_proxies_page(
|
|
|
|
error: str = "",
|
|
|
|
error: str = "",
|
|
|
|
message: str = "",
|
|
|
|
message: str = "",
|
|
|
|
socks5_in: str = "",
|
|
|
|
socks5_in: str = "",
|
|
|
|
socks4_in: str = "",
|
|
|
|
socks4_in: str = "",
|
|
|
|
http_in: str = "",
|
|
|
|
|
|
|
|
out_text: str = "",
|
|
|
|
out_text: str = "",
|
|
|
|
export_path: str = "",
|
|
|
|
export_path: str = "",
|
|
|
|
) -> str:
|
|
|
|
) -> str:
|
|
|
|
err_html = f"<p class='error'>{error}</p>" if error else ""
|
|
|
|
err_html = f"<p class='error'>{esc(error)}</p>" if error else ""
|
|
|
|
msg_html = f"<p class='success'>{message}</p>" if message else ""
|
|
|
|
msg_html = f"<p class='success'>{esc(message)}</p>" if message else ""
|
|
|
|
return f"""
|
|
|
|
return f"""
|
|
|
|
<html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<head>
|
|
|
|
@@ -868,27 +1154,22 @@ def render_proxies_page(
|
|
|
|
<form method="post" action="/proxies">
|
|
|
|
<form method="post" action="/proxies">
|
|
|
|
<div class="row">
|
|
|
|
<div class="row">
|
|
|
|
<label>SOCKS5 (ein Proxy pro Zeile, z. B. IP:PORT)</label><br/>
|
|
|
|
<label>SOCKS5 (ein Proxy pro Zeile, z. B. IP:PORT)</label><br/>
|
|
|
|
<textarea name="socks5_in" rows="6" style="width:100%; max-width:860px; padding:10px; border:1px solid #ccc; border-radius:8px;">{socks5_in}</textarea>
|
|
|
|
<textarea name="socks5_in" rows="6" style="width:100%; max-width:860px; padding:10px; border:1px solid #ccc; border-radius:8px;">{esc(socks5_in)}</textarea>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="row">
|
|
|
|
<label>SOCKS4 (ein Proxy pro Zeile, z. B. IP:PORT)</label><br/>
|
|
|
|
<label>SOCKS4 (ein Proxy pro Zeile, z. B. IP:PORT)</label><br/>
|
|
|
|
<textarea name="socks4_in" rows="6" style="width:100%; max-width:860px; padding:10px; border:1px solid #ccc; border-radius:8px;">{socks4_in}</textarea>
|
|
|
|
<textarea name="socks4_in" rows="6" style="width:100%; max-width:860px; padding:10px; border:1px solid #ccc; border-radius:8px;">{esc(socks4_in)}</textarea>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
|
|
|
|
<label>HTTP (ein Proxy pro Zeile, z. B. IP:PORT)</label><br/>
|
|
|
|
|
|
|
|
<textarea name="http_in" rows="6" style="width:100%; max-width:860px; padding:10px; border:1px solid #ccc; border-radius:8px;">{http_in}</textarea>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<button type="submit">In JDownloader-Format umwandeln</button>
|
|
|
|
<button type="submit">In JDownloader-Format umwandeln</button>
|
|
|
|
</form>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|
<h2 style="margin-top:18px;">JDownloader Import-Liste</h2>
|
|
|
|
<h2 style="margin-top:18px;">JDownloader Import-Liste</h2>
|
|
|
|
<p class="hint">Format: <code>socks5://IP:PORT</code>, <code>socks4://IP:PORT</code>, <code>http://IP:PORT</code>. Keine Prüfung/Validierung.</p>
|
|
|
|
<p class="hint">Format: <code>socks5://IP:PORT</code>, <code>socks4://IP:PORT</code>. Keine Prüfung/Validierung.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="row">
|
|
|
|
<textarea id="out" rows="12" readonly style="width:100%; max-width:860px; padding:10px; border:1px solid #ccc; border-radius:8px;">{out_text}</textarea>
|
|
|
|
<textarea id="out" rows="12" readonly style="width:100%; max-width:860px; padding:10px; border:1px solid #ccc; border-radius:8px;">{esc(out_text)}</textarea>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<button type="button" onclick="navigator.clipboard.writeText(document.getElementById('out').value)">Kopieren</button>
|
|
|
|
<button type="button" onclick="navigator.clipboard.writeText(document.getElementById('out').value)">Kopieren</button>
|
|
|
|
@@ -897,13 +1178,12 @@ def render_proxies_page(
|
|
|
|
<p class="hint">Speichert die Liste als <code>.jdproxies</code> im Container, z. B. zum Import in JDownloader → Verbindungsmanager → Importieren.</p>
|
|
|
|
<p class="hint">Speichert die Liste als <code>.jdproxies</code> im Container, z. B. zum Import in JDownloader → Verbindungsmanager → Importieren.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<form method="post" action="/proxies/save">
|
|
|
|
<form method="post" action="/proxies/save">
|
|
|
|
<textarea name="socks5_in" style="display:none;">{socks5_in}</textarea>
|
|
|
|
<textarea name="socks5_in" style="display:none;">{esc(socks5_in)}</textarea>
|
|
|
|
<textarea name="socks4_in" style="display:none;">{socks4_in}</textarea>
|
|
|
|
<textarea name="socks4_in" style="display:none;">{esc(socks4_in)}</textarea>
|
|
|
|
<textarea name="http_in" style="display:none;">{http_in}</textarea>
|
|
|
|
|
|
|
|
<button type="submit">Liste als JDProxies speichern</button>
|
|
|
|
<button type="submit">Liste als JDProxies speichern</button>
|
|
|
|
</form>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|
<p class="hint">Aktueller Pfad: <code>{export_path or PROXY_EXPORT_PATH}</code></p>
|
|
|
|
<p class="hint">Aktueller Pfad: <code>{esc(export_path or PROXY_EXPORT_PATH)}</code></p>
|
|
|
|
</body>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@@ -926,7 +1206,15 @@ def submit(url: str = Form(...), package_name: str = Form(""), library: str = Fo
|
|
|
|
if not URL_RE.match(url):
|
|
|
|
if not URL_RE.match(url):
|
|
|
|
return HTMLResponse(render_page("Nur http(s) URLs erlaubt."), status_code=400)
|
|
|
|
return HTMLResponse(render_page("Nur http(s) URLs erlaubt."), status_code=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
url_err = check_url_reachable(url)
|
|
|
|
|
|
|
|
if url_err:
|
|
|
|
|
|
|
|
log_connection(f"URL-Check fehlgeschlagen: {url} -> {url_err}")
|
|
|
|
|
|
|
|
return HTMLResponse(render_page(f"Link nicht erreichbar: {url_err}"), status_code=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
dev = get_device()
|
|
|
|
dev = get_device()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
return HTMLResponse(render_page(f"JDownloader nicht erreichbar: {e}"), status_code=503)
|
|
|
|
resp = dev.linkgrabber.add_links([{
|
|
|
|
resp = dev.linkgrabber.add_links([{
|
|
|
|
"links": url,
|
|
|
|
"links": url,
|
|
|
|
"autostart": True,
|
|
|
|
"autostart": True,
|
|
|
|
@@ -966,21 +1254,30 @@ def cancel(jobid: str):
|
|
|
|
job.message = "Abbruch angefordert…"
|
|
|
|
job.message = "Abbruch angefordert…"
|
|
|
|
return RedirectResponse(url="/", status_code=303)
|
|
|
|
return RedirectResponse(url="/", status_code=303)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/clear-finished")
|
|
|
|
|
|
|
|
def clear_finished():
|
|
|
|
|
|
|
|
with lock:
|
|
|
|
|
|
|
|
to_remove = [jid for jid, j in jobs.items() if j.status in {"finished", "failed", "canceled"}]
|
|
|
|
|
|
|
|
for jid in to_remove:
|
|
|
|
|
|
|
|
del jobs[jid]
|
|
|
|
|
|
|
|
return RedirectResponse(url="/", status_code=303)
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/proxies", response_class=HTMLResponse)
|
|
|
|
@app.get("/proxies", response_class=HTMLResponse)
|
|
|
|
def proxies_get():
|
|
|
|
def proxies_get():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
socks5_in = fetch_proxy_list("https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks5.txt")
|
|
|
|
socks5_in = fetch_proxy_list(
|
|
|
|
socks4_in = fetch_proxy_list("https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks4.txt")
|
|
|
|
"https://api.proxyscrape.com/v4/free-proxy-list/get?request=displayproxies&protocol=socks5&timeout=10000&country=all&ssl=yes&anonymity=elite&skip=0&limit=2000"
|
|
|
|
http_in = fetch_proxy_list("https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/http.txt")
|
|
|
|
)
|
|
|
|
|
|
|
|
socks4_in = fetch_proxy_list(
|
|
|
|
|
|
|
|
"https://api.proxyscrape.com/v4/free-proxy-list/get?request=displayproxies&protocol=socks4&timeout=10000&country=all&ssl=yes&anonymity=elite&skip=0&limit=2000"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
s5 = format_proxy_lines(socks5_in, "socks5")
|
|
|
|
s5 = format_proxy_lines(socks5_in, "socks5")
|
|
|
|
s4 = format_proxy_lines(socks4_in, "socks4")
|
|
|
|
s4 = format_proxy_lines(socks4_in, "socks4")
|
|
|
|
hp = format_proxy_lines(http_in, "http")
|
|
|
|
combined = "\n".join([x for x in [s5, s4] if x.strip()])
|
|
|
|
combined = "\n".join([x for x in [s5, s4, hp] if x.strip()])
|
|
|
|
|
|
|
|
return HTMLResponse(render_proxies_page(
|
|
|
|
return HTMLResponse(render_proxies_page(
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
http_in=http_in,
|
|
|
|
|
|
|
|
out_text=combined,
|
|
|
|
out_text=combined,
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
))
|
|
|
|
))
|
|
|
|
@@ -991,18 +1288,15 @@ def proxies_get():
|
|
|
|
def proxies_post(
|
|
|
|
def proxies_post(
|
|
|
|
socks5_in: str = Form(""),
|
|
|
|
socks5_in: str = Form(""),
|
|
|
|
socks4_in: str = Form(""),
|
|
|
|
socks4_in: str = Form(""),
|
|
|
|
http_in: str = Form(""),
|
|
|
|
|
|
|
|
):
|
|
|
|
):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
s5 = format_proxy_lines(socks5_in, "socks5")
|
|
|
|
s5 = format_proxy_lines(socks5_in, "socks5")
|
|
|
|
s4 = format_proxy_lines(socks4_in, "socks4")
|
|
|
|
s4 = format_proxy_lines(socks4_in, "socks4")
|
|
|
|
hp = format_proxy_lines(http_in, "http")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
combined = "\n".join([x for x in [s5, s4, hp] if x.strip()])
|
|
|
|
combined = "\n".join([x for x in [s5, s4] if x.strip()])
|
|
|
|
return HTMLResponse(render_proxies_page(
|
|
|
|
return HTMLResponse(render_proxies_page(
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
http_in=http_in,
|
|
|
|
|
|
|
|
out_text=combined,
|
|
|
|
out_text=combined,
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
))
|
|
|
|
))
|
|
|
|
@@ -1011,7 +1305,6 @@ def proxies_post(
|
|
|
|
error=str(e),
|
|
|
|
error=str(e),
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
http_in=http_in,
|
|
|
|
|
|
|
|
out_text="",
|
|
|
|
out_text="",
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
), status_code=400)
|
|
|
|
), status_code=400)
|
|
|
|
@@ -1020,19 +1313,16 @@ def proxies_post(
|
|
|
|
def proxies_save(
|
|
|
|
def proxies_save(
|
|
|
|
socks5_in: str = Form(""),
|
|
|
|
socks5_in: str = Form(""),
|
|
|
|
socks4_in: str = Form(""),
|
|
|
|
socks4_in: str = Form(""),
|
|
|
|
http_in: str = Form(""),
|
|
|
|
|
|
|
|
):
|
|
|
|
):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
s5 = format_proxy_lines(socks5_in, "socks5")
|
|
|
|
s5 = format_proxy_lines(socks5_in, "socks5")
|
|
|
|
s4 = format_proxy_lines(socks4_in, "socks4")
|
|
|
|
s4 = format_proxy_lines(socks4_in, "socks4")
|
|
|
|
hp = format_proxy_lines(http_in, "http")
|
|
|
|
combined = "\n".join([x for x in [s5, s4] if x.strip()])
|
|
|
|
combined = "\n".join([x for x in [s5, s4, hp] if x.strip()])
|
|
|
|
|
|
|
|
export_path = save_proxy_export(combined)
|
|
|
|
export_path = save_proxy_export(combined)
|
|
|
|
return HTMLResponse(render_proxies_page(
|
|
|
|
return HTMLResponse(render_proxies_page(
|
|
|
|
message=f"Proxy-Liste gespeichert: {export_path}",
|
|
|
|
message=f"Proxy-Liste gespeichert: {export_path}",
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
http_in=http_in,
|
|
|
|
|
|
|
|
out_text=combined,
|
|
|
|
out_text=combined,
|
|
|
|
export_path=export_path,
|
|
|
|
export_path=export_path,
|
|
|
|
))
|
|
|
|
))
|
|
|
|
@@ -1041,7 +1331,6 @@ def proxies_save(
|
|
|
|
error=str(e),
|
|
|
|
error=str(e),
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks5_in=socks5_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
socks4_in=socks4_in,
|
|
|
|
http_in=http_in,
|
|
|
|
|
|
|
|
out_text="",
|
|
|
|
out_text="",
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
export_path=PROXY_EXPORT_PATH,
|
|
|
|
), status_code=400)
|
|
|
|
), status_code=400)
|
|
|
|
|