Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,6 +30,8 @@ ignited_uids = set()
|
|
| 30 |
cached_vault_folders = set()
|
| 31 |
last_tree_fetch = 0
|
| 32 |
|
|
|
|
|
|
|
| 33 |
# ==========================================
|
| 34 |
# ⚡ GOOGLE PROXY HELPER
|
| 35 |
# ==========================================
|
|
@@ -427,13 +429,17 @@ def stream(access_key, type, id):
|
|
| 427 |
binge_id = ""
|
| 428 |
|
| 429 |
if is_ready:
|
| 430 |
-
#
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
elif u_id in ignited_uids:
|
|
|
|
| 437 |
def check_engine(url):
|
| 438 |
try: return requests.get(f"{url}/status/{u_id}?detailed=1", timeout=2).json()
|
| 439 |
except: return {"status": "offline"}
|
|
@@ -448,38 +454,31 @@ def stream(access_key, type, id):
|
|
| 448 |
total_prog += res.get("progress", 0)
|
| 449 |
max_eta = max(max_eta, res.get("eta_seconds", 0))
|
| 450 |
|
| 451 |
-
if active_count > 0
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
name_str = f"{source_tag} {quality_tag}".strip()
|
| 461 |
-
if label:
|
| 462 |
-
name_str += f"\n{label}"
|
| 463 |
-
|
| 464 |
-
# ⚡ 4. SAFELY MAP TITLE AND DESCRIPTION FOR STREMIO UI
|
| 465 |
-
stream_obj = {
|
| 466 |
-
"name": name_str,
|
| 467 |
-
"title": f"{title_prefix}{display_text}",
|
| 468 |
-
"url": stream_url,
|
| 469 |
-
"behaviorHints": {
|
| 470 |
-
"bingeGroup": binge_id,
|
| 471 |
-
"videoSize": size_bytes,
|
| 472 |
-
"videoHash": str(u_id)
|
| 473 |
}
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
if s.get('_orig_desc'):
|
| 479 |
stream_obj["description"] = s['_orig_desc']
|
| 480 |
-
|
| 481 |
-
stream_obj["title"] = title_prefix.strip()
|
| 482 |
-
|
| 483 |
custom_streams.append(stream_obj)
|
| 484 |
|
| 485 |
# ⚡ 4-LINE VAULT RESCUE ⚡
|
|
@@ -510,10 +509,12 @@ def traffic_cop(access_key, u_id):
|
|
| 510 |
if u_id in ignited_uids:
|
| 511 |
return redirect("http://127.0.0.1:65535/igniting.mp4")
|
| 512 |
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
|
|
|
|
|
|
| 517 |
|
| 518 |
return redirect("http://127.0.0.1:65535/igniting.mp4")
|
| 519 |
|
|
|
|
| 30 |
cached_vault_folders = set()
|
| 31 |
last_tree_fetch = 0
|
| 32 |
|
| 33 |
+
ignition_lock = threading.Lock()
|
| 34 |
+
|
| 35 |
# ==========================================
|
| 36 |
# ⚡ GOOGLE PROXY HELPER
|
| 37 |
# ==========================================
|
|
|
|
| 429 |
binge_id = ""
|
| 430 |
|
| 431 |
if is_ready:
|
| 432 |
+
# ☁️ STATE 1: VAULTED (Plays instantly from System E)
|
| 433 |
+
stream_obj = {
|
| 434 |
+
"name": f"☁️ Vaulted\n{source_tag} {quality_tag}",
|
| 435 |
+
"title": f"☁️ Ready to Play\n{display_text}",
|
| 436 |
+
"url": f"{SYS_E_URL}/stream/{u_id}/video.mkv",
|
| 437 |
+
"behaviorHints": {"bingeGroup": binge_id, "videoSize": size_bytes, "videoHash": str(u_id)}
|
| 438 |
+
}
|
| 439 |
+
if s.get('_orig_title'): stream_obj["title"] = f"☁️ Ready to Play\n{s['_orig_title']}"
|
| 440 |
|
| 441 |
elif u_id in ignited_uids:
|
| 442 |
+
# ⏳ STATE 2: DOWNLOADING (Plays natively via P2P while cluster vaults)
|
| 443 |
def check_engine(url):
|
| 444 |
try: return requests.get(f"{url}/status/{u_id}?detailed=1", timeout=2).json()
|
| 445 |
except: return {"status": "offline"}
|
|
|
|
| 454 |
total_prog += res.get("progress", 0)
|
| 455 |
max_eta = max(max_eta, res.get("eta_seconds", 0))
|
| 456 |
|
| 457 |
+
avg_prog = int(total_prog / active_count) if active_count > 0 else 0
|
| 458 |
+
eta_str = format_eta(max_eta) if active_count > 0 else "Starting..."
|
| 459 |
+
|
| 460 |
+
stream_obj = {
|
| 461 |
+
"name": f"⏳ Vaulting (P2P)\n{source_tag} {quality_tag}",
|
| 462 |
+
"title": f"⏳ Downloading: 🔄 [{avg_prog}%] - ETA: {eta_str}\n{display_text}",
|
| 463 |
+
"infoHash": info_hash, # ⚡ NATIVE P2P PLAYBACK
|
| 464 |
+
"fileIdx": int(file_idx),
|
| 465 |
+
"behaviorHints": {"bingeGroup": binge_id, "videoSize": size_bytes, "videoHash": str(u_id)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
}
|
| 467 |
+
if s.get('_orig_title'): stream_obj["title"] = f"⏳ Downloading: 🔄 [{avg_prog}%] - ETA: {eta_str}\n{s['_orig_title']}"
|
| 468 |
+
|
| 469 |
+
else:
|
| 470 |
+
# 🧲 STATE 3: UNCACHED (Click sends to Traffic Cop -> Bumper Video)
|
| 471 |
+
stream_obj = {
|
| 472 |
+
"name": f"▶️ Stream & Vault\n{source_tag} {quality_tag}",
|
| 473 |
+
"title": f"Click to start Cloud Download...\n{display_text}",
|
| 474 |
+
"url": f"{ADDON_DOMAIN}/{access_key}/traffic_cop/{u_id}?h={info_hash}&sz={size_bytes}&series={is_series_flag}&pidx={file_idx}",
|
| 475 |
+
"behaviorHints": {"bingeGroup": binge_id, "videoSize": size_bytes, "videoHash": str(u_id)}
|
| 476 |
+
}
|
| 477 |
+
if s.get('_orig_title'): stream_obj["title"] = f"Downloading to Cloud...\n{s['_orig_title']}"
|
| 478 |
+
|
| 479 |
if s.get('_orig_desc'):
|
| 480 |
stream_obj["description"] = s['_orig_desc']
|
| 481 |
+
|
|
|
|
|
|
|
| 482 |
custom_streams.append(stream_obj)
|
| 483 |
|
| 484 |
# ⚡ 4-LINE VAULT RESCUE ⚡
|
|
|
|
| 509 |
if u_id in ignited_uids:
|
| 510 |
return redirect("http://127.0.0.1:65535/igniting.mp4")
|
| 511 |
|
| 512 |
+
with ignition_lock:
|
| 513 |
+
if u_id not in ignited_uids:
|
| 514 |
+
ignited_uids.add(u_id)
|
| 515 |
+
threading.Thread(target=fire_missiles, args=(u_id, info_hash, size_bytes, is_series, p_idx)).start()
|
| 516 |
+
threading.Thread(target=monitor_cluster_thread, args=(u_id,)).start()
|
| 517 |
+
|
| 518 |
|
| 519 |
return redirect("http://127.0.0.1:65535/igniting.mp4")
|
| 520 |
|