nexus33rd commited on
Commit
dc42ed2
·
verified ·
1 Parent(s): 3733fe4

Upload 18 files

Browse files
Files changed (3) hide show
  1. README.md +3 -1
  2. app.py +214 -5
  3. templates/index.html +27 -7
README.md CHANGED
@@ -18,7 +18,7 @@ Fitur utama:
18
  - status torrent realtime
19
  - pause, resume, delete
20
  - auto cancel untuk torrent stuck
21
- - upload file selesai ke GoFile
22
  - panel ringkasan server dan speedtest
23
 
24
  ## Jalankan Dengan Docker
@@ -72,6 +72,8 @@ Proyek sekarang memakai satu `Dockerfile` default. File [docker-compose.yml](./d
72
  - `QBITTORRENT_SAVE_PATH`: direktori hasil download. Default `/downloads`, atau `/data/downloads` bila `/data` tersedia
73
  - `GOFILE_API_TOKEN`: token opsional untuk GoFile
74
  - `GOFILE_UPLOAD_URLS`: daftar endpoint upload GoFile dipisahkan koma. Default mencoba beberapa server resmi GoFile dan otomatis mengurutkannya berdasarkan latency terdekat
 
 
75
  - `IP_LOCATION_API_URL`: endpoint lookup lokasi. Default `https://ipapi.co/json/`
76
  - `TORRENT_STUCK_TIMEOUT_MINUTES`: timeout torrent stuck. Default `5`
77
 
 
18
  - status torrent realtime
19
  - pause, resume, delete
20
  - auto cancel untuk torrent stuck
21
+ - upload file selesai ke GoFile atau PixelDrain
22
  - panel ringkasan server dan speedtest
23
 
24
  ## Jalankan Dengan Docker
 
72
  - `QBITTORRENT_SAVE_PATH`: direktori hasil download. Default `/downloads`, atau `/data/downloads` bila `/data` tersedia
73
  - `GOFILE_API_TOKEN`: token opsional untuk GoFile
74
  - `GOFILE_UPLOAD_URLS`: daftar endpoint upload GoFile dipisahkan koma. Default mencoba beberapa server resmi GoFile dan otomatis mengurutkannya berdasarkan latency terdekat
75
+ - `PIXELDRAIN_API_KEY`: API key PixelDrain untuk upload via API
76
+ - `PIXELDRAIN_API_URL`: base API PixelDrain. Default `https://pixeldrain.com/api`
77
  - `IP_LOCATION_API_URL`: endpoint lookup lokasi. Default `https://ipapi.co/json/`
78
  - `TORRENT_STUCK_TIMEOUT_MINUTES`: timeout torrent stuck. Default `5`
79
 
app.py CHANGED
@@ -8,7 +8,7 @@ import subprocess
8
  import threading
9
  import time
10
  from pathlib import Path
11
- from urllib.parse import urlparse
12
 
13
  from flask import Flask, flash, jsonify, redirect, render_template, request, url_for
14
  import psutil
@@ -154,6 +154,8 @@ def cancel_upload_process(pid: int | None) -> bool:
154
 
155
  GOFILE_UPLOAD_URLS = parse_gofile_upload_urls()
156
  GOFILE_API_TOKEN = env("GOFILE_API_TOKEN", "")
 
 
157
  IP_LOCATION_API_URL = env("IP_LOCATION_API_URL", "https://ipapi.co/json/")
158
  CLOUDFLARE_DOWNLOAD_URL = env("CLOUDFLARE_DOWNLOAD_URL", "https://speed.cloudflare.com/__down")
159
  CLOUDFLARE_UPLOAD_URL = env("CLOUDFLARE_UPLOAD_URL", "https://speed.cloudflare.com/__up")
@@ -390,10 +392,11 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
390
  status_message = state_entry.get("status_message", "")
391
  content_path = Path(getattr(torrent, "content_path", "") or "")
392
  gofile_uploading = bool(state_entry.get("gofile_uploading"))
 
393
  gofile_progress = int(state_entry.get("gofile_progress", 0) or 0)
394
  gofile_eta_seconds = int(state_entry.get("gofile_eta_seconds", 0) or 0)
395
  display_progress = gofile_progress if gofile_uploading else progress_percent(torrent_progress)
396
- progress_label = "GoFile Upload" if gofile_uploading else "Progress"
397
  gofile_speed = state_entry.get("gofile_speed", "")
398
  if gofile_uploading:
399
  eta_text = human_eta(gofile_eta_seconds)
@@ -402,7 +405,7 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
402
  else:
403
  eta_text = human_eta(eta_value)
404
  display_speed = gofile_speed if gofile_uploading else format_speed(torrent_dlspeed)
405
- display_speed_label = "GoFile Upload" if gofile_uploading else "Download"
406
  if not gofile_uploading and torrent_progress >= 1 and torrent_upspeed > 0:
407
  display_speed = format_speed(torrent_upspeed)
408
  display_speed_label = "Seed Upload"
@@ -442,8 +445,10 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
442
  "gofile_speed": gofile_speed,
443
  "gofile_eta": human_eta(gofile_eta_seconds) if gofile_uploading else "-",
444
  "gofile_endpoint": state_entry.get("gofile_endpoint", ""),
 
445
  "can_copy_link": bool(state_entry.get("gofile_link")),
446
  "can_cancel_gofile_upload": gofile_uploading,
 
447
  }
448
 
449
 
@@ -463,6 +468,7 @@ def clear_gofile_runtime_fields(entry: dict) -> None:
463
  entry["gofile_cancel_requested"] = False
464
  entry["gofile_pid"] = 0
465
  entry["gofile_endpoint"] = ""
 
466
 
467
 
468
  def evaluate_torrent_health(client, torrents: list, state: dict) -> bool:
@@ -495,6 +501,7 @@ def evaluate_torrent_health(client, torrents: list, state: dict) -> bool:
495
  "gofile_link": "",
496
  "gofile_pid": 0,
497
  "gofile_endpoint": "",
 
498
  },
499
  )
500
 
@@ -759,7 +766,7 @@ def monitor_curl_progress(stderr_pipe, torrent_hash: str, total_bytes: int, uplo
759
  "gofile_progress": progress["progress"],
760
  "gofile_speed": speed_text,
761
  "gofile_eta_seconds": progress["eta_seconds"],
762
- "gofile_status": f"Sedang upload ke GoFile via {upload_label}...",
763
  "status_message": "",
764
  }
765
  )
@@ -836,6 +843,7 @@ def gofile_upload_attempt(
836
  "gofile_uploading": True,
837
  "gofile_pid": process.pid,
838
  "gofile_endpoint": upload_label,
 
839
  "gofile_status": f"Sedang upload ke GoFile via {upload_label}...",
840
  "status_message": "",
841
  }
@@ -859,6 +867,7 @@ def gofile_upload_attempt(
859
  "gofile_uploading": True,
860
  "gofile_pid": process.pid,
861
  "gofile_endpoint": upload_label,
 
862
  "gofile_status": f"Sedang upload ke GoFile via {upload_label}...",
863
  "status_message": "",
864
  }
@@ -883,6 +892,110 @@ def gofile_upload_attempt(
883
  return payload
884
 
885
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886
  def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_path: Path) -> None:
887
  def worker():
888
  try:
@@ -901,6 +1014,7 @@ def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_pa
901
  lambda state: state.setdefault("torrents", {}).setdefault(torrent_hash, {}).update(
902
  {
903
  "gofile_uploading": True,
 
904
  "gofile_status": f"Endpoint gagal, mencoba server lain: {upload_url}",
905
  "status_message": f"Endpoint gagal, mencoba server lain: {upload_url}",
906
  }
@@ -919,6 +1033,7 @@ def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_pa
919
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
920
  clear_gofile_runtime_fields(entry)
921
  entry["gofile_link"] = download_page
 
922
  entry["gofile_status"] = f"Upload GoFile berhasil: {download_page}"
923
  entry["status_message"] = "Upload GoFile selesai. Link siap disalin."
924
 
@@ -927,6 +1042,7 @@ def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_pa
927
  def cancel_mutator(state: dict):
928
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
929
  clear_gofile_runtime_fields(entry)
 
930
  entry["gofile_status"] = "Upload GoFile dibatalkan."
931
  entry["status_message"] = "Upload GoFile dibatalkan."
932
  add_event(state, "warning", f"Upload GoFile dibatalkan untuk {torrent_name}.")
@@ -936,6 +1052,7 @@ def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_pa
936
  def error_mutator(state: dict):
937
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
938
  clear_gofile_runtime_fields(entry)
 
939
  entry["gofile_status"] = f"Upload GoFile gagal: {exc}"
940
  entry["status_message"] = f"Upload GoFile gagal: {exc}"
941
  add_event(state, "error", f"Upload GoFile gagal untuk {torrent_name}: {exc}")
@@ -948,6 +1065,51 @@ def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_pa
948
  thread.start()
949
 
950
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
  @app.route("/", methods=["GET"])
952
  def index():
953
  try:
@@ -1095,6 +1257,7 @@ def upload_torrent_to_gofile(torrent_hash: str):
1095
  entry["gofile_cancel_requested"] = False
1096
  entry["gofile_pid"] = 0
1097
  entry["gofile_endpoint"] = ""
 
1098
  entry["gofile_status"] = "Sedang upload ke GoFile..."
1099
  entry["status_message"] = ""
1100
  save_monitor_state(state)
@@ -1112,11 +1275,57 @@ def cancel_gofile_upload(torrent_hash: str):
1112
  if not entry or not entry.get("gofile_uploading"):
1113
  return action_response("Upload GoFile tidak sedang berjalan.", ok=False, status_code=409)
1114
 
 
1115
  entry["gofile_cancel_requested"] = True
1116
  entry["status_message"] = "Membatalkan upload GoFile..."
1117
  save_monitor_state(state)
1118
  cancel_upload_process(int(entry.get("gofile_pid", 0) or 0))
1119
- return action_response("Pembatalan upload GoFile diproses.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1120
 
1121
 
1122
  @app.route("/add-magnet", methods=["POST"])
 
8
  import threading
9
  import time
10
  from pathlib import Path
11
+ from urllib.parse import quote, urlparse
12
 
13
  from flask import Flask, flash, jsonify, redirect, render_template, request, url_for
14
  import psutil
 
154
 
155
  GOFILE_UPLOAD_URLS = parse_gofile_upload_urls()
156
  GOFILE_API_TOKEN = env("GOFILE_API_TOKEN", "")
157
+ PIXELDRAIN_API_KEY = env("PIXELDRAIN_API_KEY", "f315f659-0e6e-4cce-bdc1-2b0d654c8f51")
158
+ PIXELDRAIN_API_URL = env("PIXELDRAIN_API_URL", "https://pixeldrain.com/api")
159
  IP_LOCATION_API_URL = env("IP_LOCATION_API_URL", "https://ipapi.co/json/")
160
  CLOUDFLARE_DOWNLOAD_URL = env("CLOUDFLARE_DOWNLOAD_URL", "https://speed.cloudflare.com/__down")
161
  CLOUDFLARE_UPLOAD_URL = env("CLOUDFLARE_UPLOAD_URL", "https://speed.cloudflare.com/__up")
 
392
  status_message = state_entry.get("status_message", "")
393
  content_path = Path(getattr(torrent, "content_path", "") or "")
394
  gofile_uploading = bool(state_entry.get("gofile_uploading"))
395
+ upload_provider = state_entry.get("gofile_provider", "GoFile")
396
  gofile_progress = int(state_entry.get("gofile_progress", 0) or 0)
397
  gofile_eta_seconds = int(state_entry.get("gofile_eta_seconds", 0) or 0)
398
  display_progress = gofile_progress if gofile_uploading else progress_percent(torrent_progress)
399
+ progress_label = f"{upload_provider} Upload" if gofile_uploading else "Progress"
400
  gofile_speed = state_entry.get("gofile_speed", "")
401
  if gofile_uploading:
402
  eta_text = human_eta(gofile_eta_seconds)
 
405
  else:
406
  eta_text = human_eta(eta_value)
407
  display_speed = gofile_speed if gofile_uploading else format_speed(torrent_dlspeed)
408
+ display_speed_label = f"{upload_provider} Upload" if gofile_uploading else "Download"
409
  if not gofile_uploading and torrent_progress >= 1 and torrent_upspeed > 0:
410
  display_speed = format_speed(torrent_upspeed)
411
  display_speed_label = "Seed Upload"
 
445
  "gofile_speed": gofile_speed,
446
  "gofile_eta": human_eta(gofile_eta_seconds) if gofile_uploading else "-",
447
  "gofile_endpoint": state_entry.get("gofile_endpoint", ""),
448
+ "upload_provider": upload_provider,
449
  "can_copy_link": bool(state_entry.get("gofile_link")),
450
  "can_cancel_gofile_upload": gofile_uploading,
451
+ "can_pixeldrain_upload": can_gofile_upload and bool(PIXELDRAIN_API_KEY),
452
  }
453
 
454
 
 
468
  entry["gofile_cancel_requested"] = False
469
  entry["gofile_pid"] = 0
470
  entry["gofile_endpoint"] = ""
471
+ entry["gofile_provider"] = ""
472
 
473
 
474
  def evaluate_torrent_health(client, torrents: list, state: dict) -> bool:
 
501
  "gofile_link": "",
502
  "gofile_pid": 0,
503
  "gofile_endpoint": "",
504
+ "gofile_provider": "",
505
  },
506
  )
507
 
 
766
  "gofile_progress": progress["progress"],
767
  "gofile_speed": speed_text,
768
  "gofile_eta_seconds": progress["eta_seconds"],
769
+ "gofile_status": f"Sedang upload ke {state.setdefault('torrents', {}).setdefault(torrent_hash, {}).get('gofile_provider', 'GoFile')} via {upload_label}...",
770
  "status_message": "",
771
  }
772
  )
 
843
  "gofile_uploading": True,
844
  "gofile_pid": process.pid,
845
  "gofile_endpoint": upload_label,
846
+ "gofile_provider": "GoFile",
847
  "gofile_status": f"Sedang upload ke GoFile via {upload_label}...",
848
  "status_message": "",
849
  }
 
867
  "gofile_uploading": True,
868
  "gofile_pid": process.pid,
869
  "gofile_endpoint": upload_label,
870
+ "gofile_provider": "GoFile",
871
  "gofile_status": f"Sedang upload ke GoFile via {upload_label}...",
872
  "status_message": "",
873
  }
 
892
  return payload
893
 
894
 
895
+ def pixeldrain_upload_attempt(torrent_hash: str, file_path: Path, started_at: float) -> dict:
896
+ response_path = UPLOAD_DIR / f"pixeldrain-{torrent_hash}.json"
897
+ encoded_name = quote(file_path.name, safe="")
898
+ upload_url = f"{PIXELDRAIN_API_URL}/file/{encoded_name}"
899
+ command = [
900
+ "curl",
901
+ "--show-error",
902
+ "--location",
903
+ "--ipv4",
904
+ "--retry",
905
+ "2",
906
+ "--retry-delay",
907
+ "2",
908
+ "--retry-all-errors",
909
+ "--connect-timeout",
910
+ "15",
911
+ "--speed-time",
912
+ "60",
913
+ "--speed-limit",
914
+ "10240",
915
+ "--max-time",
916
+ "0",
917
+ "--upload-file",
918
+ str(file_path),
919
+ "--user",
920
+ f":{PIXELDRAIN_API_KEY}",
921
+ "--output",
922
+ str(response_path),
923
+ "--write-out",
924
+ "%{http_code}",
925
+ upload_url,
926
+ ]
927
+
928
+ process = subprocess.Popen(
929
+ command,
930
+ stdout=subprocess.PIPE,
931
+ stderr=subprocess.PIPE,
932
+ text=True,
933
+ bufsize=1,
934
+ )
935
+ total_bytes = file_path.stat().st_size
936
+ upload_label = "pixeldrain"
937
+ error_lines: list[str] = []
938
+ monitor_thread = threading.Thread(
939
+ target=monitor_curl_progress,
940
+ args=(process.stderr, torrent_hash, total_bytes, upload_label, error_lines),
941
+ daemon=True,
942
+ )
943
+ monitor_thread.start()
944
+
945
+ update_state(
946
+ lambda state: state.setdefault("torrents", {}).setdefault(torrent_hash, {}).update(
947
+ {
948
+ "gofile_uploading": True,
949
+ "gofile_pid": process.pid,
950
+ "gofile_endpoint": upload_label,
951
+ "gofile_provider": "PixelDrain",
952
+ "gofile_status": "Sedang upload ke PixelDrain...",
953
+ "status_message": "",
954
+ }
955
+ )
956
+ )
957
+
958
+ while True:
959
+ return_code = process.poll()
960
+ current_state = load_monitor_state()
961
+ current_entry = current_state.setdefault("torrents", {}).setdefault(torrent_hash, {})
962
+ if current_entry.get("gofile_cancel_requested"):
963
+ cancel_upload_process(process.pid)
964
+
965
+ if return_code is not None:
966
+ break
967
+
968
+ update_state(
969
+ lambda state: state.setdefault("torrents", {}).setdefault(torrent_hash, {}).update(
970
+ {
971
+ "gofile_uploading": True,
972
+ "gofile_pid": process.pid,
973
+ "gofile_endpoint": upload_label,
974
+ "gofile_provider": "PixelDrain",
975
+ "gofile_status": "Sedang upload ke PixelDrain...",
976
+ "status_message": "",
977
+ }
978
+ )
979
+ )
980
+ time.sleep(1)
981
+
982
+ stdout = process.stdout.read() if process.stdout else ""
983
+ monitor_thread.join(timeout=1)
984
+ if current_entry.get("gofile_cancel_requested") or process.returncode == -15:
985
+ raise GofileUploadCancelled("Upload PixelDrain dibatalkan.")
986
+ if process.returncode != 0:
987
+ error_detail = " | ".join(error_lines[-3:]).strip() or stdout.strip() or f"curl exited with code {process.returncode}"
988
+ raise ValueError(error_detail)
989
+
990
+ http_code = int((stdout or "0").strip() or "0")
991
+ if http_code >= 400 or http_code == 0:
992
+ error_body = response_path.read_text(encoding="utf-8", errors="replace") if response_path.exists() else ""
993
+ raise ValueError(f"HTTP {http_code}: {error_body[:500]}".strip())
994
+
995
+ payload = json.loads(response_path.read_text(encoding="utf-8"))
996
+ return payload
997
+
998
+
999
  def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_path: Path) -> None:
1000
  def worker():
1001
  try:
 
1014
  lambda state: state.setdefault("torrents", {}).setdefault(torrent_hash, {}).update(
1015
  {
1016
  "gofile_uploading": True,
1017
+ "gofile_provider": "GoFile",
1018
  "gofile_status": f"Endpoint gagal, mencoba server lain: {upload_url}",
1019
  "status_message": f"Endpoint gagal, mencoba server lain: {upload_url}",
1020
  }
 
1033
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1034
  clear_gofile_runtime_fields(entry)
1035
  entry["gofile_link"] = download_page
1036
+ entry["gofile_provider"] = "GoFile"
1037
  entry["gofile_status"] = f"Upload GoFile berhasil: {download_page}"
1038
  entry["status_message"] = "Upload GoFile selesai. Link siap disalin."
1039
 
 
1042
  def cancel_mutator(state: dict):
1043
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1044
  clear_gofile_runtime_fields(entry)
1045
+ entry["gofile_provider"] = "GoFile"
1046
  entry["gofile_status"] = "Upload GoFile dibatalkan."
1047
  entry["status_message"] = "Upload GoFile dibatalkan."
1048
  add_event(state, "warning", f"Upload GoFile dibatalkan untuk {torrent_name}.")
 
1052
  def error_mutator(state: dict):
1053
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1054
  clear_gofile_runtime_fields(entry)
1055
+ entry["gofile_provider"] = "GoFile"
1056
  entry["gofile_status"] = f"Upload GoFile gagal: {exc}"
1057
  entry["status_message"] = f"Upload GoFile gagal: {exc}"
1058
  add_event(state, "error", f"Upload GoFile gagal untuk {torrent_name}: {exc}")
 
1065
  thread.start()
1066
 
1067
 
1068
+ def start_pixeldrain_upload_background(torrent_hash: str, torrent_name: str, file_path: Path) -> None:
1069
+ def worker():
1070
+ try:
1071
+ payload = pixeldrain_upload_attempt(torrent_hash, file_path, time.time())
1072
+ file_id = payload.get("id")
1073
+ if not file_id:
1074
+ raise ValueError("Respons PixelDrain tidak mengandung file id.")
1075
+ download_page = f"https://pixeldrain.com/u/{file_id}"
1076
+
1077
+ def success_mutator(state: dict):
1078
+ entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1079
+ clear_gofile_runtime_fields(entry)
1080
+ entry["gofile_link"] = download_page
1081
+ entry["gofile_provider"] = "PixelDrain"
1082
+ entry["gofile_status"] = f"Upload PixelDrain berhasil: {download_page}"
1083
+ entry["status_message"] = "Upload PixelDrain selesai. Link siap disalin."
1084
+
1085
+ update_state(success_mutator)
1086
+ except GofileUploadCancelled:
1087
+ def cancel_mutator(state: dict):
1088
+ entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1089
+ clear_gofile_runtime_fields(entry)
1090
+ entry["gofile_provider"] = "PixelDrain"
1091
+ entry["gofile_status"] = "Upload PixelDrain dibatalkan."
1092
+ entry["status_message"] = "Upload PixelDrain dibatalkan."
1093
+ add_event(state, "warning", f"Upload PixelDrain dibatalkan untuk {torrent_name}.")
1094
+
1095
+ update_state(cancel_mutator)
1096
+ except ValueError as exc:
1097
+ def error_mutator(state: dict):
1098
+ entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1099
+ clear_gofile_runtime_fields(entry)
1100
+ entry["gofile_provider"] = "PixelDrain"
1101
+ entry["gofile_status"] = f"Upload PixelDrain gagal: {exc}"
1102
+ entry["status_message"] = f"Upload PixelDrain gagal: {exc}"
1103
+ add_event(state, "error", f"Upload PixelDrain gagal untuk {torrent_name}: {exc}")
1104
+
1105
+ update_state(error_mutator)
1106
+ finally:
1107
+ (UPLOAD_DIR / f"pixeldrain-{torrent_hash}.json").unlink(missing_ok=True)
1108
+
1109
+ thread = threading.Thread(target=worker, daemon=True)
1110
+ thread.start()
1111
+
1112
+
1113
  @app.route("/", methods=["GET"])
1114
  def index():
1115
  try:
 
1257
  entry["gofile_cancel_requested"] = False
1258
  entry["gofile_pid"] = 0
1259
  entry["gofile_endpoint"] = ""
1260
+ entry["gofile_provider"] = "GoFile"
1261
  entry["gofile_status"] = "Sedang upload ke GoFile..."
1262
  entry["status_message"] = ""
1263
  save_monitor_state(state)
 
1275
  if not entry or not entry.get("gofile_uploading"):
1276
  return action_response("Upload GoFile tidak sedang berjalan.", ok=False, status_code=409)
1277
 
1278
+ provider = entry.get("gofile_provider", "upload")
1279
  entry["gofile_cancel_requested"] = True
1280
  entry["status_message"] = "Membatalkan upload GoFile..."
1281
  save_monitor_state(state)
1282
  cancel_upload_process(int(entry.get("gofile_pid", 0) or 0))
1283
+ return action_response(f"Pembatalan upload {provider} diproses.")
1284
+
1285
+
1286
+ @app.route("/api/torrents/<torrent_hash>/upload-pixeldrain", methods=["POST"])
1287
+ def upload_torrent_to_pixeldrain(torrent_hash: str):
1288
+ if not PIXELDRAIN_API_KEY:
1289
+ return action_response("PIXELDRAIN_API_KEY belum diset.", ok=False, status_code=400)
1290
+
1291
+ try:
1292
+ client = get_client()
1293
+ torrents = client.torrents_info(torrent_hashes=torrent_hash)
1294
+ if not torrents:
1295
+ return action_response("Torrent tidak ditemukan.", ok=False, status_code=404)
1296
+
1297
+ torrent = torrents[0]
1298
+ progress = float(getattr(torrent, "progress", 0) or 0)
1299
+ if progress < 1:
1300
+ return action_response("Upload ke PixelDrain hanya tersedia setelah download selesai.", ok=False, status_code=400)
1301
+
1302
+ content_path = Path(getattr(torrent, "content_path", "") or "")
1303
+ if not content_path.exists():
1304
+ return action_response("File hasil download tidak ditemukan di storage.", ok=False, status_code=404)
1305
+ if content_path.is_dir():
1306
+ return action_response("Upload PixelDrain saat ini hanya mendukung torrent single-file.", ok=False, status_code=400)
1307
+
1308
+ state = load_monitor_state()
1309
+ entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1310
+ if entry.get("gofile_uploading"):
1311
+ return action_response("Upload file eksternal masih berjalan.", ok=False, status_code=409)
1312
+
1313
+ entry["gofile_uploading"] = True
1314
+ entry["gofile_progress"] = 0
1315
+ entry["gofile_speed"] = ""
1316
+ entry["gofile_eta_seconds"] = 0
1317
+ entry["gofile_cancel_requested"] = False
1318
+ entry["gofile_pid"] = 0
1319
+ entry["gofile_endpoint"] = "pixeldrain"
1320
+ entry["gofile_provider"] = "PixelDrain"
1321
+ entry["gofile_status"] = "Sedang upload ke PixelDrain..."
1322
+ entry["status_message"] = ""
1323
+ save_monitor_state(state)
1324
+
1325
+ start_pixeldrain_upload_background(torrent_hash, torrent.name, content_path)
1326
+ return action_response("Upload ke PixelDrain dimulai.")
1327
+ except qbittorrentapi.APIError as exc:
1328
+ return action_response(f"Gagal memulai upload PixelDrain: {exc}", ok=False, status_code=502)
1329
 
1330
 
1331
  @app.route("/add-magnet", methods=["POST"])
templates/index.html CHANGED
@@ -70,7 +70,7 @@
70
  <div class="grid grid-cols-2 gap-3 text-sm text-stone-300 sm:block">
71
  <div>{{ torrent.total_size }}</div>
72
  <div class="text-xs uppercase tracking-[0.2em] text-stone-500">{{ torrent.display_speed_label }}</div>
73
- {% if torrent.gofile_uploading %}
74
  <div class="text-sky-300">{{ torrent.display_speed }}</div>
75
  {% else %}
76
  <div class="text-emerald-300">{{ torrent.display_speed }}</div>
@@ -84,7 +84,7 @@
84
  <span>{{ torrent.progress }}%</span>
85
  </div>
86
  <div class="h-2 rounded-full bg-white/10">
87
- <div class="h-2 rounded-full {% if torrent.gofile_uploading %}bg-sky-400{% else %}bg-emerald-400{% endif %}" style="width: {{ torrent.progress }}%"></div>
88
  </div>
89
  </div>
90
 
@@ -131,12 +131,17 @@
131
  <i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile
132
  </button>
133
  {% endif %}
 
 
 
 
 
134
  </div>
135
 
136
  {% if torrent.gofile_link %}
137
  <div class="mt-4 rounded-2xl border border-sky-500/20 bg-sky-500/10 px-4 py-4 text-sm text-sky-100">
138
  <p class="font-semibold text-sky-50">Upload Complete.</p>
139
- <p class="mt-1 text-sky-200/90">GoFile Link:</p>
140
  <div class="mt-3 flex flex-col gap-2 rounded-2xl border border-white/10 bg-stone-950/70 p-2 sm:flex-row sm:items-center">
141
  <code class="min-w-0 flex-1 break-all px-2 py-2 text-xs text-cyan-200 sm:text-sm">{{ torrent.gofile_link }}</code>
142
  <button type="button" data-action="copy-link" data-link="{{ torrent.gofile_link }}" class="shrink-0 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs font-medium text-stone-200 transition hover:bg-white/10 sm:w-auto">
@@ -397,6 +402,9 @@
397
  if (torrent.can_gofile_upload) {
398
  buttons.push(`<button type="button" data-action="upload-gofile" data-hash="${escapeHtml(torrent.hash)}" class="inline-flex w-full items-center justify-center rounded-2xl border border-sky-400/30 bg-sky-400/10 px-4 py-2 text-sm font-medium text-sky-100 transition hover:bg-sky-400/20 sm:w-auto"><i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile</button>`);
399
  }
 
 
 
400
  return buttons.join("");
401
  }
402
 
@@ -407,7 +415,7 @@
407
  const gofileBlock = torrent.gofile_link
408
  ? `<div class="mt-4 rounded-2xl border border-sky-500/20 bg-sky-500/10 px-4 py-4 text-sm text-sky-100">
409
  <p class="font-semibold text-sky-50">Upload Complete.</p>
410
- <p class="mt-1 text-sky-200/90">GoFile Link:</p>
411
  <div class="mt-3 flex flex-col gap-2 rounded-2xl border border-white/10 bg-stone-950/70 p-2 sm:flex-row sm:items-center">
412
  <code class="min-w-0 flex-1 break-all px-2 py-2 text-xs text-cyan-200 sm:text-sm">${escapeHtml(torrent.gofile_link)}</code>
413
  <button type="button" data-action="copy-link" data-link="${escapeHtml(torrent.gofile_link)}" class="shrink-0 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs font-medium text-stone-200 transition hover:bg-white/10 sm:w-auto">
@@ -446,7 +454,7 @@
446
  <span>${torrent.progress}%</span>
447
  </div>
448
  <div class="h-2 rounded-full bg-white/10">
449
- <div class="h-2 rounded-full ${progressColor} transition-all duration-700" style="width: ${torrent.progress}%"></div>
450
  </div>
451
  </div>
452
  <div class="mt-4 grid grid-cols-2 gap-3 text-sm text-stone-300 lg:grid-cols-4">
@@ -467,6 +475,13 @@
467
  versionValue.textContent = versionText;
468
  }
469
 
 
 
 
 
 
 
 
470
  function updateSystemInfo(system) {
471
  document.getElementById("system-os").textContent = system.os || "-";
472
  document.getElementById("system-cpu").textContent = system.cpu || "-";
@@ -526,6 +541,7 @@
526
  renderEmptyState();
527
  } else {
528
  torrentList.innerHTML = data.torrents.map(renderTorrent).join("");
 
529
  }
530
 
531
  await refreshSystem();
@@ -557,8 +573,11 @@
557
  if (action === "upload-gofile") {
558
  showToast(payload.message || "Upload GoFile dimulai.");
559
  }
 
 
 
560
  if (action === "copy-link") {
561
- showToast("Link GoFile berhasil disalin.");
562
  }
563
  await refreshTorrents();
564
  }
@@ -613,7 +632,7 @@
613
  if (button.dataset.action === "copy-link") {
614
  try {
615
  await navigator.clipboard.writeText(button.dataset.link || "");
616
- showToast("Link GoFile berhasil disalin.");
617
  } catch (error) {
618
  showToast("Gagal menyalin link.", "error");
619
  }
@@ -658,6 +677,7 @@
658
  });
659
 
660
  refreshTorrents();
 
661
  setInterval(refreshTorrents, 3000);
662
  </script>
663
  </body>
 
70
  <div class="grid grid-cols-2 gap-3 text-sm text-stone-300 sm:block">
71
  <div>{{ torrent.total_size }}</div>
72
  <div class="text-xs uppercase tracking-[0.2em] text-stone-500">{{ torrent.display_speed_label }}</div>
73
+ {% if torrent.gofile_uploading %}
74
  <div class="text-sky-300">{{ torrent.display_speed }}</div>
75
  {% else %}
76
  <div class="text-emerald-300">{{ torrent.display_speed }}</div>
 
84
  <span>{{ torrent.progress }}%</span>
85
  </div>
86
  <div class="h-2 rounded-full bg-white/10">
87
+ <div class="progress-fill h-2 rounded-full {% if torrent.gofile_uploading %}bg-sky-400{% else %}bg-emerald-400{% endif %}" data-progress="{{ torrent.progress }}"></div>
88
  </div>
89
  </div>
90
 
 
131
  <i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile
132
  </button>
133
  {% endif %}
134
+ {% if torrent.can_pixeldrain_upload %}
135
+ <button type="button" data-action="upload-pixeldrain" data-hash="{{ torrent.hash }}" class="inline-flex w-full items-center justify-center rounded-2xl border border-fuchsia-400/30 bg-fuchsia-400/10 px-4 py-2 text-sm font-medium text-fuchsia-100 transition hover:bg-fuchsia-400/20 sm:w-auto">
136
+ <i class="fa-solid fa-hard-drive mr-2"></i>Upload PixelDrain
137
+ </button>
138
+ {% endif %}
139
  </div>
140
 
141
  {% if torrent.gofile_link %}
142
  <div class="mt-4 rounded-2xl border border-sky-500/20 bg-sky-500/10 px-4 py-4 text-sm text-sky-100">
143
  <p class="font-semibold text-sky-50">Upload Complete.</p>
144
+ <p class="mt-1 text-sky-200/90">{{ torrent.upload_provider }} Link:</p>
145
  <div class="mt-3 flex flex-col gap-2 rounded-2xl border border-white/10 bg-stone-950/70 p-2 sm:flex-row sm:items-center">
146
  <code class="min-w-0 flex-1 break-all px-2 py-2 text-xs text-cyan-200 sm:text-sm">{{ torrent.gofile_link }}</code>
147
  <button type="button" data-action="copy-link" data-link="{{ torrent.gofile_link }}" class="shrink-0 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs font-medium text-stone-200 transition hover:bg-white/10 sm:w-auto">
 
402
  if (torrent.can_gofile_upload) {
403
  buttons.push(`<button type="button" data-action="upload-gofile" data-hash="${escapeHtml(torrent.hash)}" class="inline-flex w-full items-center justify-center rounded-2xl border border-sky-400/30 bg-sky-400/10 px-4 py-2 text-sm font-medium text-sky-100 transition hover:bg-sky-400/20 sm:w-auto"><i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile</button>`);
404
  }
405
+ if (torrent.can_pixeldrain_upload) {
406
+ buttons.push(`<button type="button" data-action="upload-pixeldrain" data-hash="${escapeHtml(torrent.hash)}" class="inline-flex w-full items-center justify-center rounded-2xl border border-fuchsia-400/30 bg-fuchsia-400/10 px-4 py-2 text-sm font-medium text-fuchsia-100 transition hover:bg-fuchsia-400/20 sm:w-auto"><i class="fa-solid fa-hard-drive mr-2"></i>Upload PixelDrain</button>`);
407
+ }
408
  return buttons.join("");
409
  }
410
 
 
415
  const gofileBlock = torrent.gofile_link
416
  ? `<div class="mt-4 rounded-2xl border border-sky-500/20 bg-sky-500/10 px-4 py-4 text-sm text-sky-100">
417
  <p class="font-semibold text-sky-50">Upload Complete.</p>
418
+ <p class="mt-1 text-sky-200/90">${escapeHtml(torrent.upload_provider || "Remote Upload")} Link:</p>
419
  <div class="mt-3 flex flex-col gap-2 rounded-2xl border border-white/10 bg-stone-950/70 p-2 sm:flex-row sm:items-center">
420
  <code class="min-w-0 flex-1 break-all px-2 py-2 text-xs text-cyan-200 sm:text-sm">${escapeHtml(torrent.gofile_link)}</code>
421
  <button type="button" data-action="copy-link" data-link="${escapeHtml(torrent.gofile_link)}" class="shrink-0 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs font-medium text-stone-200 transition hover:bg-white/10 sm:w-auto">
 
454
  <span>${torrent.progress}%</span>
455
  </div>
456
  <div class="h-2 rounded-full bg-white/10">
457
+ <div class="progress-fill h-2 rounded-full ${progressColor} transition-all duration-700" data-progress="${torrent.progress}"></div>
458
  </div>
459
  </div>
460
  <div class="mt-4 grid grid-cols-2 gap-3 text-sm text-stone-300 lg:grid-cols-4">
 
475
  versionValue.textContent = versionText;
476
  }
477
 
478
+ function applyProgressBars() {
479
+ document.querySelectorAll(".progress-fill").forEach((element) => {
480
+ const progress = Number(element.dataset.progress || "0");
481
+ element.style.width = `${Math.max(0, Math.min(progress, 100))}%`;
482
+ });
483
+ }
484
+
485
  function updateSystemInfo(system) {
486
  document.getElementById("system-os").textContent = system.os || "-";
487
  document.getElementById("system-cpu").textContent = system.cpu || "-";
 
541
  renderEmptyState();
542
  } else {
543
  torrentList.innerHTML = data.torrents.map(renderTorrent).join("");
544
+ applyProgressBars();
545
  }
546
 
547
  await refreshSystem();
 
573
  if (action === "upload-gofile") {
574
  showToast(payload.message || "Upload GoFile dimulai.");
575
  }
576
+ if (action === "upload-pixeldrain") {
577
+ showToast(payload.message || "Upload PixelDrain dimulai.");
578
+ }
579
  if (action === "copy-link") {
580
+ showToast("Link berhasil disalin.");
581
  }
582
  await refreshTorrents();
583
  }
 
632
  if (button.dataset.action === "copy-link") {
633
  try {
634
  await navigator.clipboard.writeText(button.dataset.link || "");
635
+ showToast("Link berhasil disalin.");
636
  } catch (error) {
637
  showToast("Gagal menyalin link.", "error");
638
  }
 
677
  });
678
 
679
  refreshTorrents();
680
+ applyProgressBars();
681
  setInterval(refreshTorrents, 3000);
682
  </script>
683
  </body>