Tggggg / app.py
yuyutsu07's picture
Update app.py
4bba265 verified
raw
history blame
3.6 kB
import streamlit as st
import imdb
import requests
import logging
import socket
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# --- API Configuration ---
API_BASE_URL = "https://vidsrc-pi.vercel.app"
PROXY_URL = "https://movie.yuyutsu.workers.dev"
# --- 1. Setup ---
ia = imdb.IMDb()
# --- 2. Helper Functions ---
def test_proxy_connection():
try:
# First, try to resolve the hostname
ip_address = socket.gethostbyname(PROXY_URL.split("//")[1])
logger.info(f"Resolved IP address: {ip_address}")
# If resolution succeeds, try to connect
response = requests.get(PROXY_URL, timeout=5)
logger.info(f"Proxy connection test result: {response.status_code}")
return True, f"Connected successfully. Status code: {response.status_code}"
except socket.gaierror as e:
logger.error(f"DNS resolution failed: {e}")
return False, f"Failed to resolve hostname: {e}"
except requests.exceptions.RequestException as e:
logger.error(f"Proxy connection test failed: {e}")
return False, f"Connection failed: {e}"
# ... (keep the rest of the helper functions as they were) ...
# --- 3. Streamlit App ---
st.title("Movie & TV Show Streamer")
# Test proxy connection at startup
proxy_status, proxy_message = test_proxy_connection()
if not proxy_status:
st.error(f"Unable to connect to the proxy. Error: {proxy_message}")
st.info("Debugging Information:")
st.code(f"""
Proxy URL: {PROXY_URL}
API Base URL: {API_BASE_URL}
Try to ping the proxy server:
ping {PROXY_URL.split("//")[1]}
Try to curl the proxy server:
curl -v {PROXY_URL}
""")
else:
st.success(f"Connected to proxy successfully. {proxy_message}")
search_query = st.text_input("Enter a movie or TV show title:")
# --- 4. Search & Display Results ---
if search_query:
with st.spinner('Searching for titles...'):
results = search_titles(search_query)
if results:
for result in results[:5]:
try:
movie = ia.get_movie(result.movieID)
title = movie['title']
year = movie.get('year')
poster_url = get_poster_url(movie)
col1, col2 = st.columns([1, 4])
with col1:
st.image(poster_url, width=150)
with col2:
st.subheader(title)
if year:
st.caption(f"({year})")
if st.button(f"Watch {title}", key=f"watch_{result.movieID}"):
st.session_state.selected_imdb_id = result.movieID
except Exception as e:
logger.error(f"Error processing result: {e}")
st.error("An error occurred while processing this result.")
else:
st.info("No results found. Please try another search.")
# --- 5. Handle Movie/Show Selection & Video Playback ---
if 'selected_imdb_id' in st.session_state:
imdb_id = st.session_state.selected_imdb_id
with st.spinner('Fetching video stream...'):
video_url = get_video_url(imdb_id)
if video_url:
st.video(video_url)
else:
st.warning("Video stream not found for this title.")
# --- 6. Footer ---
st.markdown("---")
st.caption("Powered by IMDb and vidsrc. For educational purposes only.")