Make TDV steal more resilient

This commit is contained in:
Kumi 2021-02-27 14:37:26 +01:00
parent bb20dc3119
commit edef07a592

View file

@ -6,8 +6,13 @@ import subprocess
import tempfile import tempfile
import pathlib import pathlib
import os import os
from stitching import tiles_to_equirectangular_blender, multistitch from stitching import tiles_to_equirectangular_blender, multistitch
from socket import timeout
from ssl import SSLError
from urllib.error import URLError, HTTPError
def tdv_normalize(url): def tdv_normalize(url):
''' '''
Takes the URL of any image in a tdv panorama and returns a string Takes the URL of any image in a tdv panorama and returns a string
@ -42,16 +47,7 @@ def tdv_getmaxzoom(schema):
:return: int value of largest available zoom level :return: int value of largest available zoom level
''' '''
l = 0 return 0
while True:
try:
url = schema % ("f", l+1, 0, 0)
with urllib.request.urlopen(url) as res:
assert res.getcode() == 200
l += 1
except:
return l
def tdv_export(schema): def tdv_export(schema):
''' '''
@ -75,9 +71,18 @@ def tdv_export(schema):
while True: while True:
try: try:
res = urllib.request.urlopen(schema % (tile, maxzoom, y, x)) print("Getting %s" % (schema % (tile, maxzoom, y, x)))
while True:
try:
res = urllib.request.urlopen(schema % (tile, maxzoom, y, x), timeout=10)
assert res.getcode() == 200 assert res.getcode() == 200
fo = io.BytesIO(res.read()) fo = io.BytesIO(res.read())
break
except (timeout, SSLError, URLError) as e:
if isinstance(e, HTTPError):
raise
continue
print("Done")
img = PIL.Image.open(fo) img = PIL.Image.open(fo)
r_array.append(img) r_array.append(img)
x += 1 x += 1