Spaces:
Sleeping
Sleeping
Commit
·
5ccc24c
1
Parent(s):
10df67a
add routes
Browse files
app.py
CHANGED
|
@@ -114,9 +114,68 @@ async def get_season_metadata_api(series_id: int, season: str):
|
|
| 114 |
raise HTTPException(status_code=404, detail="Metadata not found")
|
| 115 |
|
| 116 |
@app.get('/api/get/instances')
|
| 117 |
-
def get_instances():
|
| 118 |
return load_balancer.instances
|
| 119 |
|
| 120 |
@app.get('/api/get/instances/health')
|
| 121 |
-
def get_instances_health():
|
| 122 |
-
return load_balancer.instances_health
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
raise HTTPException(status_code=404, detail="Metadata not found")
|
| 115 |
|
| 116 |
@app.get('/api/get/instances')
|
| 117 |
+
async def get_instances():
|
| 118 |
return load_balancer.instances
|
| 119 |
|
| 120 |
@app.get('/api/get/instances/health')
|
| 121 |
+
async def get_instances_health():
|
| 122 |
+
return load_balancer.instances_health
|
| 123 |
+
|
| 124 |
+
@app.get("/api/get/film/{title}")
|
| 125 |
+
async def get_movie_api(title: str):
|
| 126 |
+
"""Endpoint to get the movie by title."""
|
| 127 |
+
if not title:
|
| 128 |
+
raise HTTPException(status_code=400, detail="Title parameter is required")
|
| 129 |
+
|
| 130 |
+
# Check if the film is already cached
|
| 131 |
+
if title in load_balancer.FILM_STORE:
|
| 132 |
+
url = load_balancer.FILM_STORE[title]
|
| 133 |
+
return JSONResponse(content={"url": url})
|
| 134 |
+
|
| 135 |
+
movie_path = load_balancer.find_movie_path(title)
|
| 136 |
+
|
| 137 |
+
if not movie_path:
|
| 138 |
+
raise HTTPException(status_code=404, detail="Movie not found")
|
| 139 |
+
|
| 140 |
+
# Start the download in an instance
|
| 141 |
+
response = load_balancer.download_film_to_best_instance(title=title)
|
| 142 |
+
if response:
|
| 143 |
+
return JSONResponse(content=response)
|
| 144 |
+
|
| 145 |
+
@app.get("/api/get/tv/{title}/{season}/{episode}")
|
| 146 |
+
async def get_tv_show_api(title: str, season: str, episode: str):
|
| 147 |
+
"""Endpoint to get the TV show by title, season, and episode."""
|
| 148 |
+
if not title or not season or not episode:
|
| 149 |
+
raise HTTPException(status_code=400, detail="Title, season, and episode parameters are required")
|
| 150 |
+
|
| 151 |
+
# Check if the episode is already cached
|
| 152 |
+
if title in load_balancer.TV_STORE and season in load_balancer.TV_STORE[title]:
|
| 153 |
+
for ep in load_balancer.TV_STORE[title][season]:
|
| 154 |
+
if episode in ep:
|
| 155 |
+
url = load_balancer.TV_STORE[title][season][ep]
|
| 156 |
+
return JSONResponse(content={"url": url})
|
| 157 |
+
|
| 158 |
+
tv_path = load_balancer.find_tv_path(title)
|
| 159 |
+
|
| 160 |
+
if not tv_path:
|
| 161 |
+
raise HTTPException(status_code=404, detail="TV show not found")
|
| 162 |
+
|
| 163 |
+
episode_path = None
|
| 164 |
+
for directory in load_balancer.file_structure:
|
| 165 |
+
if directory['type'] == 'directory' and directory['path'] == 'tv':
|
| 166 |
+
for sub_directory in directory['contents']:
|
| 167 |
+
if sub_directory['type'] == 'directory' and title.lower() in sub_directory['path'].lower():
|
| 168 |
+
for season_dir in sub_directory['contents']:
|
| 169 |
+
if season_dir['type'] == 'directory' and season in season_dir['path']:
|
| 170 |
+
for episode_file in season_dir['contents']:
|
| 171 |
+
if episode_file['type'] == 'file' and episode in episode_file['path']:
|
| 172 |
+
episode_path = episode_file['path']
|
| 173 |
+
break
|
| 174 |
+
|
| 175 |
+
if not episode_path:
|
| 176 |
+
raise HTTPException(status_code=404, detail="Episode not found")
|
| 177 |
+
|
| 178 |
+
# Start the download in an instance
|
| 179 |
+
response = load_balancer.download_episode_to_best_instance(title=title, season=season, episode=episode)
|
| 180 |
+
if response:
|
| 181 |
+
return JSONResponse(content=response)
|