Spaces:
Paused
Paused
Upload 18 files
Browse files
app.py
CHANGED
|
@@ -408,7 +408,10 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
|
|
| 408 |
gofile_progress = int(state_entry.get("gofile_progress", 0) or 0)
|
| 409 |
gofile_eta_seconds = int(state_entry.get("gofile_eta_seconds", 0) or 0)
|
| 410 |
display_progress = gofile_progress if gofile_uploading else progress_percent(torrent_progress)
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
| 412 |
gofile_speed = state_entry.get("gofile_speed", "")
|
| 413 |
if gofile_uploading:
|
| 414 |
eta_text = human_eta(gofile_eta_seconds)
|
|
@@ -417,7 +420,11 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
|
|
| 417 |
else:
|
| 418 |
eta_text = human_eta(eta_value)
|
| 419 |
display_speed = gofile_speed if gofile_uploading else format_speed(torrent_dlspeed)
|
| 420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
if not gofile_uploading and torrent_progress >= 1 and torrent_upspeed > 0:
|
| 422 |
display_speed = format_speed(torrent_upspeed)
|
| 423 |
display_speed_label = "Seed Upload"
|
|
@@ -483,6 +490,7 @@ def prepare_upload_source(source_path: Path, torrent_hash: str, provider_name: s
|
|
| 483 |
|
| 484 |
update_torrent_entry(
|
| 485 |
torrent_hash,
|
|
|
|
| 486 |
gofile_status=f"Archiving folder for {provider_name}...",
|
| 487 |
status_message=f"Archiving folder for {provider_name}...",
|
| 488 |
gofile_progress=0,
|
|
@@ -491,13 +499,22 @@ def prepare_upload_source(source_path: Path, torrent_hash: str, provider_name: s
|
|
| 491 |
)
|
| 492 |
|
| 493 |
process = subprocess.Popen(
|
| 494 |
-
["7z", "a", "-tzip", "-mx=5", str(archive_path), source_path.name],
|
| 495 |
cwd=str(source_path.parent),
|
| 496 |
stdout=subprocess.PIPE,
|
| 497 |
stderr=subprocess.PIPE,
|
| 498 |
text=True,
|
|
|
|
| 499 |
)
|
| 500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
update_torrent_entry(torrent_hash, gofile_pid=process.pid)
|
| 502 |
while True:
|
| 503 |
return_code = process.poll()
|
|
@@ -510,18 +527,21 @@ def prepare_upload_source(source_path: Path, torrent_hash: str, provider_name: s
|
|
| 510 |
break
|
| 511 |
time.sleep(1)
|
| 512 |
|
| 513 |
-
|
|
|
|
| 514 |
if current_entry.get("gofile_cancel_requested") or process.returncode == -15:
|
| 515 |
archive_path.unlink(missing_ok=True)
|
| 516 |
raise GofileUploadCancelled(f"Archiving {provider_name} dibatalkan.")
|
| 517 |
if process.returncode != 0:
|
| 518 |
archive_path.unlink(missing_ok=True)
|
| 519 |
-
raise ValueError(stderr.strip() or
|
| 520 |
|
| 521 |
update_torrent_entry(
|
| 522 |
torrent_hash,
|
|
|
|
| 523 |
gofile_status=f"Archive ready, memulai upload ke {provider_name}...",
|
| 524 |
status_message="",
|
|
|
|
| 525 |
)
|
| 526 |
return archive_path, True
|
| 527 |
|
|
@@ -944,6 +964,51 @@ def parse_curl_progress_line(line: str, total_bytes: int) -> dict | None:
|
|
| 944 |
}
|
| 945 |
|
| 946 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 947 |
def monitor_curl_progress(stderr_pipe, torrent_hash: str, total_bytes: int, upload_label: str, error_lines: list[str]) -> None:
|
| 948 |
buffer = ""
|
| 949 |
try:
|
|
|
|
| 408 |
gofile_progress = int(state_entry.get("gofile_progress", 0) or 0)
|
| 409 |
gofile_eta_seconds = int(state_entry.get("gofile_eta_seconds", 0) or 0)
|
| 410 |
display_progress = gofile_progress if gofile_uploading else progress_percent(torrent_progress)
|
| 411 |
+
if gofile_uploading and upload_provider == "Archiving":
|
| 412 |
+
progress_label = "Archiving"
|
| 413 |
+
else:
|
| 414 |
+
progress_label = f"{upload_provider} Upload" if gofile_uploading else "Progress"
|
| 415 |
gofile_speed = state_entry.get("gofile_speed", "")
|
| 416 |
if gofile_uploading:
|
| 417 |
eta_text = human_eta(gofile_eta_seconds)
|
|
|
|
| 420 |
else:
|
| 421 |
eta_text = human_eta(eta_value)
|
| 422 |
display_speed = gofile_speed if gofile_uploading else format_speed(torrent_dlspeed)
|
| 423 |
+
if gofile_uploading and upload_provider == "Archiving":
|
| 424 |
+
display_speed = state_entry.get("gofile_status", "") or "Archiving..."
|
| 425 |
+
display_speed_label = "Archive"
|
| 426 |
+
else:
|
| 427 |
+
display_speed_label = f"{upload_provider} Upload" if gofile_uploading else "Download"
|
| 428 |
if not gofile_uploading and torrent_progress >= 1 and torrent_upspeed > 0:
|
| 429 |
display_speed = format_speed(torrent_upspeed)
|
| 430 |
display_speed_label = "Seed Upload"
|
|
|
|
| 490 |
|
| 491 |
update_torrent_entry(
|
| 492 |
torrent_hash,
|
| 493 |
+
gofile_provider="Archiving",
|
| 494 |
gofile_status=f"Archiving folder for {provider_name}...",
|
| 495 |
status_message=f"Archiving folder for {provider_name}...",
|
| 496 |
gofile_progress=0,
|
|
|
|
| 499 |
)
|
| 500 |
|
| 501 |
process = subprocess.Popen(
|
| 502 |
+
["7z", "a", "-tzip", "-mx=5", "-bsp1", str(archive_path), source_path.name],
|
| 503 |
cwd=str(source_path.parent),
|
| 504 |
stdout=subprocess.PIPE,
|
| 505 |
stderr=subprocess.PIPE,
|
| 506 |
text=True,
|
| 507 |
+
bufsize=1,
|
| 508 |
)
|
| 509 |
|
| 510 |
+
error_lines: list[str] = []
|
| 511 |
+
monitor_thread = threading.Thread(
|
| 512 |
+
target=monitor_7z_progress,
|
| 513 |
+
args=(process.stdout, torrent_hash, provider_name, error_lines),
|
| 514 |
+
daemon=True,
|
| 515 |
+
)
|
| 516 |
+
monitor_thread.start()
|
| 517 |
+
|
| 518 |
update_torrent_entry(torrent_hash, gofile_pid=process.pid)
|
| 519 |
while True:
|
| 520 |
return_code = process.poll()
|
|
|
|
| 527 |
break
|
| 528 |
time.sleep(1)
|
| 529 |
|
| 530 |
+
stderr = process.stderr.read() if process.stderr else ""
|
| 531 |
+
monitor_thread.join(timeout=1)
|
| 532 |
if current_entry.get("gofile_cancel_requested") or process.returncode == -15:
|
| 533 |
archive_path.unlink(missing_ok=True)
|
| 534 |
raise GofileUploadCancelled(f"Archiving {provider_name} dibatalkan.")
|
| 535 |
if process.returncode != 0:
|
| 536 |
archive_path.unlink(missing_ok=True)
|
| 537 |
+
raise ValueError(stderr.strip() or " | ".join(error_lines[-3:]).strip() or "7z gagal membuat arsip.")
|
| 538 |
|
| 539 |
update_torrent_entry(
|
| 540 |
torrent_hash,
|
| 541 |
+
gofile_provider=provider_name,
|
| 542 |
gofile_status=f"Archive ready, memulai upload ke {provider_name}...",
|
| 543 |
status_message="",
|
| 544 |
+
gofile_progress=0,
|
| 545 |
)
|
| 546 |
return archive_path, True
|
| 547 |
|
|
|
|
| 964 |
}
|
| 965 |
|
| 966 |
|
| 967 |
+
def parse_7z_progress_line(line: str) -> int | None:
|
| 968 |
+
match = re.search(r"(\d{1,3})%", line)
|
| 969 |
+
if not match:
|
| 970 |
+
return None
|
| 971 |
+
return max(0, min(int(match.group(1)), 100))
|
| 972 |
+
|
| 973 |
+
|
| 974 |
+
def monitor_7z_progress(stdout_pipe, torrent_hash: str, provider_name: str, error_lines: list[str]) -> None:
|
| 975 |
+
buffer = ""
|
| 976 |
+
try:
|
| 977 |
+
while True:
|
| 978 |
+
chunk = stdout_pipe.read(1)
|
| 979 |
+
if chunk == "":
|
| 980 |
+
break
|
| 981 |
+
|
| 982 |
+
if chunk in {"\r", "\n"}:
|
| 983 |
+
progress = parse_7z_progress_line(buffer)
|
| 984 |
+
if progress is not None:
|
| 985 |
+
update_state(
|
| 986 |
+
lambda state: state.setdefault("torrents", {}).setdefault(torrent_hash, {}).update(
|
| 987 |
+
{
|
| 988 |
+
"gofile_provider": "Archiving",
|
| 989 |
+
"gofile_progress": progress,
|
| 990 |
+
"gofile_speed": "",
|
| 991 |
+
"gofile_eta_seconds": 0,
|
| 992 |
+
"gofile_status": f"Archiving folder for {provider_name}... {progress}%",
|
| 993 |
+
"status_message": f"Archiving folder for {provider_name}... {progress}%",
|
| 994 |
+
}
|
| 995 |
+
)
|
| 996 |
+
)
|
| 997 |
+
elif buffer.strip():
|
| 998 |
+
error_lines.append(buffer.strip())
|
| 999 |
+
buffer = ""
|
| 1000 |
+
continue
|
| 1001 |
+
|
| 1002 |
+
buffer += chunk
|
| 1003 |
+
finally:
|
| 1004 |
+
if buffer.strip():
|
| 1005 |
+
error_lines.append(buffer.strip())
|
| 1006 |
+
try:
|
| 1007 |
+
stdout_pipe.close()
|
| 1008 |
+
except OSError:
|
| 1009 |
+
pass
|
| 1010 |
+
|
| 1011 |
+
|
| 1012 |
def monitor_curl_progress(stderr_pipe, torrent_hash: str, total_bytes: int, upload_label: str, error_lines: list[str]) -> None:
|
| 1013 |
buffer = ""
|
| 1014 |
try:
|