lexicalspace commited on
Commit
37ea118
·
verified ·
1 Parent(s): cabe089

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,18 +1,21 @@
1
- import streamlit as st
2
  import socket
 
3
 
4
- # --- NETWORK FIX: FORCE IPv4 (Must be at the top) ---
5
- # This forces the app to use standard internet (IPv4) instead of IPv6
6
- # which fixes the "[Errno -5] No address associated with hostname" error.
 
 
7
  try:
8
  _old_getaddrinfo = socket.getaddrinfo
9
  def _new_getaddrinfo(*args, **kwargs):
10
  responses = _old_getaddrinfo(*args, **kwargs)
 
11
  return [r for r in responses if r[0] == socket.AF_INET]
12
  socket.getaddrinfo = _new_getaddrinfo
13
- except:
14
  pass
15
- # ----------------------------------------------------
16
 
17
  import yt_dlp
18
  import os
@@ -23,8 +26,6 @@ import re
23
  from bs4 import BeautifulSoup
24
  import markdown
25
 
26
- # ... rest of your code ...
27
-
28
  # --- PAGE CONFIG ---
29
  st.set_page_config(
30
  page_title="Lexical Tools",
@@ -35,7 +36,6 @@ st.set_page_config(
35
 
36
  # --- SIDEBAR NAVIGATION ---
37
  st.sidebar.title("Navigation")
38
- # Default to "Toolkit" unless ?mode=downloader is in URL
39
  query_params = st.query_params
40
  default_index = 1 if query_params.get("mode") == "downloader" else 0
41
 
@@ -64,9 +64,9 @@ if app_mode == "YouTube Downloader":
64
 
65
  try:
66
  timestamp = int(time.time())
67
- # Save to a temporary folder
68
  out_tmpl = f"{timestamp}_%(title)s.%(ext)s"
69
 
 
70
  ydl_opts = {
71
  'outtmpl': out_tmpl,
72
  'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' if format_type == "Video (MP4)" else 'bestaudio/best',
@@ -78,7 +78,7 @@ if app_mode == "YouTube Downloader":
78
  'quiet': True,
79
  'no_warnings': True,
80
  'noplaylist': True,
81
- 'force_ipv4': True # <--- THIS FIXES THE NETWORK ERROR
82
  }
83
 
84
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
@@ -110,7 +110,7 @@ if app_mode == "YouTube Downloader":
110
  st.error(f"Error: {str(e)}")
111
 
112
  # ==========================================
113
- # VIEW 2: WEBMASTER TOOLKIT (Original)
114
  # ==========================================
115
  elif app_mode == "Webmaster Toolkit":
116
  st.title("⚡ Webmaster's Toolkit")
@@ -146,7 +146,6 @@ elif app_mode == "Webmaster Toolkit":
146
 
147
  if uploaded_file:
148
  original_image = Image.open(uploaded_file)
149
- # FIXED: Using use_column_width instead of container_width
150
  st.image(original_image, caption="Original", use_column_width=True)
151
 
152
  if st.button("Convert to WebP"):
 
 
1
  import socket
2
+ import streamlit as st
3
 
4
+ # ==========================================
5
+ # 🛑 CRITICAL NETWORK FIX (Must be at top)
6
+ # ==========================================
7
+ # This hack forces the server to ignore IPv6 completely.
8
+ # It fixes the "[Errno -5] No address associated with hostname" error.
9
  try:
10
  _old_getaddrinfo = socket.getaddrinfo
11
  def _new_getaddrinfo(*args, **kwargs):
12
  responses = _old_getaddrinfo(*args, **kwargs)
13
+ # Filter out IPv6 (AF_INET6) and keep only IPv4 (AF_INET)
14
  return [r for r in responses if r[0] == socket.AF_INET]
15
  socket.getaddrinfo = _new_getaddrinfo
16
+ except Exception as e:
17
  pass
18
+ # ==========================================
19
 
20
  import yt_dlp
21
  import os
 
26
  from bs4 import BeautifulSoup
27
  import markdown
28
 
 
 
29
  # --- PAGE CONFIG ---
30
  st.set_page_config(
31
  page_title="Lexical Tools",
 
36
 
37
  # --- SIDEBAR NAVIGATION ---
38
  st.sidebar.title("Navigation")
 
39
  query_params = st.query_params
40
  default_index = 1 if query_params.get("mode") == "downloader" else 0
41
 
 
64
 
65
  try:
66
  timestamp = int(time.time())
 
67
  out_tmpl = f"{timestamp}_%(title)s.%(ext)s"
68
 
69
+ # UPDATED OPTIONS: Using built-in cookies and aggressive timeouts
70
  ydl_opts = {
71
  'outtmpl': out_tmpl,
72
  'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' if format_type == "Video (MP4)" else 'bestaudio/best',
 
78
  'quiet': True,
79
  'no_warnings': True,
80
  'noplaylist': True,
81
+ 'socket_timeout': 10, # Prevent hanging
82
  }
83
 
84
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
 
110
  st.error(f"Error: {str(e)}")
111
 
112
  # ==========================================
113
+ # VIEW 2: WEBMASTER TOOLKIT
114
  # ==========================================
115
  elif app_mode == "Webmaster Toolkit":
116
  st.title("⚡ Webmaster's Toolkit")
 
146
 
147
  if uploaded_file:
148
  original_image = Image.open(uploaded_file)
 
149
  st.image(original_image, caption="Original", use_column_width=True)
150
 
151
  if st.button("Convert to WebP"):