Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,27 @@ PROXY_LIST = [
|
|
| 38 |
FAILED_LOG_PATH = "failed_downloads.txt"
|
| 39 |
BLOCKED_SITES = ["bigw.com.au"]
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
session = requests.Session()
|
| 42 |
# --- Utility Functions ---
|
| 43 |
def process_url_images(data, fmt, w, h):
|
|
|
|
| 38 |
FAILED_LOG_PATH = "failed_downloads.txt"
|
| 39 |
BLOCKED_SITES = ["bigw.com.au"]
|
| 40 |
|
| 41 |
+
def random_headers(referer):
|
| 42 |
+
"""Return a rotating User‑Agent + referer header dict."""
|
| 43 |
+
return {
|
| 44 |
+
"User-Agent": random.choice(USER_AGENTS),
|
| 45 |
+
"Referer": referer
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
def try_download(url, headers, proxies):
|
| 49 |
+
"""
|
| 50 |
+
Attempt a simple GET through a proxy dict {"http":..., "https":...}.
|
| 51 |
+
Returns the response if status_code==200, else None.
|
| 52 |
+
"""
|
| 53 |
+
try:
|
| 54 |
+
resp = session.get(url, headers=headers, proxies=proxies, stream=True, timeout=8)
|
| 55 |
+
if resp.status_code == 200 and "image" in resp.headers.get("Content-Type", ""):
|
| 56 |
+
return resp
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"⚠️ Proxy download error ({proxies}): {e}")
|
| 59 |
+
return None
|
| 60 |
+
|
| 61 |
+
|
| 62 |
session = requests.Session()
|
| 63 |
# --- Utility Functions ---
|
| 64 |
def process_url_images(data, fmt, w, h):
|