yuyutsu07 commited on
Commit
f641632
1 Parent(s): 76672e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -40
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import imdb
3
  import requests
4
  import logging
 
5
 
6
  # Configure logging
7
  logging.basicConfig(level=logging.INFO)
@@ -9,7 +10,7 @@ logger = logging.getLogger(__name__)
9
 
10
  # --- API Configuration ---
11
  API_BASE_URL = "https://vidsrc-pi.vercel.app"
12
- PROXY_URL = "https://simple-proxy.yuyutsu.workers.dev/"
13
 
14
  # --- 1. Setup ---
15
  ia = imdb.IMDb()
@@ -18,56 +19,44 @@ ia = imdb.IMDb()
18
 
19
  def test_proxy_connection():
20
  try:
 
 
 
 
 
21
  response = requests.get(PROXY_URL, timeout=5)
22
  logger.info(f"Proxy connection test result: {response.status_code}")
23
- return response.status_code == 200
 
 
 
24
  except requests.exceptions.RequestException as e:
25
  logger.error(f"Proxy connection test failed: {e}")
26
- return False
27
-
28
- def search_titles(query):
29
- """Searches IMDb for titles matching the given query."""
30
- try:
31
- results = ia.search_movie(query)
32
- return results
33
- except Exception as e:
34
- logger.error(f"Error searching titles: {e}")
35
- return []
36
 
37
- def get_poster_url(movie):
38
- """Retrieves the poster URL from an IMDb movie object."""
39
- poster_url = movie.get('cover url')
40
- if poster_url:
41
- return poster_url
42
- return "https://via.placeholder.com/150x225?text=No+Poster+Available"
43
-
44
- def get_video_url(imdb_id):
45
- """Fetches the video stream URL from your API via the proxy."""
46
- destination_url = f"{API_BASE_URL}/vidsrc/tt{imdb_id}"
47
- proxy_url = f"{PROXY_URL}?destination={destination_url}"
48
- try:
49
- logger.info(f"Attempting to connect to: {proxy_url}")
50
- response = requests.get(proxy_url, timeout=10)
51
- logger.info(f"Status Code: {response.status_code}")
52
- logger.info(f"Response Content: {response.content[:100]}...") # Print first 100 chars
53
- response.raise_for_status()
54
- data = response.json()
55
- if data.get("sources"):
56
- for s in data['sources']:
57
- if s['data'].get("stream"):
58
- return s['data']['stream']
59
- return None
60
- except requests.exceptions.RequestException as e:
61
- logger.error(f"Error fetching video: {e}")
62
- return None
63
 
64
  # --- 3. Streamlit App ---
65
  st.title("Movie & TV Show Streamer")
66
 
67
  # Test proxy connection at startup
68
- if not test_proxy_connection():
69
- st.error("Unable to connect to the proxy. Please check your internet connection or try again later.")
 
 
 
 
 
 
 
 
 
 
 
 
70
  else:
 
 
71
  search_query = st.text_input("Enter a movie or TV show title:")
72
 
73
  # --- 4. Search & Display Results ---
 
2
  import imdb
3
  import requests
4
  import logging
5
+ import socket
6
 
7
  # Configure logging
8
  logging.basicConfig(level=logging.INFO)
 
10
 
11
  # --- API Configuration ---
12
  API_BASE_URL = "https://vidsrc-pi.vercel.app"
13
+ PROXY_URL = "https://simple-proxy.uyutsu.workers.dev/"
14
 
15
  # --- 1. Setup ---
16
  ia = imdb.IMDb()
 
19
 
20
  def test_proxy_connection():
21
  try:
22
+ # First, try to resolve the hostname
23
+ ip_address = socket.gethostbyname(PROXY_URL.split("//")[1])
24
+ logger.info(f"Resolved IP address: {ip_address}")
25
+
26
+ # If resolution succeeds, try to connect
27
  response = requests.get(PROXY_URL, timeout=5)
28
  logger.info(f"Proxy connection test result: {response.status_code}")
29
+ return True, f"Connected successfully. Status code: {response.status_code}"
30
+ except socket.gaierror as e:
31
+ logger.error(f"DNS resolution failed: {e}")
32
+ return False, f"Failed to resolve hostname: {e}"
33
  except requests.exceptions.RequestException as e:
34
  logger.error(f"Proxy connection test failed: {e}")
35
+ return False, f"Connection failed: {e}"
 
 
 
 
 
 
 
 
 
36
 
37
+ # ... (keep the rest of the helper functions as they were) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  # --- 3. Streamlit App ---
40
  st.title("Movie & TV Show Streamer")
41
 
42
  # Test proxy connection at startup
43
+ proxy_status, proxy_message = test_proxy_connection()
44
+ if not proxy_status:
45
+ st.error(f"Unable to connect to the proxy. Error: {proxy_message}")
46
+ st.info("Debugging Information:")
47
+ st.code(f"""
48
+ Proxy URL: {PROXY_URL}
49
+ API Base URL: {API_BASE_URL}
50
+
51
+ Try to ping the proxy server:
52
+ ping {PROXY_URL.split("//")[1]}
53
+
54
+ Try to curl the proxy server:
55
+ curl -v {PROXY_URL}
56
+ """)
57
  else:
58
+ st.success(f"Connected to proxy successfully. {proxy_message}")
59
+
60
  search_query = st.text_input("Enter a movie or TV show title:")
61
 
62
  # --- 4. Search & Display Results ---