@@ -85,7 +85,7 @@ def otel_event(self, settings: InstrumentationSettings) -> Event:
8585    __repr__  =  _utils .dataclasses_no_defaults_repr 
8686
8787
88- @dataclass (repr = False ) 
88+ @dataclass (init = False ,  repr = False ) 
8989class  FileUrl (ABC ):
9090    """Abstract base class for any URL-based file.""" 
9191
@@ -106,11 +106,29 @@ class FileUrl(ABC):
106106    - `GoogleModel`: `VideoUrl.vendor_metadata` is used as `video_metadata`: https://ai.google.dev/gemini-api/docs/video-understanding#customize-video-processing 
107107    """ 
108108
109-     @property  
109+     _media_type : str  |  None  =  field (init = False , repr = False )
110+ 
111+     def  __init__ (
112+         self ,
113+         url : str ,
114+         force_download : bool  =  False ,
115+         vendor_metadata : dict [str , Any ] |  None  =  None ,
116+         media_type : str  |  None  =  None ,
117+     ) ->  None :
118+         self .url  =  url 
119+         self .vendor_metadata  =  vendor_metadata 
120+         self .force_download  =  force_download 
121+         self ._media_type  =  media_type 
122+ 
110123    @abstractmethod  
111-     def  media_type (self ) ->  str :
124+     def  _infer_media_type (self ) ->  str :
112125        """Return the media type of the file, based on the url.""" 
113126
127+     @property  
128+     def  media_type (self ) ->  str :
129+         """Return the media type of the file, based on the url or the provided `_media_type`.""" 
130+         return  self ._media_type  or  self ._infer_media_type ()
131+ 
114132    @property  
115133    @abstractmethod  
116134    def  format (self ) ->  str :
@@ -119,7 +137,7 @@ def format(self) -> str:
119137    __repr__  =  _utils .dataclasses_no_defaults_repr 
120138
121139
122- @dataclass (repr = False ) 
140+ @dataclass (init = False ,  repr = False ) 
123141class  VideoUrl (FileUrl ):
124142    """A URL to a video.""" 
125143
@@ -129,8 +147,18 @@ class VideoUrl(FileUrl):
129147    kind : Literal ['video-url' ] =  'video-url' 
130148    """Type identifier, this is available on all parts as a discriminator.""" 
131149
132-     @property  
133-     def  media_type (self ) ->  VideoMediaType :
150+     def  __init__ (
151+         self ,
152+         url : str ,
153+         force_download : bool  =  False ,
154+         vendor_metadata : dict [str , Any ] |  None  =  None ,
155+         media_type : str  |  None  =  None ,
156+         kind : Literal ['video-url' ] =  'video-url' ,
157+     ) ->  None :
158+         super ().__init__ (url = url , force_download = force_download , vendor_metadata = vendor_metadata , media_type = media_type )
159+         self .kind  =  kind 
160+ 
161+     def  _infer_media_type (self ) ->  VideoMediaType :
134162        """Return the media type of the video, based on the url.""" 
135163        if  self .url .endswith ('.mkv' ):
136164            return  'video/x-matroska' 
@@ -170,7 +198,7 @@ def format(self) -> VideoFormat:
170198        return  _video_format_lookup [self .media_type ]
171199
172200
173- @dataclass (repr = False ) 
201+ @dataclass (init = False ,  repr = False ) 
174202class  AudioUrl (FileUrl ):
175203    """A URL to an audio file.""" 
176204
@@ -180,8 +208,18 @@ class AudioUrl(FileUrl):
180208    kind : Literal ['audio-url' ] =  'audio-url' 
181209    """Type identifier, this is available on all parts as a discriminator.""" 
182210
183-     @property  
184-     def  media_type (self ) ->  AudioMediaType :
211+     def  __init__ (
212+         self ,
213+         url : str ,
214+         force_download : bool  =  False ,
215+         vendor_metadata : dict [str , Any ] |  None  =  None ,
216+         media_type : str  |  None  =  None ,
217+         kind : Literal ['audio-url' ] =  'audio-url' ,
218+     ) ->  None :
219+         super ().__init__ (url = url , force_download = force_download , vendor_metadata = vendor_metadata , media_type = media_type )
220+         self .kind  =  kind 
221+ 
222+     def  _infer_media_type (self ) ->  AudioMediaType :
185223        """Return the media type of the audio file, based on the url. 
186224
187225        References: 
@@ -208,7 +246,7 @@ def format(self) -> AudioFormat:
208246        return  _audio_format_lookup [self .media_type ]
209247
210248
211- @dataclass (repr = False ) 
249+ @dataclass (init = False ,  repr = False ) 
212250class  ImageUrl (FileUrl ):
213251    """A URL to an image.""" 
214252
@@ -218,8 +256,18 @@ class ImageUrl(FileUrl):
218256    kind : Literal ['image-url' ] =  'image-url' 
219257    """Type identifier, this is available on all parts as a discriminator.""" 
220258
221-     @property  
222-     def  media_type (self ) ->  ImageMediaType :
259+     def  __init__ (
260+         self ,
261+         url : str ,
262+         force_download : bool  =  False ,
263+         vendor_metadata : dict [str , Any ] |  None  =  None ,
264+         media_type : str  |  None  =  None ,
265+         kind : Literal ['image-url' ] =  'image-url' ,
266+     ) ->  None :
267+         super ().__init__ (url = url , force_download = force_download , vendor_metadata = vendor_metadata , media_type = media_type )
268+         self .kind  =  kind 
269+ 
270+     def  _infer_media_type (self ) ->  ImageMediaType :
223271        """Return the media type of the image, based on the url.""" 
224272        if  self .url .endswith (('.jpg' , '.jpeg' )):
225273            return  'image/jpeg' 
@@ -241,7 +289,7 @@ def format(self) -> ImageFormat:
241289        return  _image_format_lookup [self .media_type ]
242290
243291
244- @dataclass (repr = False ) 
292+ @dataclass (init = False ,  repr = False ) 
245293class  DocumentUrl (FileUrl ):
246294    """The URL of the document.""" 
247295
@@ -251,8 +299,18 @@ class DocumentUrl(FileUrl):
251299    kind : Literal ['document-url' ] =  'document-url' 
252300    """Type identifier, this is available on all parts as a discriminator.""" 
253301
254-     @property  
255-     def  media_type (self ) ->  str :
302+     def  __init__ (
303+         self ,
304+         url : str ,
305+         force_download : bool  =  False ,
306+         vendor_metadata : dict [str , Any ] |  None  =  None ,
307+         media_type : str  |  None  =  None ,
308+         kind : Literal ['document-url' ] =  'document-url' ,
309+     ) ->  None :
310+         super ().__init__ (url = url , force_download = force_download , vendor_metadata = vendor_metadata , media_type = media_type )
311+         self .kind  =  kind 
312+ 
313+     def  _infer_media_type (self ) ->  str :
256314        """Return the media type of the document, based on the url.""" 
257315        type_ , _  =  guess_type (self .url )
258316        if  type_  is  None :
0 commit comments