2323FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2424DEALINGS IN THE SOFTWARE.
2525"""
26+ from __future__ import annotations
2627
2728import os .path
2829
@@ -71,14 +72,18 @@ class File:
7172 The file description can be set to attached images to show a alternative text.
7273 """
7374
74- __slots__ = ('fp' , 'filename' , 'description' , 'spoiler' , '_original_pos' , '_owner' , '_closer' )
75-
76- def __init__ (self ,
77- fp : Union [io .IOBase , str , bytes , 'PathLike[str]' , 'PathLike[bytes]' , int ],
78- filename : Optional [str ] = None ,
79- description : Optional [str ] = None ,
80- * ,
81- spoiler : bool = False ):
75+ __slots__ = ('fp' , 'filename' , 'description' , 'spoiler' , 'duration' , 'waveform' , '_original_pos' , '_owner' , '_closer' )
76+
77+ def __init__ (
78+ self ,
79+ fp : Union [io .IOBase , str , bytes , PathLike [str ], PathLike [bytes ], int ],
80+ filename : Optional [str ] = None ,
81+ description : Optional [str ] = None ,
82+ * ,
83+ spoiler : bool = False ,
84+ duration : Optional [float ] = None ,
85+ waveform : Optional [str ] = None
86+ ):
8287 self .fp = fp
8388
8489 if isinstance (fp , io .IOBase ):
@@ -113,6 +118,8 @@ def __init__(self,
113118 self .filename = 'SPOILER_' + self .filename
114119
115120 self .spoiler = spoiler or (self .filename is not None and self .filename .startswith ('SPOILER_' ))
121+ self .duration : Optional [float ] = duration
122+ self .waveform : Optional [str ] = waveform
116123
117124 def reset (self , * , seek = True ):
118125 # The `seek` parameter is needed because
@@ -132,11 +139,17 @@ def close(self):
132139 self ._closer ()
133140
134141 def to_dict (self , file_index : int ) -> dict :
135- return {
142+ base = {
136143 'id' : file_index ,
137144 'description' : self .description ,
138145 'filename' : self .filename
139146 }
147+ if self .duration is not None :
148+ base ['duration_secs' ] = self .duration
149+ if self .waveform is not None :
150+ base ['waveform' ] = self .waveform
151+ return base
152+
140153
141154
142155class UploadFile (File ):
0 commit comments