Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
from fastapi import FastAPI, Query, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 3 |
import httpx
|
| 4 |
-
|
|
|
|
| 5 |
app = FastAPI(title="TMDB FastAPI Backend")
|
| 6 |
|
| 7 |
# ⚠️ Hardcoded API key (NOT recommended for production)
|
|
@@ -22,11 +24,7 @@ async def now_playing(
|
|
| 22 |
page: int = Query(1, ge=1),
|
| 23 |
language: str = "en-US"
|
| 24 |
):
|
| 25 |
-
"""
|
| 26 |
-
Get 'Now Playing' movies from TMDB with pagination
|
| 27 |
-
"""
|
| 28 |
url = f"{TMDB_BASE_URL}/movie/now_playing"
|
| 29 |
-
|
| 30 |
params = {
|
| 31 |
"api_key": TMDB_API_KEY,
|
| 32 |
"language": language,
|
|
@@ -37,9 +35,63 @@ async def now_playing(
|
|
| 37 |
response = await client.get(url, params=params)
|
| 38 |
|
| 39 |
if response.status_code != 200:
|
| 40 |
-
raise HTTPException(
|
| 41 |
-
status_code=response.status_code,
|
| 42 |
-
detail="TMDB API error"
|
| 43 |
-
)
|
| 44 |
|
| 45 |
return response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Query, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from fastapi.responses import RedirectResponse
|
| 4 |
import httpx
|
| 5 |
+
import requests
|
| 6 |
+
watch_list_mv=[]
|
| 7 |
app = FastAPI(title="TMDB FastAPI Backend")
|
| 8 |
|
| 9 |
# ⚠️ Hardcoded API key (NOT recommended for production)
|
|
|
|
| 24 |
page: int = Query(1, ge=1),
|
| 25 |
language: str = "en-US"
|
| 26 |
):
|
|
|
|
|
|
|
|
|
|
| 27 |
url = f"{TMDB_BASE_URL}/movie/now_playing"
|
|
|
|
| 28 |
params = {
|
| 29 |
"api_key": TMDB_API_KEY,
|
| 30 |
"language": language,
|
|
|
|
| 35 |
response = await client.get(url, params=params)
|
| 36 |
|
| 37 |
if response.status_code != 200:
|
| 38 |
+
raise HTTPException(status_code=response.status_code, detail="TMDB API error")
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
return response.json()
|
| 41 |
+
|
| 42 |
+
@app.get("/movies/{movie_id}")
|
| 43 |
+
async def movie_detail(
|
| 44 |
+
movie_id: int,
|
| 45 |
+
language: str = "en-US"
|
| 46 |
+
):
|
| 47 |
+
"""
|
| 48 |
+
Get details of a specific movie by ID from TMDB
|
| 49 |
+
"""
|
| 50 |
+
url = f"{TMDB_BASE_URL}/movie/{movie_id}"
|
| 51 |
+
params = {
|
| 52 |
+
"api_key": TMDB_API_KEY,
|
| 53 |
+
"language": language
|
| 54 |
+
}
|
| 55 |
+
similar_url=f"https://api.themoviedb.org/3/movie/{movie_id}/similar?api_key={TMDB_API_KEY}&language=en-US&page=1"
|
| 56 |
+
response_similar=requests.get(similar_url)
|
| 57 |
+
data_similar=response_similar.json()
|
| 58 |
+
|
| 59 |
+
async with httpx.AsyncClient() as client:
|
| 60 |
+
response = await client.get(url, params=params)
|
| 61 |
+
|
| 62 |
+
if response.status_code != 200:
|
| 63 |
+
raise HTTPException(status_code=response.status_code, detail="TMDB API error")
|
| 64 |
+
|
| 65 |
+
return {
|
| 66 |
+
'CinemaHub':response.json(),
|
| 67 |
+
'Similar_Movies':data_similar
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@app.get('/movies')
|
| 72 |
+
def play_movie(movie_name:str):
|
| 73 |
+
response=requests.get(f"https://api.themoviedb.org/3/search/movie?api_key={TMDB_API_KEY}&query={movie_name}&language=en-US&page=1")
|
| 74 |
+
data=response.json()
|
| 75 |
+
get_id=data['results'][0]['id']
|
| 76 |
+
streaming_url=f"https://vidsrc-embed.ru/embed/movie/{get_id}"
|
| 77 |
+
return {'CinemaHub': streaming_url}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
@app.get('/movies/search/{movie_name}')
|
| 84 |
+
def search_movie(movie_name:str):
|
| 85 |
+
response=requests.get(f"https://api.themoviedb.org/3/search/movie?api_key={TMDB_API_KEY}&query={movie_name}&language=en-US&page=1")
|
| 86 |
+
data=response.json()
|
| 87 |
+
return{
|
| 88 |
+
'CinemaHub':data
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@app.get('/movies/watch_list/{movie_id}')
|
| 93 |
+
def watch_list(movie_id:int):
|
| 94 |
+
watch_list_mv.append(movie_id)
|
| 95 |
+
return{
|
| 96 |
+
'CinemaHub':watch_list_mv
|
| 97 |
+
}
|