File size: 3,604 Bytes
8709d5a
 
 
8948281
f641632
8948281
 
 
 
8709d5a
 
8948281
024fc80
8709d5a
 
8948281
8709d5a
 
 
9c715a3
8948281
f641632
 
 
 
 
9c715a3
8948281
f641632
 
 
 
8948281
 
f641632
8948281
f641632
8709d5a
9c715a3
8709d5a
 
8948281
f641632
 
 
 
 
 
 
 
 
 
 
 
 
 
9c715a3
f641632
 
9c715a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8948281
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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://simple-proxy.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.")