File size: 1,410 Bytes
c712c4f
 
 
 
660ce8d
a38568b
c712c4f
 
 
 
 
 
 
 
a38568b
c712c4f
 
 
 
a38568b
c712c4f
 
 
a38568b
 
 
 
 
 
 
 
 
4980804
 
a38568b
 
c712c4f
a38568b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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.")