allow multiple image types
All checks were successful
Docker Image / build (push) Successful in 1m5s
All checks were successful
Docker Image / build (push) Successful in 1m5s
This commit is contained in:
38
watcher.py
38
watcher.py
@@ -265,26 +265,36 @@ def build_storj_screenshot_urls(session: requests.Session, app_id: str) -> List[
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
screenshot_urls: List[str] = []
|
screenshot_urls: List[str] = []
|
||||||
|
image_extensions = ["png", "jpg", "jpeg", "webp"]
|
||||||
for index in range(1, MAX_SCREENSHOTS_PER_APP + 1):
|
for index in range(1, MAX_SCREENSHOTS_PER_APP + 1):
|
||||||
screenshot_url = f"{MEDIA_BASE_URL.rstrip('/')}/apps/{app_id}/screenshots/screenshot{index}.png"
|
matched_for_index = False
|
||||||
try:
|
for extension in image_extensions:
|
||||||
response = session.get(
|
screenshot_url = (
|
||||||
screenshot_url,
|
f"{MEDIA_BASE_URL.rstrip('/')}/apps/{app_id}/screenshots/screenshot{index}.{extension}"
|
||||||
timeout=REQUEST_TIMEOUT_SECONDS,
|
|
||||||
headers={"User-Agent": USER_AGENT},
|
|
||||||
)
|
)
|
||||||
except requests.RequestException:
|
try:
|
||||||
|
response = session.get(
|
||||||
|
screenshot_url,
|
||||||
|
timeout=REQUEST_TIMEOUT_SECONDS,
|
||||||
|
headers={"User-Agent": USER_AGENT},
|
||||||
|
)
|
||||||
|
except requests.RequestException:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
continue
|
||||||
|
|
||||||
|
content_type = str(response.headers.get("Content-Type", "")).lower()
|
||||||
|
if content_type and "image" not in content_type:
|
||||||
|
continue
|
||||||
|
|
||||||
|
screenshot_urls.append(screenshot_url)
|
||||||
|
matched_for_index = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if response.status_code != 200:
|
if not matched_for_index:
|
||||||
break
|
break
|
||||||
|
|
||||||
content_type = str(response.headers.get("Content-Type", "")).lower()
|
|
||||||
if content_type and "image" not in content_type:
|
|
||||||
break
|
|
||||||
|
|
||||||
screenshot_urls.append(screenshot_url)
|
|
||||||
|
|
||||||
return screenshot_urls
|
return screenshot_urls
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user