slimshadow commited on
Commit
a38568b
·
verified ·
1 Parent(s): c712c4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -2,8 +2,8 @@ import streamlit as st
2
  import requests
3
 
4
  # Function to fetch video data based on the search query
5
- def fetch_video_data(query):
6
- url = f"https://www.eporner.com/api/v2/video/search/?query={query}&per_page=1&format=json"
7
  response = requests.get(url)
8
  if response.status_code == 200:
9
  return response.json()
@@ -12,17 +12,26 @@ def fetch_video_data(query):
12
  return None
13
 
14
  # Streamlit app
15
- st.title("Video Search")
16
 
17
  # Input for search query
18
  query = st.text_input("Enter your search query:")
19
 
20
- # Fetch and display video embed URL
21
  if query:
22
  data = fetch_video_data(query)
23
  if data and 'videos' in data and data['videos']:
24
- video = data['videos'][0]
25
- embed_url = video.get("embed", "Embed URL not found.")
26
- st.write(f"Embedded URL: {embed_url}")
 
 
 
 
 
 
 
 
 
27
  else:
28
- st.write("No video found for the given query.")
 
2
  import requests
3
 
4
  # Function to fetch video data based on the search query
5
+ def fetch_video_data(query, per_page=5):
6
+ url = f"https://www.eporner.com/api/v2/video/search/?query={query}&per_page={per_page}&format=json"
7
  response = requests.get(url)
8
  if response.status_code == 200:
9
  return response.json()
 
12
  return None
13
 
14
  # Streamlit app
15
+ st.title("Video Search and Player")
16
 
17
  # Input for search query
18
  query = st.text_input("Enter your search query:")
19
 
20
+ # Fetch and display video embed URLs
21
  if query:
22
  data = fetch_video_data(query)
23
  if data and 'videos' in data and data['videos']:
24
+ video_titles = [video['title'] for video in data['videos']]
25
+ selected_title = st.selectbox("Select a video to play:", video_titles)
26
+
27
+ if selected_title:
28
+ selected_video = next(video for video in data['videos'] if video['title'] == selected_title)
29
+ embed_url = selected_video.get("embed", None)
30
+
31
+ if embed_url:
32
+ st.write(f"Playing: {selected_title}")
33
+ st.video(embed_url)
34
+ else:
35
+ st.write("Embed URL not available for this video.")
36
  else:
37
+ st.write("No videos found for the given query.")