amri12310 commited on
Commit
223fdc6
·
verified ·
1 Parent(s): c5ae709

Update engine.py

Browse files
Files changed (1) hide show
  1. engine.py +113 -50
engine.py CHANGED
@@ -4,6 +4,7 @@ os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
4
  import urllib3
5
  import threading, shutil, json, time, glob, subprocess, urllib.parse, logging, struct, socket
6
  import warnings, requests, queue, re
 
7
  import libtorrent as lt
8
  from flask import Flask, request, Response, stream_with_context, render_template_string, redirect, url_for, abort
9
 
@@ -29,6 +30,13 @@ GH_TOKEN = os.environ.get("GH_PAT")
29
  ADMIN_KEY = os.environ.get("ADMIN_KEY", "Amrit2026")
30
  ADDON_URL = "https://amri12310-sys-b-addon.hf.space"
31
 
 
 
 
 
 
 
 
32
  active_vaults = set()
33
  active_handles = {}
34
  current_task_info = {}
@@ -72,8 +80,15 @@ def fetch_cinemeta(u_id):
72
  cinemeta_cache[u_id] = meta
73
  return meta
74
 
 
 
 
 
 
 
 
75
  # ==========================================
76
- # FRONT-END DASHBOARD (SMART SEASONS + BULK DELETE)
77
  # ==========================================
78
  DASHBOARD_HTML = """
79
  <!DOCTYPE html>
@@ -93,51 +108,46 @@ DASHBOARD_HTML = """
93
  <div class="bg-slate-800 rounded-xl p-6 mb-8 border border-slate-700 shadow-xl">
94
  <h2 class="text-xl font-semibold mb-6 flex items-center text-green-400">
95
  <span class="w-3 h-3 bg-green-500 rounded-full mr-2 animate-pulse"></span>
96
- Active Swarm Downloading
97
  </h2>
98
 
99
  <div class="space-y-4">
100
- {% for id, handle in handles.items() %}
101
- {% set s = handle.status() %}
102
- {% set task = task_info.get(id, {}) %}
103
- {% set meta = task.get('meta', {}) %}
104
- {% set prog = (s.progress * 100)|round(1) %}
105
-
106
  <div class="bg-slate-900 p-4 rounded-xl border border-slate-700 flex gap-5 shadow-lg relative overflow-hidden">
107
  <div class="flex-shrink-0 w-24 h-36 z-10">
108
- <img src="{{ meta.poster }}" class="w-full h-full object-cover rounded shadow-md border border-slate-600">
109
  </div>
110
 
111
  <div class="flex-1 flex flex-col justify-between z-10">
112
  <div>
113
  <div class="flex justify-between items-start">
114
  <h3 class="text-xl font-bold text-blue-300 leading-tight drop-shadow-md">
115
- {{ meta.title }}
116
- {% if meta.is_series %}
117
- <span class="text-sm text-purple-400 font-normal ml-2 bg-purple-900/30 px-2 py-0.5 rounded">{{ meta.s_e }} {{ '- ' ~ meta.ep_name if meta.ep_name else '' }}</span>
118
  {% endif %}
119
  </h3>
120
  <span class="px-2 py-1 rounded bg-blue-900/50 text-blue-200 text-[10px] uppercase font-bold border border-blue-800">
121
- {{ scout_status.get(id, 'Active') }}
122
  </span>
123
  </div>
124
- <p class="text-xs text-slate-400 mt-1 truncate max-w-xl font-mono">
125
- 📁 {{ task.get('current_file', 'Awaiting Metadata...') }}
126
  </p>
127
  </div>
128
 
129
  <div class="mt-2">
130
  <div class="flex justify-between text-xs text-slate-400 mb-1 font-mono">
131
- <span>{{ (s.total_done / 1073741824)|round(2) }} GB / {{ task.get('size_gb', '?') }} GB</span>
132
- <span class="text-green-400">{{ (s.download_rate / 1000000)|round(2) }} MB/s</span>
133
  </div>
134
  <div class="w-full bg-slate-800 rounded-full h-3 mb-2 shadow-inner border border-slate-700">
135
- <div class="bg-gradient-to-r from-blue-600 to-blue-400 h-full rounded-full transition-all duration-500" style="width: {{ prog }}%"></div>
136
  </div>
137
  <div class="flex justify-between items-center">
138
- <span class="text-sm text-white font-bold">{{ prog }}%</span>
139
- <form action="{{ addon_url }}/kill/{{ id }}?key={{ key }}" method="POST">
140
- <button class="text-red-500 hover:text-red-400 text-[10px] font-bold tracking-wider hover:underline transition-colors">KILL TASK</button>
141
  </form>
142
  </div>
143
  </div>
@@ -145,7 +155,7 @@ DASHBOARD_HTML = """
145
  </div>
146
  {% endfor %}
147
 
148
- {% if not handles %}
149
  <div class="py-12 text-center text-slate-500 italic font-mono bg-slate-900/50 rounded-xl border border-dashed border-slate-700">
150
  --- Swarm Idle. Awaiting Stremio Command ---
151
  </div>
@@ -208,7 +218,8 @@ DASHBOARD_HTML = """
208
  <p class="text-[10px] text-slate-600 mt-2 font-mono truncate" title="{{ item.id }}">{{ item.id[:20] }}...</p>
209
  </div>
210
  <div class="flex justify-between items-center mt-3 pt-3 border-t border-slate-700/50">
211
- <span class="px-2 py-0.5 rounded bg-green-900/30 text-green-400 text-[10px] font-bold border border-green-800/50">VAULTED</span>
 
212
  <form action="/delete_vaulted/{{ item.id }}?key={{ key }}" method="POST">
213
  <button class="text-slate-500 hover:text-red-500 text-[10px] font-bold hover:underline transition-colors">DELETE EP</button>
214
  </form>
@@ -232,7 +243,6 @@ DASHBOARD_HTML = """
232
  </div>
233
 
234
  <script>
235
- // 1. Remember exactly where you were scrolling
236
  document.addEventListener("DOMContentLoaded", function(event) {
237
  var scrollpos = localStorage.getItem('vault_scrollpos');
238
  if (scrollpos) window.scrollTo(0, scrollpos);
@@ -241,7 +251,6 @@ DASHBOARD_HTML = """
241
  localStorage.setItem('vault_scrollpos', window.scrollY);
242
  };
243
 
244
- // 2. The Smart Toggle that saves folder states to your browser
245
  function toggleVault(imdbId) {
246
  let el = document.getElementById('group-' + imdbId);
247
  el.classList.toggle('hidden');
@@ -252,7 +261,6 @@ DASHBOARD_HTML = """
252
  }
253
  }
254
 
255
- // 3. Instantly re-open folders when the page refreshes
256
  document.addEventListener("DOMContentLoaded", function() {
257
  let groups = document.querySelectorAll('[id^="group-"]');
258
  groups.forEach(function(el) {
@@ -270,29 +278,62 @@ DASHBOARD_HTML = """
270
  @app.route('/')
271
  def dashboard():
272
  check_auth()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  try:
274
  files = api.list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=TOKEN)
275
  raw_folders = sorted(list(set([f.split('/')[0] for f in files if '/' in f])))
276
 
277
- # ⚡ UPGRADED LOGIC: GROUPS BY SHOW AND THEN BY SEASON
278
  grouped_vault = {}
279
  for f in raw_folders:
280
  meta = fetch_cinemeta(f)
281
  imdb_id = f.split('_')[0]
282
 
283
- # Determine Season Number
284
  season_name = "Movie"
285
  if meta['is_series']:
286
  parts = f.split('_')
287
  if len(parts) > 1 and parts[1].startswith('S'):
288
- season_name = parts[1] # e.g. "S04"
289
 
290
  if imdb_id not in grouped_vault:
291
- grouped_vault[imdb_id] = {
292
- "title": meta['title'],
293
- "poster": meta['poster'],
294
- "seasons": {}
295
- }
296
 
297
  if season_name not in grouped_vault[imdb_id]["seasons"]:
298
  grouped_vault[imdb_id]["seasons"][season_name] = []
@@ -300,7 +341,8 @@ def dashboard():
300
  grouped_vault[imdb_id]["seasons"][season_name].append({"id": f, "meta": meta})
301
 
302
  except: grouped_vault = {}
303
- return render_template_string(DASHBOARD_HTML, handles=active_handles, grouped_vault=grouped_vault, task_info=current_task_info, scout_status=scout_status, key=ADMIN_KEY, addon_url=ADDON_URL)
 
304
 
305
  # ==========================================
306
  # AGGRESSIVE I/O LIBTORRENT SETTINGS
@@ -309,8 +351,8 @@ settings = {
309
  'listen_interfaces': '0.0.0.0:6881',
310
  'enable_dht': True,
311
  'dht_bootstrap_nodes': 'router.bittorrent.com:6881,router.utorrent.com:6881,dht.transmissionbt.com:6881',
312
- 'connections_limit': 350,
313
- 'unchoke_slots_limit': 150,
314
  'active_downloads': 1,
315
  'aio_threads': 12,
316
  'cache_size': 49152,
@@ -377,9 +419,26 @@ def force_inject_peers(info_hash, trackers, handle, peer_id):
377
  except Exception:
378
  pass
379
 
 
380
  @app.route('/status/<u_id>')
381
  def get_status(u_id):
382
- if u_id in active_vaults: return {"status": "active"}, 200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  return {"status": "completed"}, 200
384
 
385
  # ==========================================
@@ -460,9 +519,6 @@ def process_and_queue(filepath, target_u_id, start_chunk, end_chunk, chunk_size,
460
  if batch_state['bytes'] >= DISK_THRESHOLD:
461
  flush_batch(batch_state, f"Vaulting 4.5GB dynamic meta batch")
462
 
463
- # ==========================================
464
- # ⚡ BACKGROUND PULSE INJECTOR (FIXED ANTI-DDOS BAN) ⚡
465
- # ==========================================
466
  def continuous_peer_pulse(u_id, info_hash, trackers, handle, peer_id):
467
  """Silently tops off the peer list every 3 minutes until the download finishes."""
468
  while True:
@@ -532,9 +588,6 @@ def do_archive(u_id, info_hash, part=1, total=1, is_series=False, priority_idx=-
532
  chunk_size = 500 * 1024 * 1024
533
  my_assigned_files = []
534
 
535
- # ⚡==========================================⚡
536
- # HYBRID SHARDING ENGINE: Bytes vs VIP Files
537
- # ⚡==========================================⚡
538
  # ⚡==========================================⚡
539
  # HYBRID SHARDING ENGINE: Bytes vs VIP Files
540
  # ⚡==========================================⚡
@@ -733,7 +786,7 @@ def internal_kill(u_id):
733
  return "Node Aborted", 200
734
 
735
  # ==========================================
736
- # TURBO LEAD-PIPE PROXY (WITH SELF-HEALING)
737
  # ==========================================
738
  @app.route('/stream/<u_id>')
739
  def stream_vault(u_id):
@@ -797,6 +850,11 @@ def stream_vault(u_id):
797
 
798
  headers = {"Content-Length": str(bytes_to_send), "Content-Type": "video/x-matroska", "Accept-Ranges": "bytes", "Connection": "keep-alive"}
799
  if range_header: headers["Content-Range"] = f"bytes {req_start}-{req_end}/{total_size}"
 
 
 
 
 
800
  return Response(stream_with_context(generate_turbo_new()), status=206 if range_header else 200, headers=headers)
801
  except Exception as e: print(f"Meta A error: {e}", flush=True)
802
 
@@ -840,10 +898,10 @@ def stream_vault(u_id):
840
  data_queue.put(data)
841
  current_start += len(data)
842
  bytes_this_req += len(data)
843
- if expected_len > 0 and bytes_this_req < expected_len:
844
- print(f"⚠️ [NETWORK] Old chunk truncated. Resuming...", flush=True)
845
- continue
846
- else: break
847
  except: time.sleep(1)
848
  except Exception as e: print(f"Legacy Worker Error: {e}", flush=True)
849
  finally: data_queue.put(None)
@@ -862,6 +920,11 @@ def stream_vault(u_id):
862
 
863
  headers = {"Content-Length": str(bytes_to_send), "Content-Type": "video/x-matroska", "Accept-Ranges": "bytes", "Connection": "keep-alive"}
864
  if range_header: headers["Content-Range"] = f"bytes {req_start}-{req_end}/{total_size}"
 
 
 
 
 
865
  return Response(stream_with_context(generate_turbo_old()), status=206 if range_header else 200, headers=headers)
866
 
867
  @app.route('/delete_active/<u_id>', methods=['POST'])
@@ -909,4 +972,4 @@ def delete_season(imdb_id, season_name):
909
  return redirect(url_for('dashboard', key=ADMIN_KEY))
910
 
911
  if __name__ == "__main__":
912
- app.run(host="0.0.0.0", port=7860)
 
4
  import urllib3
5
  import threading, shutil, json, time, glob, subprocess, urllib.parse, logging, struct, socket
6
  import warnings, requests, queue, re
7
+ import concurrent.futures # ⚡ ADDED: For Cross-Engine Dashboard Polling
8
  import libtorrent as lt
9
  from flask import Flask, request, Response, stream_with_context, render_template_string, redirect, url_for, abort
10
 
 
30
  ADMIN_KEY = os.environ.get("ADMIN_KEY", "Amrit2026")
31
  ADDON_URL = "https://amri12310-sys-b-addon.hf.space"
32
 
33
+ # ⚡ ADDED: ENGINE URLS FOR UNIFIED DASHBOARD MATH
34
+ ENGINE_URLS = [
35
+ "https://amri12310-sys-b-engine.hf.space",
36
+ "https://amri12310-sys-c-engine.hf.space",
37
+ "https://amri12310-sys-d-engine.hf.space"
38
+ ]
39
+
40
  active_vaults = set()
41
  active_handles = {}
42
  current_task_info = {}
 
80
  cinemeta_cache[u_id] = meta
81
  return meta
82
 
83
+ def format_eta(seconds):
84
+ if seconds >= 86400: return "> 1 Day"
85
+ h, m, s = seconds // 3600, (seconds % 3600) // 60, seconds % 60
86
+ if h > 0: return f"{h}h {m}m"
87
+ if m > 0: return f"{m}m {s}s"
88
+ return f"{s}s"
89
+
90
  # ==========================================
91
+ # FRONT-END DASHBOARD (WITH COMBINED MATH & DOWNLOAD BUTTONS)
92
  # ==========================================
93
  DASHBOARD_HTML = """
94
  <!DOCTYPE html>
 
108
  <div class="bg-slate-800 rounded-xl p-6 mb-8 border border-slate-700 shadow-xl">
109
  <h2 class="text-xl font-semibold mb-6 flex items-center text-green-400">
110
  <span class="w-3 h-3 bg-green-500 rounded-full mr-2 animate-pulse"></span>
111
+ Active Swarm (Cluster Aggregated)
112
  </h2>
113
 
114
  <div class="space-y-4">
115
+ {% for uid, c_data in cluster_data.items() %}
 
 
 
 
 
116
  <div class="bg-slate-900 p-4 rounded-xl border border-slate-700 flex gap-5 shadow-lg relative overflow-hidden">
117
  <div class="flex-shrink-0 w-24 h-36 z-10">
118
+ <img src="{{ c_data.meta.poster }}" class="w-full h-full object-cover rounded shadow-md border border-slate-600">
119
  </div>
120
 
121
  <div class="flex-1 flex flex-col justify-between z-10">
122
  <div>
123
  <div class="flex justify-between items-start">
124
  <h3 class="text-xl font-bold text-blue-300 leading-tight drop-shadow-md">
125
+ {{ c_data.meta.title }}
126
+ {% if c_data.meta.is_series %}
127
+ <span class="text-sm text-purple-400 font-normal ml-2 bg-purple-900/30 px-2 py-0.5 rounded">{{ c_data.meta.s_e }} {{ '- ' ~ c_data.meta.ep_name if c_data.meta.ep_name else '' }}</span>
128
  {% endif %}
129
  </h3>
130
  <span class="px-2 py-1 rounded bg-blue-900/50 text-blue-200 text-[10px] uppercase font-bold border border-blue-800">
131
+ {{ c_data.active_nodes }}/3 NODES ACTIVE
132
  </span>
133
  </div>
134
+ <p class="text-xs text-slate-400 mt-1 font-mono">
135
+ ⏱️ Cluster ETA: {{ c_data.eta_str }}
136
  </p>
137
  </div>
138
 
139
  <div class="mt-2">
140
  <div class="flex justify-between text-xs text-slate-400 mb-1 font-mono">
141
+ <span>{{ c_data.done_gb }} GB / {{ c_data.total_gb }} GB</span>
142
+ <span class="text-green-400">{{ c_data.speed_mb }} MB/s</span>
143
  </div>
144
  <div class="w-full bg-slate-800 rounded-full h-3 mb-2 shadow-inner border border-slate-700">
145
+ <div class="bg-gradient-to-r from-blue-600 to-blue-400 h-full rounded-full transition-all duration-500" style="width: {{ c_data.progress }}%"></div>
146
  </div>
147
  <div class="flex justify-between items-center">
148
+ <span class="text-sm text-white font-bold">{{ c_data.progress }}%</span>
149
+ <form action="{{ addon_url }}/kill/{{ uid }}?key={{ key }}" method="POST">
150
+ <button class="text-red-500 hover:text-red-400 text-[10px] font-bold tracking-wider hover:underline transition-colors">KILL TASK (GLOBAL)</button>
151
  </form>
152
  </div>
153
  </div>
 
155
  </div>
156
  {% endfor %}
157
 
158
+ {% if not cluster_data %}
159
  <div class="py-12 text-center text-slate-500 italic font-mono bg-slate-900/50 rounded-xl border border-dashed border-slate-700">
160
  --- Swarm Idle. Awaiting Stremio Command ---
161
  </div>
 
218
  <p class="text-[10px] text-slate-600 mt-2 font-mono truncate" title="{{ item.id }}">{{ item.id[:20] }}...</p>
219
  </div>
220
  <div class="flex justify-between items-center mt-3 pt-3 border-t border-slate-700/50">
221
+ <a href="/stream/{{ item.id }}?dl=1" class="px-2 py-1 bg-blue-600 hover:bg-blue-500 text-white rounded text-[10px] font-bold transition-colors">DOWNLOAD EP</a>
222
+
223
  <form action="/delete_vaulted/{{ item.id }}?key={{ key }}" method="POST">
224
  <button class="text-slate-500 hover:text-red-500 text-[10px] font-bold hover:underline transition-colors">DELETE EP</button>
225
  </form>
 
243
  </div>
244
 
245
  <script>
 
246
  document.addEventListener("DOMContentLoaded", function(event) {
247
  var scrollpos = localStorage.getItem('vault_scrollpos');
248
  if (scrollpos) window.scrollTo(0, scrollpos);
 
251
  localStorage.setItem('vault_scrollpos', window.scrollY);
252
  };
253
 
 
254
  function toggleVault(imdbId) {
255
  let el = document.getElementById('group-' + imdbId);
256
  el.classList.toggle('hidden');
 
261
  }
262
  }
263
 
 
264
  document.addEventListener("DOMContentLoaded", function() {
265
  let groups = document.querySelectorAll('[id^="group-"]');
266
  groups.forEach(function(el) {
 
278
  @app.route('/')
279
  def dashboard():
280
  check_auth()
281
+
282
+ # ⚡ 1. CROSS-ENGINE POLLER FOR UNIFIED MATH
283
+ cluster_data = {}
284
+
285
+ def fetch_engine_status(url, uid):
286
+ try: return requests.get(f"{url}/status/{uid}?detailed=1", timeout=2).json()
287
+ except: return {"status": "offline"}
288
+
289
+ # We use active_vaults so each engine checks the tasks it currently knows about
290
+ for u_id in list(active_vaults):
291
+ with concurrent.futures.ThreadPoolExecutor() as executor:
292
+ results = list(executor.map(lambda url: fetch_engine_status(url, u_id), ENGINE_URLS))
293
+
294
+ engines_alive = 0
295
+ total_wanted = 0
296
+ total_done = 0
297
+ total_speed = 0
298
+ max_eta = 0
299
+
300
+ for r in results:
301
+ if r.get("status") == "active":
302
+ engines_alive += 1
303
+ total_wanted += r.get("wanted_bytes", 0)
304
+ total_done += r.get("done_bytes", 0)
305
+ total_speed += r.get("speed_bytes", 0)
306
+ max_eta = max(max_eta, r.get("eta_seconds", 0))
307
+
308
+ if engines_alive > 0:
309
+ cluster_data[u_id] = {
310
+ "active_nodes": engines_alive,
311
+ "progress": int((total_done / total_wanted) * 100) if total_wanted > 0 else 0,
312
+ "total_gb": round(total_wanted / 1024**3, 2),
313
+ "done_gb": round(total_done / 1024**3, 2),
314
+ "speed_mb": round(total_speed / 1024**2, 2),
315
+ "eta_str": format_eta(max_eta),
316
+ "meta": fetch_cinemeta(u_id)
317
+ }
318
+
319
+ # ⚡ 2. THE VAULT LISTER
320
  try:
321
  files = api.list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=TOKEN)
322
  raw_folders = sorted(list(set([f.split('/')[0] for f in files if '/' in f])))
323
 
 
324
  grouped_vault = {}
325
  for f in raw_folders:
326
  meta = fetch_cinemeta(f)
327
  imdb_id = f.split('_')[0]
328
 
 
329
  season_name = "Movie"
330
  if meta['is_series']:
331
  parts = f.split('_')
332
  if len(parts) > 1 and parts[1].startswith('S'):
333
+ season_name = parts[1]
334
 
335
  if imdb_id not in grouped_vault:
336
+ grouped_vault[imdb_id] = {"title": meta['title'], "poster": meta['poster'], "seasons": {}}
 
 
 
 
337
 
338
  if season_name not in grouped_vault[imdb_id]["seasons"]:
339
  grouped_vault[imdb_id]["seasons"][season_name] = []
 
341
  grouped_vault[imdb_id]["seasons"][season_name].append({"id": f, "meta": meta})
342
 
343
  except: grouped_vault = {}
344
+
345
+ return render_template_string(DASHBOARD_HTML, cluster_data=cluster_data, grouped_vault=grouped_vault, key=ADMIN_KEY, addon_url=ADDON_URL)
346
 
347
  # ==========================================
348
  # AGGRESSIVE I/O LIBTORRENT SETTINGS
 
351
  'listen_interfaces': '0.0.0.0:6881',
352
  'enable_dht': True,
353
  'dht_bootstrap_nodes': 'router.bittorrent.com:6881,router.utorrent.com:6881,dht.transmissionbt.com:6881',
354
+ 'connections_limit': 350,
355
+ 'unchoke_slots_limit': 150,
356
  'active_downloads': 1,
357
  'aio_threads': 12,
358
  'cache_size': 49152,
 
419
  except Exception:
420
  pass
421
 
422
+ # ⚡ UPDATED: /status ENDPOINT NOW FEEDS DETAILED MATH TO ADDON & ENGINES
423
  @app.route('/status/<u_id>')
424
  def get_status(u_id):
425
+ detailed = request.args.get('detailed') == '1'
426
+ if u_id in active_vaults:
427
+ if detailed and u_id in active_handles:
428
+ s = active_handles[u_id].status()
429
+ dl_speed = s.download_rate if s.download_rate > 0 else 1
430
+ bytes_left = s.total_wanted - s.total_done
431
+ eta_seconds = int(bytes_left / dl_speed)
432
+
433
+ return jsonify({
434
+ "status": "active",
435
+ "progress": int(s.progress * 100),
436
+ "wanted_bytes": s.total_wanted,
437
+ "done_bytes": s.total_done,
438
+ "speed_bytes": s.download_rate,
439
+ "eta_seconds": eta_seconds
440
+ })
441
+ return {"status": "active", "progress": 0, "wanted_bytes": 0, "done_bytes": 0, "speed_bytes": 0, "eta_seconds": 9999}, 200
442
  return {"status": "completed"}, 200
443
 
444
  # ==========================================
 
519
  if batch_state['bytes'] >= DISK_THRESHOLD:
520
  flush_batch(batch_state, f"Vaulting 4.5GB dynamic meta batch")
521
 
 
 
 
522
  def continuous_peer_pulse(u_id, info_hash, trackers, handle, peer_id):
523
  """Silently tops off the peer list every 3 minutes until the download finishes."""
524
  while True:
 
588
  chunk_size = 500 * 1024 * 1024
589
  my_assigned_files = []
590
 
 
 
 
591
  # ⚡==========================================⚡
592
  # HYBRID SHARDING ENGINE: Bytes vs VIP Files
593
  # ⚡==========================================⚡
 
786
  return "Node Aborted", 200
787
 
788
  # ==========================================
789
+ # TURBO LEAD-PIPE PROXY (WITH ⚡ DOWNLOAD SUPPORT)
790
  # ==========================================
791
  @app.route('/stream/<u_id>')
792
  def stream_vault(u_id):
 
850
 
851
  headers = {"Content-Length": str(bytes_to_send), "Content-Type": "video/x-matroska", "Accept-Ranges": "bytes", "Connection": "keep-alive"}
852
  if range_header: headers["Content-Range"] = f"bytes {req_start}-{req_end}/{total_size}"
853
+
854
+ # ⚡ ADDED: FORCE BROWSER TO DOWNLOAD FILE IF ?dl=1
855
+ if request.args.get('dl', '0') == '1':
856
+ headers["Content-Disposition"] = f'attachment; filename="{u_id}.mkv"'
857
+
858
  return Response(stream_with_context(generate_turbo_new()), status=206 if range_header else 200, headers=headers)
859
  except Exception as e: print(f"Meta A error: {e}", flush=True)
860
 
 
898
  data_queue.put(data)
899
  current_start += len(data)
900
  bytes_this_req += len(data)
901
+ if expected_len > 0 and bytes_this_req < expected_len:
902
+ print(f"⚠️ [NETWORK] Old chunk truncated. Resuming...", flush=True)
903
+ continue
904
+ else: break
905
  except: time.sleep(1)
906
  except Exception as e: print(f"Legacy Worker Error: {e}", flush=True)
907
  finally: data_queue.put(None)
 
920
 
921
  headers = {"Content-Length": str(bytes_to_send), "Content-Type": "video/x-matroska", "Accept-Ranges": "bytes", "Connection": "keep-alive"}
922
  if range_header: headers["Content-Range"] = f"bytes {req_start}-{req_end}/{total_size}"
923
+
924
+ # ⚡ ADDED: FORCE BROWSER TO DOWNLOAD FILE IF ?dl=1
925
+ if request.args.get('dl', '0') == '1':
926
+ headers["Content-Disposition"] = f'attachment; filename="{u_id}.mkv"'
927
+
928
  return Response(stream_with_context(generate_turbo_old()), status=206 if range_header else 200, headers=headers)
929
 
930
  @app.route('/delete_active/<u_id>', methods=['POST'])
 
972
  return redirect(url_for('dashboard', key=ADMIN_KEY))
973
 
974
  if __name__ == "__main__":
975
+ app.run(host="0.0.0.0", port=7860)