File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
2
import tempfile
3
3
from typing import Callable , List , Optional , Union
4
+ from urllib .parse import unquote , urlparse
4
5
5
6
import PIL .Image
6
7
import PIL .ImageOps
@@ -80,12 +81,22 @@ def load_video(
80
81
)
81
82
82
83
if is_url :
83
- video_data = requests .get (video , stream = True ).raw
84
- suffix = os .path .splitext (video )[1 ] or ".mp4"
84
+ response = requests .get (video , stream = True )
85
+ if response .status_code != 200 :
86
+ raise ValueError (f"Failed to download video. Status code: { response .status_code } " )
87
+
88
+ parsed_url = urlparse (video )
89
+ file_name = os .path .basename (unquote (parsed_url .path ))
90
+
91
+ suffix = os .path .splitext (file_name )[1 ] or ".mp4"
85
92
video_path = tempfile .NamedTemporaryFile (suffix = suffix , delete = False ).name
93
+
86
94
was_tempfile_created = True
95
+
96
+ video_data = response .iter_content (chunk_size = 8192 )
87
97
with open (video_path , "wb" ) as f :
88
- f .write (video_data .read ())
98
+ for chunk in video_data :
99
+ f .write (chunk )
89
100
90
101
video = video_path
91
102
You can’t perform that action at this time.
0 commit comments