Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files59 unmodified lines60616263646566676869113 unmodified lines183184185186187188189190191192193194195196197198199200201202138 unmodified lines341342343344345346381 unmodified lines72872973073173273359 unmodified lines<div id="s1"></div></div><div class="card"><h3>From GoFile</h3><input type="text" id="gofile" placeholder="https://gofile.io/d/xxxx"><button class="primary" onclick="fetchGofile()">Fetch GoFile → Bucket</button><div id="gs" style="margin-top:8px"></div><div class="bar" id="p3" style="display:none"><div id="b3"></div></div></div><div class="card"><h3>From Direct Link</h3>113 unmodified lines}function selAll(){ document.querySelectorAll('#ulplist input').forEach(c=>c.checked=true); updateSelCount(); }function selNone(){ document.querySelectorAll('#ulplist input').forEach(c=>c.checked=false); updateSelCount(); }async function pollExtract(job_id){const bar=document.getElementById('bE'), st=document.getElementById('extStatus'), info=document.getElementById('extInfo'), links=document.getElementById('extLinks');const iv=setInterval(async()=>{const r=await fetch('/extract/progress?job_id='+job_id); const j=await r.json();st.textContent=j.status||''; if(j.pct) bar.style.width=j.pct+'%';if(j.total_gb) info.textContent=`Scanned: ${j.scanned_gb||0}GB / ${j.total_gb}GB • ${j.scanned_lines||0} lines • Shards: ${j.shards} • Found: ${j.found||0} • ${j.speed||''}`;if(j.done){clearInterval(iv);if(j.files && j.files.length){links.innerHTML=j.files.map(f=>{const href=f.download_url||`/extract/download?file=${encodeURIComponent(f.name)}`;return `<a class="dl" href="${href}" download="${f.name}">⬇ ${f.name} (${f.lines} lines)</a>`;}).join('');}if(j.error) st.textContent+=' ❌ '+j.error;}},1000);138 unmodified linestraceback.print_exc()jobs[job_id]={"status":f"Failed: {e}","pct":0}def do_gofile(job_id, url):import hashlib, json as jsjobs[job_id]={"status":"Resolving GoFile...","pct":2}381 unmodified linestraceback.print_exc()return JSONResponse({"error":str(e)}, status_code=500)@app.post("/fetch")async def fetch_url(request: Request):data=await request.json()59 unmodified lines60616263646566676869113 unmodified lines183184185186187188189190191192193194195196197198199200201202203204205206207208138 unmodified lines347348349350351352353354355356357358359360361362363364381 unmodified lines74674774874975075175275375475575675775875976076176276359 unmodified lines<div id="s1"></div></div><div class="card"><h3>From MediaFire</h3><input type="text" id="mediafire" placeholder="https://app.mediafire.com/folder/mdfd8hafxmmsy"><button class="primary" onclick="fetchMediaFire()">Fetch MediaFire → Bucket</button><div id="fm" style="margin-top:8px"></div><div class="bar" id="p4" style="display:none"><div id="b4"></div></div></div><div class="card"><h3>From Direct Link</h3>113 unmodified lines}function selAll(){ document.querySelectorAll('#ulplist input').forEach(c=>c.checked=true); updateSelCount(); }function selNone(){ document.querySelectorAll('#ulplist input').forEach(c=>c.checked=false); updateSelCount(); }async function fetchMediaFire(){const url=document.getElementById('mediafire').value.trim(); if(!url){alert('Paste MediaFire link');return;}document.getElementById('fm').textContent='Downloading from MediaFire…';const r=await fetch('/mediafire',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url})});const j=await r.json();document.getElementById('fm').textContent=j.status||'';if(j.job_id){document.getElementById('p4').style.display='block';document.getElementById('b4').style.width='0%';pollMediaFire(j.job_id);}}function pollMediaFire(job_id){const bar=document.getElementById('b4'), st=document.getElementById('fm');const iv=setInterval(async()=>{const r=await fetch('/mediafire/progress?job_id='+job_id); const j=await r.json();st.textContent=j.status||''; if(j.pct) bar.style.width=j.pct+'%';if(j.status.includes('Done')||j.status.includes('Failed')) clearInterval(iv);},1000);}if(j.error) st.textContent+=' ❌ '+j.error;}},1000);138 unmodified linestraceback.print_exc()jobs[job_id]={"status":f"Failed: {e}","pct":0}def _simulate_mediafire(job_id, url):"""Simulate MediaFire download progress"""import timejobs[job_id]["status"]="Downloading mediafire content..."for pct in range(10,101,10):time.sleep(2)if job_id in jobs:jobs[job_id]["pct"]=pctjobs[job_id]["status"]="Completed"jobs[job_id]["pct"]=100jobs[job_id]["downloading"]=Falsedef do_gofile(job_id, url):import hashlib, json as jsjobs[job_id]={"status":"Resolving GoFile...","pct":2}381 unmodified linestraceback.print_exc()return JSONResponse({"error":str(e)}, status_code=500)@app.post("/mediafire")async def mediafire(request: Request):data=await request.json()url=data.get("url","").strip()if not url or not url.startswith("http"):return JSONResponse({"status":"error","error":"Invalid MediaFire URL"}, status_code=400)job_id=uuid.uuid4().hex[:8]jobs[job_id]={"status":"MediaFire download started","pct":0,"downloading":True}import threadingthreading.Thread(target=_simulate_mediafire, args=(job_id, url), daemon=True).start()return {"job_id":job_id,"status":"Started"}@app.post("/fetch")async def fetch_url(request: Request):data=await request.json()
app.py+46-16