Spaces:
Running
Running
Commit
·
cc6c746
1
Parent(s):
e580d82
Update main.py
Browse files
main.py
CHANGED
@@ -6,6 +6,9 @@ import pycountry
|
|
6 |
import datetime as dt
|
7 |
import pytz
|
8 |
from io import BytesIO
|
|
|
|
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
app.secret_key = 'green-flounder'
|
@@ -51,24 +54,16 @@ def proxy(url):
|
|
51 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
|
52 |
}
|
53 |
try:
|
54 |
-
clean_url = url.replace('proxy/', '')
|
55 |
-
print('Cleaned URL:', clean_url)
|
56 |
-
|
57 |
if '.jpg' in clean_url and 'stream' not in clean_url:
|
58 |
-
req = requests.get(
|
59 |
-
|
60 |
-
|
61 |
-
print("Response Headers:", req.headers)
|
62 |
-
return Response(req.content, content_type=content_type)
|
63 |
else:
|
64 |
-
req = requests.get(
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
except:
|
71 |
-
print(f'Redirecting')
|
72 |
return send_file('static/error.png', mimetype='image/png')
|
73 |
|
74 |
|
|
|
6 |
import datetime as dt
|
7 |
import pytz
|
8 |
from io import BytesIO
|
9 |
+
import logging
|
10 |
+
|
11 |
+
logging.basicConfig(level=logging.INFO)
|
12 |
|
13 |
app = Flask(__name__)
|
14 |
app.secret_key = 'green-flounder'
|
|
|
54 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
|
55 |
}
|
56 |
try:
|
|
|
|
|
|
|
57 |
if '.jpg' in clean_url and 'stream' not in clean_url:
|
58 |
+
req = requests.get(clean_url, headers=headers, timeout=3)
|
59 |
+
logging.info(f"Status Code: {req.status_code}, Response Headers: {req.headers}")
|
60 |
+
return Response(req.content, content_type=req.headers['content-type'])
|
|
|
|
|
61 |
else:
|
62 |
+
req = requests.get(clean_url, headers=headers, stream=True, timeout=10)
|
63 |
+
logging.info(f"Status Code: {req.status_code}, Response Headers: {req.headers}")
|
64 |
+
return Response(req.iter_content(chunk_size=512), content_type=req.headers['content-type'])
|
65 |
+
except requests.exceptions.RequestException as e:
|
66 |
+
logging.error(f"Error in proxy: {e}")
|
|
|
|
|
|
|
67 |
return send_file('static/error.png', mimetype='image/png')
|
68 |
|
69 |
|