Skip to content

Commit

Permalink
Update download_videos to handle too many redirects and missing conte…
Browse files Browse the repository at this point in the history
…nt-type
  • Loading branch information
dale-wahl committed Jan 30, 2024
1 parent e1211c7 commit 97209cb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions processors/visualisation/download_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def dmi_match_filter(vid_info, *, incomplete):
}]
success = True
self.videos_downloaded_from_url = 1
except (requests.exceptions.Timeout, requests.exceptions.SSLError, requests.exceptions.ConnectionError, FilesizeException, FailedDownload, NotAVideo) as e:
except (requests.exceptions.Timeout, requests.exceptions.SSLError, requests.exceptions.ConnectionError, requests.exceptions.TooManyRedirects, FilesizeException, FailedDownload, NotAVideo) as e:
# FilesizeException raised when file size is too large or unknown filesize (and that is disabled in 4CAT settings)
# FailedDownload raised when response other than 200 received
# NotAVideo raised due to specific Content-Type known to not be a video (and not a webpage/html that could lead to a video via YT-DLP)
Expand Down Expand Up @@ -570,9 +570,12 @@ def download_video_with_requests(self, url, results_path, max_video_size, retrie
# Verify video
# YT-DLP will download images; so we raise them differently
# TODO: test/research other possible ways to verify video links; watch for additional YT-DLP oddities
if "image" in response.headers["Content-Type"].lower():
content_type = response.headers.get("Content-Type")
if not content_type:
raise VideoStreamUnavailable(f"Unable to verify video; no Content-Type provided: {url}")
elif "image" in content_type.lower():
raise NotAVideo("Not a Video (%s): %s" % (response.headers["Content-Type"], url))
elif "video" not in response.headers["Content-Type"].lower():
elif "video" not in content_type.lower():
raise VideoStreamUnavailable(f"Does not appear to be a direct to video link: {url}; "
f"Content-Type: {response.headers['Content-Type']}")

Expand Down

0 comments on commit 97209cb

Please sign in to comment.