Spaces:
Running
Running
Commit
·
743016f
1
Parent(s):
5aaf6b9
Update main.py
Browse files
main.py
CHANGED
@@ -11,6 +11,18 @@ with open('video_dict.pkl', 'rb') as f:
|
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def get_ip_info(ip_address):
|
15 |
try:
|
16 |
response = requests.get(f"http://ipinfo.io/{ip_address}/json")
|
@@ -29,7 +41,7 @@ def latlon_to_pixel(loc):
|
|
29 |
|
30 |
@app.route('/video/<path:url>')
|
31 |
def video(url):
|
32 |
-
req =
|
33 |
|
34 |
def generate():
|
35 |
for chunk in req.iter_content(chunk_size=1024):
|
|
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
|
14 |
+
from time import sleep
|
15 |
+
|
16 |
+
def get_video_feed(url, retries=3, backoff_factor=0.3):
|
17 |
+
for i in range(retries):
|
18 |
+
try:
|
19 |
+
response = requests.get(url, timeout=10)
|
20 |
+
if response.status_code == 200:
|
21 |
+
return response
|
22 |
+
except requests.exceptions.Timeout:
|
23 |
+
sleep((2 ** i) * backoff_factor)
|
24 |
+
return None
|
25 |
+
|
26 |
def get_ip_info(ip_address):
|
27 |
try:
|
28 |
response = requests.get(f"http://ipinfo.io/{ip_address}/json")
|
|
|
41 |
|
42 |
@app.route('/video/<path:url>')
|
43 |
def video(url):
|
44 |
+
req = get_video_feed(url)
|
45 |
|
46 |
def generate():
|
47 |
for chunk in req.iter_content(chunk_size=1024):
|