--- title: EGDownloader-API sdk: docker emoji: ⚡ colorFrom: red colorTo: yellow pinned: false --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference # Video Download Middleware API وسيط بين الـ client وبين n8n / GitHub Action pipeline. --- ## الـ Flow الكامل ``` Client │ ├─ POST /download {"url": "https://youtube.com/..."} │ ↓ │ API يبعت trigger لـ n8n (webhook "run gethup action") │ ↓ │ n8n يشغل GitHub Action │ ↓ │ GitHub Action يحمّل الفيديو وبعدين يبعت POST على │ /n8n/callback/{job_id} ← الـ API بيستقبله ويحفظ الفيديو │ ├─ GET /status/{job_id} ← polling كل 5 ثواني مثلاً │ ↓ لما status = "done" └─ GET /file/{job_id} ← يجيب الفيديو ``` --- ## Endpoints | Method | Path | الوصف | |--------|------|-------| | `POST` | `/download` | ابدأ تحميل جديد | | `GET` | `/status/{job_id}` | اعرف الحالة | | `GET` | `/file/{job_id}` | حمّل الفيديو | | `POST` | `/n8n/callback/{job_id}` | n8n بيبعت النتيجة هنا | | `GET` | `/jobs` | قائمة كل الجوبز (للـ debug) | | `DELETE` | `/job/{job_id}` | احذف جوب وملفه | | `GET` | `/health` | health check | --- ## مثال كامل ### 1. ابدأ التحميل ```bash curl -X POST https://your-api/download \ -H "Content-Type: application/json" \ -d '{"url": "https://www.youtube.com/watch?v=3Yw2SGumGQ8"}' # Response: # {"job_id": "abc-123", "status": "processing"} ``` ### 2. اعمل polling ```bash curl https://your-api/status/abc-123 # بيرجع: # {"job_id":"abc-123","status":"processing",...} ← لسه بيتحمل # {"job_id":"abc-123","status":"done","download_url":"https://your-api/file/abc-123",...} ← خلص ``` ### 3. حمّل الفيديو ```bash curl -L https://your-api/file/abc-123 -o video.mp4 ``` --- ## كيف تربطه بـ n8n في n8n، الـ node اللي كان بيبعت النتيجة (downlode video1) محتاج يبعت على: ``` https://YOUR_API_URL/n8n/callback/{job_id} ``` الـ `job_id` بيوصل لـ n8n في الـ inputs لما الـ API يشغل الـ workflow. ### n8n يدعم حالتين: **Case A – JSON (مجرد إشعار إن الأرتيفاكت جاهز):** ```json { "status": "success", "run_id": "25934033751", "filename": "video.mp4" } ``` → الـ API هيجيب الأرتيفاكت من GitHub بنفسه. **Case B – Raw binary (يبعت الفيديو نفسه):** بس يبعت binary body + header: ``` x-filename: video.mp4 Content-Type: video/mp4 ``` --- ## Environment Variables ```env PUBLIC_URL=https://your-api-public-url.com # مهم جداً عشان n8n يعرف يرد GITHUB_TOKEN=ghp_... GITHUB_REPO=expher510/AutoClip-Pipeline WORKFLOW_FILE=video-download.yml N8N_TRIGGER_URL=https://egauto-n8n.hf.space/webhook/run%20gethup%20action ``` --- ## تشغيل محلي ```bash pip install -r requirements.txt PUBLIC_URL=https://xxxx.ngrok.io uvicorn main:app --reload --port 8000 ``` ## تشغيل على Hugging Face Spaces (Docker) 1. ارفع الملفات على Space جديد (Docker SDK) 2. حط الـ env vars في Settings → Repository secrets 3. الـ port هو `7860`