Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Function to search for movies or TV shows using the TMDb API
|
| 5 |
+
def search_tmdb(query, media_type, api_key):
|
| 6 |
+
url = f"https://api.themoviedb.org/3/search/{media_type}"
|
| 7 |
+
params = {
|
| 8 |
+
"api_key": api_key,
|
| 9 |
+
"query": query,
|
| 10 |
+
"language": "en-US",
|
| 11 |
+
"page": 1,
|
| 12 |
+
}
|
| 13 |
+
response = requests.get(url, params=params)
|
| 14 |
+
results = response.json().get("results", [])
|
| 15 |
+
return results[:5] # Return only the first 5 results
|
| 16 |
+
|
| 17 |
+
# Function to generate the embed link
|
| 18 |
+
def generate_embed_link(tmdb_id, media_type):
|
| 19 |
+
base_url = "https://v1.sdsp.xyz/embed"
|
| 20 |
+
if media_type == "movie":
|
| 21 |
+
return f"{base_url}/movies/{tmdb_id}"
|
| 22 |
+
elif media_type == "tv":
|
| 23 |
+
return f"{base_url}/tv/{tmdb_id}"
|
| 24 |
+
|
| 25 |
+
# Streamlit app layout
|
| 26 |
+
st.title("TMDb Movie & TV Show Search")
|
| 27 |
+
st.write("Search for a movie or TV show and get 5 results with TMDb ID and embed link.")
|
| 28 |
+
|
| 29 |
+
# Input fields for search query and media type
|
| 30 |
+
query = st.text_input("Enter the movie or TV show name:")
|
| 31 |
+
media_type = st.selectbox("Select media type:", ["movie", "tv"])
|
| 32 |
+
|
| 33 |
+
# API key (replace 'your_api_key' with your actual TMDb API key)
|
| 34 |
+
api_key = "c8402e1c7b8bb9bcbf95b3fa3bad4d84"
|
| 35 |
+
|
| 36 |
+
if st.button("Search"):
|
| 37 |
+
if query and api_key:
|
| 38 |
+
results = search_tmdb(query, media_type, api_key)
|
| 39 |
+
if results:
|
| 40 |
+
for result in results:
|
| 41 |
+
title = result["title"] if media_type == "movie" else result["name"]
|
| 42 |
+
tmdb_id = result["id"]
|
| 43 |
+
embed_link = generate_embed_link(tmdb_id, media_type)
|
| 44 |
+
st.write(f"**Title:** {title}")
|
| 45 |
+
st.write(f"**TMDb ID:** {tmdb_id}")
|
| 46 |
+
st.write(f"**Embed Link:** [Watch here]({embed_link})")
|
| 47 |
+
st.write("---")
|
| 48 |
+
else:
|
| 49 |
+
st.write("No results found. Please try a different query.")
|
| 50 |
+
else:
|
| 51 |
+
st.write("Please enter a search query and ensure the API key is set.")
|
| 52 |
+
|