@@ -54,7 +54,9 @@ async def upload_to_tg(
54
54
from_user ,
55
55
dict_contatining_uploaded_files ,
56
56
edit_media = False ,
57
- custom_caption = None
57
+ custom_caption = None ,
58
+ force_doc = False ,
59
+ cfn = None
58
60
):
59
61
LOGGER .info (local_file_name )
60
62
base_file_name = os .path .basename (local_file_name )
@@ -90,7 +92,9 @@ async def upload_to_tg(
90
92
from_user ,
91
93
dict_contatining_uploaded_files ,
92
94
edit_media ,
93
- caption_str
95
+ caption_str ,
96
+ force_doc = force_doc ,
97
+ cfn = cfn
94
98
)
95
99
else :
96
100
if os .path .getsize (local_file_name ) > TG_MAX_FILE_SIZE :
@@ -118,25 +122,40 @@ async def upload_to_tg(
118
122
message ,
119
123
os .path .join (splitted_dir , le_file ),
120
124
from_user ,
121
- dict_contatining_uploaded_files
125
+ dict_contatining_uploaded_files ,
126
+ force_doc = force_doc ,
127
+ cfn = cfn
122
128
)
123
129
else :
124
130
sent_message = await upload_single_file (
125
131
message ,
126
132
local_file_name ,
127
133
caption_str ,
128
134
from_user ,
129
- edit_media
135
+ edit_media ,
136
+ force_doc ,
137
+ cfn
130
138
)
131
139
if sent_message is not None :
132
140
dict_contatining_uploaded_files [os .path .basename (local_file_name )] = sent_message .message_id
133
141
# await message.delete()
134
142
return dict_contatining_uploaded_files
135
143
136
144
137
- async def upload_single_file (message , local_file_name , caption_str , from_user , edit_media ):
145
+ async def upload_single_file (
146
+ message ,
147
+ local_file_name ,
148
+ caption_str ,
149
+ from_user ,
150
+ edit_media ,
151
+ force_doc = False ,
152
+ cfn = None
153
+ ):
138
154
await asyncio .sleep (EDIT_SLEEP_TIME_OUT )
139
155
sent_message = None
156
+ if cfn :
157
+ os .rename (local_file_name , cfn )
158
+ local_file_name = cfn
140
159
start_time = time .time ()
141
160
#
142
161
thumbnail_location = os .path .join (
@@ -151,7 +170,10 @@ async def upload_single_file(message, local_file_name, caption_str, from_user, e
151
170
message_for_progress_display = await message .reply_text (
152
171
"starting upload of {}" .format (os .path .basename (local_file_name ))
153
172
)
154
- if local_file_name .upper ().endswith (("MKV" , "MP4" , "WEBM" )):
173
+
174
+ if local_file_name .upper ().endswith ((
175
+ "M4V" , "MP4" , "MOV" , "FLV" , "WMV" , "3GP" , "MPEG" , "WEBM" , "MKV"
176
+ )) and not force_doc :
155
177
metadata = extractMetadata (createParser (local_file_name ))
156
178
duration = 0
157
179
if metadata .has ("duration" ):
@@ -230,7 +252,10 @@ async def upload_single_file(message, local_file_name, caption_str, from_user, e
230
252
)
231
253
if thumb is not None :
232
254
os .remove (thumb )
233
- elif local_file_name .upper ().endswith (("MP3" , "M4A" , "M4B" , "FLAC" , "WAV" )):
255
+
256
+ elif local_file_name .upper ().endswith ((
257
+ "MP3" , "M4A" , "M4B" , "FLAC" , "WAV" , "AIF" , "OGG" , "AAC" , "DTS"
258
+ )) and not force_doc :
234
259
metadata = extractMetadata (createParser (local_file_name ))
235
260
duration = 0
236
261
title = ""
@@ -285,6 +310,7 @@ async def upload_single_file(message, local_file_name, caption_str, from_user, e
285
310
)
286
311
if thumb is not None :
287
312
os .remove (thumb )
313
+
288
314
else :
289
315
thumb_image_path = None
290
316
if os .path .isfile (thumbnail_location ):
@@ -330,5 +356,6 @@ async def upload_single_file(message, local_file_name, caption_str, from_user, e
330
356
331
357
if message .message_id != message_for_progress_display .message_id :
332
358
await message_for_progress_display .delete ()
359
+
333
360
os .remove (local_file_name )
334
361
return sent_message
0 commit comments