slimshadow's picture
Update app.py
660ce8d verified
import streamlit as st
import requests
# Function to fetch video data based on the search query
def fetch_video_data(query, per_page=200):
url = f"https://www.eporner.com/api/v2/video/search/?query={query}&per_page={per_page}&format=json"
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
st.error("Error fetching data from the API.")
return None
# Streamlit app
st.title("Video Search and Player")
# Input for search query
query = st.text_input("Enter your search query:")
# Fetch and display video embed URLs
if query:
data = fetch_video_data(query)
if data and 'videos' in data and data['videos']:
video_titles = [video['title'] for video in data['videos']]
selected_title = st.selectbox("Select a video to play:", video_titles)
if selected_title:
selected_video = next(video for video in data['videos'] if video['title'] == selected_title)
embed_url = selected_video.get("embed", None)
if embed_url:
st.write(f"Playing: {selected_title}")
# Embed the video using an iframe
st.components.v1.iframe(embed_url, width=640, height=360)
else:
st.write("Embed URL not available for this video.")
else:
st.write("No videos found for the given query.")