ChandimaPrabath
commited on
Commit
•
db46eb3
1
Parent(s):
6dcf562
patch aiofiles
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ from Instance import Instance
|
|
5 |
from api import LoadBalancerAPI
|
6 |
import os
|
7 |
import re
|
|
|
|
|
8 |
# Constants and Configuration
|
9 |
CACHE_DIR = os.getenv("CACHE_DIR")
|
10 |
TOKEN = os.getenv("TOKEN")
|
@@ -42,9 +44,9 @@ async def serve_video(file_path: str, request: Request):
|
|
42 |
'Content-Length': str(end - start + 1),
|
43 |
'Content-Type': 'video/mp4' # Change as per your video format
|
44 |
}
|
45 |
-
with open(file_path, 'rb') as f:
|
46 |
-
f.seek(start)
|
47 |
-
data = f.read(end - start + 1)
|
48 |
return Response(content=data, status_code=206, headers=headers)
|
49 |
|
50 |
# Fallback for serving the whole file if no range requested
|
@@ -99,7 +101,7 @@ async def get_movie_api(request: Request, title: str):
|
|
99 |
return JSONResponse({"status": "Download started", "film_id": film_id})
|
100 |
|
101 |
@app.get("/api/get/tv/{title}/{season}/{episode}")
|
102 |
-
async def get_tv_show_api(title: str, season: str, episode: str):
|
103 |
"""Endpoint to get the TV show by title, season, and episode."""
|
104 |
if not title or not season or not episode:
|
105 |
raise HTTPException(status_code=400, detail="Title, season, and episode parameters are required")
|
@@ -110,7 +112,7 @@ async def get_tv_show_api(title: str, season: str, episode: str):
|
|
110 |
if episode in ep:
|
111 |
cache_path = instance.TV_STORE[title][season][ep]
|
112 |
if os.path.exists(cache_path):
|
113 |
-
return
|
114 |
|
115 |
tv_path = instance.find_tv_path(title)
|
116 |
|
|
|
5 |
from api import LoadBalancerAPI
|
6 |
import os
|
7 |
import re
|
8 |
+
import aiofiles
|
9 |
+
|
10 |
# Constants and Configuration
|
11 |
CACHE_DIR = os.getenv("CACHE_DIR")
|
12 |
TOKEN = os.getenv("TOKEN")
|
|
|
44 |
'Content-Length': str(end - start + 1),
|
45 |
'Content-Type': 'video/mp4' # Change as per your video format
|
46 |
}
|
47 |
+
async with aiofiles.open(file_path, 'rb') as f:
|
48 |
+
await f.seek(start)
|
49 |
+
data = await f.read(end - start + 1)
|
50 |
return Response(content=data, status_code=206, headers=headers)
|
51 |
|
52 |
# Fallback for serving the whole file if no range requested
|
|
|
101 |
return JSONResponse({"status": "Download started", "film_id": film_id})
|
102 |
|
103 |
@app.get("/api/get/tv/{title}/{season}/{episode}")
|
104 |
+
async def get_tv_show_api(request: Request, title: str, season: str, episode: str):
|
105 |
"""Endpoint to get the TV show by title, season, and episode."""
|
106 |
if not title or not season or not episode:
|
107 |
raise HTTPException(status_code=400, detail="Title, season, and episode parameters are required")
|
|
|
112 |
if episode in ep:
|
113 |
cache_path = instance.TV_STORE[title][season][ep]
|
114 |
if os.path.exists(cache_path):
|
115 |
+
return await serve_video(cache_path, request)
|
116 |
|
117 |
tv_path = instance.find_tv_path(title)
|
118 |
|