File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -7133,6 +7133,30 @@ class Video(_common.BaseModel):
71337133 default = None , description = """Video encoding, for example "video/mp4"."""
71347134 )
71357135
7136+ @classmethod
7137+ def from_file (
7138+ cls , * , location : str , mime_type : Optional [str ] = None
7139+ ) -> 'Video' :
7140+ """Loads a video from a local file.
7141+
7142+ Args:
7143+ location: The local path to load the video from.
7144+ mime_type: The MIME type of the video. If not provided, the MIME type
7145+ will be automatically determined.
7146+
7147+ Returns:
7148+ A loaded video as an `Video` object.
7149+ """
7150+ import mimetypes # pylint: disable=g-import-not-at-top
7151+ import pathlib # pylint: disable=g-import-not-at-top
7152+
7153+ video_bytes = pathlib .Path (location ).read_bytes ()
7154+
7155+ if not mime_type :
7156+ mime_type , _ = mimetypes .guess_type (location )
7157+ video = cls (video_bytes = video_bytes , mime_type = mime_type )
7158+ return video
7159+
71367160 def save (
71377161 self ,
71387162 path : str ,
You can’t perform that action at this time.
0 commit comments