feat: enhance JDownloader script to handle .torrent files and save them to output directory
Some checks failed
validate / lint (push) Failing after 1s
Some checks failed
validate / lint (push) Failing after 1s
This commit is contained in:
parent
fb3e2976e2
commit
c354e6c39f
@ -122,13 +122,16 @@ spec:
|
|||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: config
|
- name: config
|
||||||
mountPath: /config
|
mountPath: /config
|
||||||
|
- name: dl
|
||||||
|
mountPath: /output
|
||||||
command:
|
command:
|
||||||
- python3
|
- python3
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
import http.server, urllib.parse, os, time
|
import http.server, urllib.parse, urllib.request, os, time
|
||||||
|
|
||||||
WATCH_DIR = '/config/folderwatch'
|
WATCH_DIR = '/config/folderwatch'
|
||||||
|
TORRENT_DIR = '/output'
|
||||||
os.makedirs(WATCH_DIR, exist_ok=True)
|
os.makedirs(WATCH_DIR, exist_ok=True)
|
||||||
|
|
||||||
class Handler(http.server.BaseHTTPRequestHandler):
|
class Handler(http.server.BaseHTTPRequestHandler):
|
||||||
@ -143,6 +146,27 @@ spec:
|
|||||||
self.send_response(400); self.end_headers(); return
|
self.send_response(400); self.end_headers(); return
|
||||||
url = urls[0]
|
url = urls[0]
|
||||||
basename = urllib.parse.unquote(urllib.parse.urlparse(url).path.rsplit('/', 1)[-1])
|
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'
|
package_name = basename.split('.', 1)[0] or 'subyshare'
|
||||||
fname = f'{WATCH_DIR}/{int(time.time()*1000)}.crawljob'
|
fname = f'{WATCH_DIR}/{int(time.time()*1000)}.crawljob'
|
||||||
with open(fname, 'w') as f:
|
with open(fname, 'w') as f:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user