Skip to content

Commit

Permalink
Merge pull request #917 from rewbs/improve-download-format-check
Browse files Browse the repository at this point in the history
Don't reject URLs that are for valid video formats but where the URL doesn't end with the extension (e.g. if there is a query string).
  • Loading branch information
kabachuha committed Oct 29, 2023
2 parents 8dcb139 + e1b0499 commit 6e99b31
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripts/deforum_helpers/video_audio_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,21 @@ def is_vid_path_valid(video_path):
# vid path is actually a URL, check it
if video_path.startswith('http://') or video_path.startswith('https://'):
response = requests.head(video_path, allow_redirects=True)
extension = video_path.rsplit('?', 1)[0] # remove query string before checking file format extension.
content_disposition = response.headers.get('Content-Disposition')
if content_disposition:
# Attempt to extract the filename from the Content-Disposition header
match = re.search(r'filename="?(?P<filename>[^"]+)"?', content_disposition)
if match:
extension = match.group('filename').rsplit('.', 1)[-1].lower()
if response.status_code == 404:
raise ConnectionError(f"Video URL {video_path} is not valid. Response status code: {response.status_code}")
elif response.status_code == 302:
response = requests.head(response.headers['location'], allow_redirects=True)
if response.status_code != 200:
raise ConnectionError(f"Video URL {video_path} is not valid. Response status code: {response.status_code}")
if extension not in file_formats:
raise ValueError(f"Video file {video_path} has format '{extension}', which not supported. Supported formats are: {file_formats}")
raise ValueError(f"Video file {video_path} has format '{extension}', which is not supported. Supported formats are: {file_formats}")
else:
video_path = os.path.realpath(video_path)
if not os.path.exists(video_path):
Expand Down

0 comments on commit 6e99b31

Please sign in to comment.