File size: 3,434 Bytes
c41ece5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a412233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18e14fb
a412233
 
 
 
 
 
 
 
 
 
 
18e14fb
 
a412233
 
 
 
 
 
 
 
 
 
 
c41ece5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
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`