diff --git a/manifests/media/jdownloader.yaml b/manifests/media/jdownloader.yaml index 4b7fcf0..08d41e5 100644 --- a/manifests/media/jdownloader.yaml +++ b/manifests/media/jdownloader.yaml @@ -122,13 +122,16 @@ spec: volumeMounts: - name: config mountPath: /config + - name: dl + mountPath: /output command: - python3 - -c - | - import http.server, urllib.parse, os, time + import http.server, urllib.parse, urllib.request, os, time WATCH_DIR = '/config/folderwatch' + TORRENT_DIR = '/output' os.makedirs(WATCH_DIR, exist_ok=True) class Handler(http.server.BaseHTTPRequestHandler): @@ -143,6 +146,27 @@ spec: self.send_response(400); self.end_headers(); return url = urls[0] basename = urllib.parse.unquote(urllib.parse.urlparse(url).path.rsplit('/', 1)[-1]) + + # .torrent files aren't handled by JDownloader's crawler (no BT + # plugin), so fetch the raw file ourselves instead of writing a + # crawljob. This container shares gluetun's netns, so the fetch + # is still VPN-routed same as JDownloader's own downloads. + if basename.lower().endswith('.torrent'): + safe_name = basename.replace('/', '_').replace('\\', '_') + try: + req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'}) + with urllib.request.urlopen(req, timeout=30) as resp: + data = resp.read() + with open(f'{TORRENT_DIR}/{safe_name}', 'wb') as f: + f.write(data) + except Exception as e: + self.send_response(502); self.end_headers() + self.wfile.write(str(e).encode()) + return + self.send_response(200); self.end_headers() + self.wfile.write(b'Ok.') + return + package_name = basename.split('.', 1)[0] or 'subyshare' fname = f'{WATCH_DIR}/{int(time.time()*1000)}.crawljob' with open(fname, 'w') as f: