This repository was archived by the owner on Aug 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathapi.py
More file actions
556 lines (495 loc) · 22.3 KB
/
Copy pathapi.py
File metadata and controls
556 lines (495 loc) · 22.3 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
import re
import json
import httpx
import asyncio
from fastapi import FastAPI, HTTPException, Query
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse
app = FastAPI(
title="MovieBox API Pro",
description="Full Pure REST API for moviebox.ph — Zero Scraping",
version="2.1.5"
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
BASE_URL = "https://moviebox.ph"
API_BASE = "https://h5-api.aoneroom.com/wefeed-h5api-bff"
_bearer_token: str | None = None
DEFAULT_HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36",
"Referer": "https://moviebox.ph/",
"Origin": "https://moviebox.ph",
"X-Client-Info": '{"timezone":"Asia/Dhaka"}',
"X-Request-Lang": "en",
"Accept": "application/json",
"Content-Type": "application/json",
"sec-ch-ua": '"Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
}
# Player-side headers for the stream domain (netfilm.world)
PLAYER_HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36",
"Accept": "application/json",
"Accept-Language": "en-US,en;q=0.9",
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"X-Client-Info": '{"timezone":"Asia/Dhaka"}',
"X-Source": "",
"sec-ch-ua": '"Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
}
async def _get_bearer_token() -> str:
"""Auto-acquire a guest JWT from the x-user response header."""
global _bearer_token
if _bearer_token:
return _bearer_token
async with httpx.AsyncClient(follow_redirects=True, timeout=25) as client:
resp = await client.get(f"{API_BASE}/home?host=moviebox.ph", headers=DEFAULT_HEADERS)
x_user = resp.headers.get("x-user")
if x_user:
_bearer_token = json.loads(x_user).get("token")
if not _bearer_token:
# fallback: read from set-cookie
cookie = resp.headers.get("set-cookie", "")
import re as _re
m = _re.search(r"token=([^;]+)", cookie)
if m:
_bearer_token = m.group(1)
return _bearer_token or ""
async def _make_request(url: str, method: str = "GET", payload: dict = None, custom_headers: dict = None) -> dict:
global _bearer_token
token = await _get_bearer_token()
headers = {
**DEFAULT_HEADERS,
"Authorization": f"Bearer {token}" if token else "",
**(custom_headers or {})
}
async with httpx.AsyncClient(follow_redirects=True, timeout=25) as client:
try:
if method == "POST":
resp = await client.post(url, headers=headers, json=payload)
else:
resp = await client.get(url, headers=headers)
# Refresh token if server sends a new one
x_user = resp.headers.get("x-user")
if x_user:
new_token = json.loads(x_user).get("token")
if new_token:
_bearer_token = new_token
if resp.status_code != 200:
raise HTTPException(status_code=502, detail=f"Upstream API error: {resp.status_code}")
return resp.json()
except Exception as e:
if isinstance(e, HTTPException): raise e
raise HTTPException(status_code=502, detail=f"Request failed: {str(e)}")
@app.get("/", response_class=HTMLResponse)
async def dashboard():
html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MovieBox Pure API | Pro Dashboard</title>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--primary: #ff3d71;
--secondary: #3366ff;
--accent: #00f2ff;
--bg: #07080c;
--card-bg: rgba(255, 255, 255, 0.03);
--glass: rgba(255, 255, 255, 0.06);
--text: #ffffff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Outfit', sans-serif;
background: var(--bg);
color: var(--text);
overflow-x: hidden;
min-height: 100vh;
background-image:
radial-gradient(circle at 10% 10%, rgba(255, 61, 113, 0.12) 0%, transparent 40%),
radial-gradient(circle at 90% 90%, rgba(51, 102, 255, 0.12) 0%, transparent 40%);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 60px 24px;
position: relative;
}
header {
text-align: center;
margin-bottom: 80px;
animation: fadeInDown 1s ease-out;
}
@keyframes fadeInDown {
from { opacity: 0; transform: translateY(-30px); }
to { opacity: 1; transform: translateY(0); }
}
h1 {
font-size: clamp(2.5rem, 8vw, 4rem);
font-weight: 800;
background: linear-gradient(135deg, #fff 0%, #aaa 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 15px;
letter-spacing: -2px;
}
.badge {
background: linear-gradient(90deg, var(--primary), var(--secondary));
padding: 8px 18px;
border-radius: 40px;
font-size: 0.85rem;
font-weight: 700;
display: inline-block;
margin-bottom: 25px;
text-transform: uppercase;
letter-spacing: 1px;
box-shadow: 0 10px 30px rgba(255, 61, 113, 0.3);
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
gap: 30px;
margin-top: 20px;
}
.card {
background: var(--card-bg);
border: 1px solid var(--glass);
border-radius: 28px;
padding: 35px;
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
backdrop-filter: blur(12px);
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
}
@media (hover: hover) {
.card:hover {
transform: translateY(-12px) scale(1.02);
border-color: rgba(255,255,255,0.2);
box-shadow: 0 30px 60px rgba(0,0,0,0.5);
}
}
.card-title {
font-size: 1.5rem;
font-weight: 700;
margin-bottom: 18px;
display: flex;
align-items: center;
gap: 12px;
}
.card-title i {
width: 32px; height: 32px;
background: rgba(255,255,255,0.05);
border-radius: 8px;
display: flex; align-items: center; justify-content: center;
font-size: 1rem; color: var(--accent);
font-style: normal;
}
.card-desc {
color: #9ea3ac;
font-size: 1rem;
line-height: 1.6;
margin-bottom: 25px;
flex-grow: 1;
}
.endpoint {
font-family: 'JetBrains Mono', monospace;
background: rgba(0,0,0,0.4);
padding: 14px;
border-radius: 14px;
font-size: 0.85rem;
color: var(--accent);
border: 1px solid rgba(0,242,255,0.15);
margin-bottom: 25px;
word-break: break-all;
position: relative;
}
.endpoint::after {
content: 'GET';
position: absolute;
right: 14px; top: 14px;
font-size: 0.65rem; font-weight: 800;
color: rgba(255,255,255,0.3);
}
.btn {
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
background: #ffffff;
color: #000000;
text-decoration: none;
border-radius: 16px;
font-weight: 700;
font-size: 0.95rem;
transition: all 0.3s;
}
.btn:hover {
background: var(--primary);
color: #fff;
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(255, 61, 113, 0.4);
}
footer {
text-align: center;
padding: 80px 0 40px;
animation: fadeIn 2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.dev-tag {
font-weight: 800;
color: #666;
letter-spacing: 3px;
text-transform: uppercase;
font-size: 0.75rem;
border: 1px solid #222;
padding: 12px 30px;
border-radius: 50px;
display: inline-block;
background: rgba(255,255,255,0.01);
transition: all 0.3s;
}
.dev-tag:hover {
color: var(--text);
border-color: var(--primary);
letter-spacing: 5px;
}
@media (max-width: 480px) {
.container { padding: 40px 16px; }
.card { padding: 25px; }
h1 { margin-bottom: 10px; }
}
</style>
</head>
<body>
<div class="container">
<header>
<div class="badge">Enterprise API Solution</div>
<h1>MovieBox Pro</h1>
<p style="color: #667; font-size: 1.25rem; font-weight: 300;">State-of-the-Art Pure API Architecture</p>
</header>
<div class="grid">
<div class="card">
<div class="card-title"><i>🏠</i> Discover Home</div>
<p class="card-desc">The ultimate window into MovieBox. Headlines, recommended content, and trending blocks updated in real-time.</p>
<div class="endpoint">/home</div>
<a href="/home" target="_blank" class="btn">Launch API</a>
</div>
<div class="card">
<div class="card-title"><i>🔍</i> Smart Search</div>
<p class="card-desc">High-precision search engine results. Returns titles, posters, and slugs for lightning-fast matching.</p>
<div class="endpoint">/search?q=Attack on Titan</div>
<a href="/search?q=Attack on Titan" target="_blank" class="btn">Test Search</a>
</div>
<div class="card">
<div class="card-title"><i>🆔</i> Metadata A-Z</div>
<p class="card-desc">Deep-dive into any subject. Episodes, seasons, languages, and full high-resolution metadata trees.</p>
<div class="endpoint">/detail/{slug}</div>
<a href="/detail/attack-on-titan-hindi-kGWQOIx0d4" target="_blank" class="btn">Fetch Specs</a>
</div>
<div class="card">
<div class="card-title"><i>🎬</i> Stream Engine</div>
<p class="card-desc">Dynamic domain discovery and direct MP4 extraction. Supports multiple resolutions and qualities.</p>
<div class="endpoint">/api/stream/{subject_id}</div>
<a href="/api/stream/56988683026712168?detail_path=attack-on-titan-hindi-kGWQOIx0d4" target="_blank" class="btn">Get Player Link</a>
</div>
<div class="card">
<div class="card-title"><i>📦</i> Catalog Filters</div>
<p class="card-desc">Paginated collections for all genres. Movies, TV shows, and Animations filtered by professional criteria. Pagination Supported.</p>
<div class="endpoint">/tv-series?page=2</div>
<a href="/tv-series?page=2" target="_blank" class="btn">Test Page 2</a>
</div>
<div class="card">
<div class="card-title"><i>💬</i> Subtitle Suite</div>
<p class="card-desc">Access to the complete SRT/VTT global database for all streaming subjects.</p>
<div class="endpoint">/api/stream/{id}/captions</div>
<a href="/api/stream/6207982430134357800/captions?detail_path=breaking-bad-ej6Bp0MCAo7" target="_blank" class="btn">Retrive Subs</a>
</div>
</div>
<footer>
<div class="dev-tag">Developer: Walter</div>
</footer>
</div>
</body>
</html>
"""
return HTMLResponse(content=html_content)
@app.get("/home")
async def get_home():
url = f"{API_BASE}/home?host=moviebox.ph"
data = await _make_request(url)
sections = []
for op in data.get("data", {}).get("operatingList", []) or []:
op_type = op.get("type")
title = op.get("title", "Featured")
if op_type == "BANNER":
items = [{
"name": item.get("title") or (item.get("subject") or {}).get("title"),
"poster_url": item.get("image", {}).get("url") or (item.get("subject") or {}).get("cover", {}).get("url"),
"slug": item.get("detailPath") or (item.get("subject") or {}).get("detailPath"),
"subject_id": (item.get("subject") or {}).get("subjectId"),
"badge": (item.get("subject") or {}).get("corner")
} for item in op.get("banner", {}).get("items", []) if item.get("title") and "Communities" not in item.get("title")]
sections.append({"section": "Banner", "count": len(items), "items": items})
elif op_type in ["SUBJECTS_MOVIE", "SUBJECTS_TV", "SUBJECTS_ANIMATION"]:
items = [{
"name": sub.get("title"),
"poster_url": sub.get("cover", {}).get("url"),
"slug": sub.get("detailPath"),
"subject_id": sub.get("subjectId"),
"badge": sub.get("corner"),
"rating": sub.get("imdbRatingValue")
} for sub in op.get("subjects", [])]
sections.append({"section": title, "count": len(items), "items": items})
return {"status": "success", "sections": sections}
async def _get_category_data(tab_id: int, page: int = 1, per_page: int = 24, sort: str = "RECOMMEND") -> dict:
url = f"{API_BASE}/subject/filter"
payload = {"tabId": tab_id, "filter": {"sort": sort, "genre": "ALL", "country": "ALL", "year": "ALL", "language": "ALL"}, "page": page, "perPage": per_page}
data = await _make_request(url, method="POST", payload=payload)
inner = data.get("data", {})
raw_items = inner.get("items", inner.get("subjects", []))
items = [{
"name": sub.get("title"),
"poster_url": sub.get("cover", {}).get("url"),
"slug": sub.get("detailPath"),
"subject_id": sub.get("subjectId"),
"badge": sub.get("corner"),
"rating": sub.get("imdbRatingValue"),
"year": sub.get("releaseDate", "")[:4] if sub.get("releaseDate") else None
} for sub in raw_items]
pager = inner.get("pager", {})
total = pager.get("totalCount") or inner.get("total") or len(items)
return {"page": page, "per_page": per_page, "total": total, "items": items}
@app.get("/movies")
async def get_movies(page: int = 1, sort: str = "RECOMMEND"):
return await _get_category_data(tab_id=2, page=page, sort=sort)
@app.get("/tv-series")
async def get_tv_series(page: int = 1, sort: str = "RECOMMEND"):
return await _get_category_data(tab_id=5, page=page, sort=sort)
@app.get("/animation")
async def get_animation(page: int = 1, sort: str = "RECOMMEND"):
return await _get_category_data(tab_id=8, page=page, sort=sort)
@app.get("/search/suggest")
async def get_search_suggestions(q: str = Query(..., min_length=1)):
url = f"{API_BASE}/subject/search-suggest"
data = await _make_request(url, method="POST", payload={"keyword": q, "perPage": 10})
inner = data.get("data", {})
raw = inner.get("items", inner.get("list", []))
suggestions = []
for item in raw:
sub = item.get("subject") or {}
suggestions.append({
"title": sub.get("title") or item.get("word") or item.get("title"),
"slug": sub.get("detailPath") or item.get("detailPath"),
"subject_id": sub.get("subjectId") or item.get("subjectId")
})
return {"suggestions": suggestions}
@app.get("/search")
async def search(q: str = Query(..., min_length=1), page: int = 1):
url = f"{API_BASE}/subject/search"
data = await _make_request(url, method="POST", payload={"keyword": q, "page": page, "perPage": 20})
inner = data.get("data", {})
raw = inner.get("items", inner.get("list", []))
items = [{
"name": sub.get("title"),
"poster_url": sub.get("cover", {}).get("url"),
"slug": sub.get("detailPath"),
"subject_id": sub.get("subjectId")
} for sub in raw]
pager = inner.get("pager", {})
total = pager.get("totalCount") or inner.get("total") or len(items)
return {"query": q, "page": page, "total": total, "items": items}
@app.get("/detail/{slug}")
async def get_movie_detail(slug: str):
url = f"{API_BASE}/detail?detailPath={slug}"
return await _make_request(url)
@app.get("/api/stream/{subject_id}")
async def get_stream_sources(subject_id: str, detail_path: str, se: int = 1, ep: int = 1):
# Step 1: get the player domain
dom_data = await _make_request(f"{API_BASE}/media-player/get-domain")
domain = dom_data.get("data", "https://netfilm.world").rstrip("/")
# Step 2: build the Referer the way the real browser player does
player_referer = (
f"{domain}/spa/videoPlayPage/movies/{detail_path}"
f"?id={subject_id}&type=/movie/detail&detailSe={se}&detailEp={ep}&lang=en"
)
play_url = f"{domain}/wefeed-h5api-bff/subject/play?subjectId={subject_id}&se={se}&ep={ep}&detailPath={detail_path}"
async with httpx.AsyncClient(follow_redirects=True, timeout=25) as client:
resp = await client.get(play_url, headers={**PLAYER_HEADERS, "Referer": player_referer})
data = resp.json().get("data", {})
has_resource = data.get("hasResource", False)
streams = [
{
"resolution": f"{s.get('resolutions')}p",
"format": s.get("format"),
"url": s.get("url"),
"size": s.get("size"),
"duration": s.get("duration"),
"codec": s.get("codecName")
}
for s in data.get("streams", [])
]
return {
"subject_id": subject_id,
"se": se,
"ep": ep,
"has_resource": has_resource,
"sources": streams,
"hls": data.get("hls", []),
"dash": data.get("dash", []),
"free_episodes": data.get("freeNum"),
"limited": data.get("limited", False),
"note": None if has_resource else "No stream found for this episode."
}
@app.get("/api/stream/{subject_id}/captions")
async def get_captions(subject_id: str, detail_path: str, se: int = 1, ep: int = 1):
dom_data = await _make_request(f"{API_BASE}/media-player/get-domain")
domain = dom_data.get("data", "https://netfilm.world").rstrip("/")
player_referer = (
f"{domain}/spa/videoPlayPage/movies/{detail_path}"
f"?id={subject_id}&type=/movie/detail&detailSe={se}&detailEp={ep}&lang=en"
)
play_url = f"{domain}/wefeed-h5api-bff/subject/play?subjectId={subject_id}&se={se}&ep={ep}&detailPath={detail_path}"
async with httpx.AsyncClient(follow_redirects=True, timeout=25) as client:
play_resp = await client.get(play_url, headers={**PLAYER_HEADERS, "Referer": player_referer})
play_data = play_resp.json().get("data", {})
streams = play_data.get("streams", [])
dash = play_data.get("dash", [])
stream_id = None
stream_format = None
if streams:
stream_id = streams[0].get("id")
stream_format = streams[0].get("format", "MP4")
elif dash:
stream_id = dash[0].get("id")
stream_format = dash[0].get("format", "DASH")
if not stream_id:
return {"subject_id": subject_id, "se": se, "ep": ep, "count": 0, "captions": []}
cap_url = (
f"{API_BASE}/subject/caption"
f"?format={stream_format}&id={stream_id}&subjectId={subject_id}&detailPath={detail_path}"
)
data = await _make_request(cap_url)
inner = data.get("data", {})
captions = inner.get("captions", []) if isinstance(inner, dict) else inner
return {"subject_id": subject_id, "se": se, "ep": ep, "count": len(captions), "captions": captions}
if __name__ == "__main__":
import uvicorn
uvicorn.run("newapi:app", host="0.0.0.0", port=8000, reload=True)