@@ -909,8 +909,8 @@ async def search_file(
909
909
async def _push_file (
910
910
self , pf : 'PreparedFile' ,
911
911
progress_callback : Optional [Callable [[int , int ], None ]] = None ,
912
- message_to_edit : Optional [Union [int , Message ]] = None
913
- ) -> 'DecryptedRemoteBoxFile' :
912
+ message_to_edit : Optional [Union [int , Message ]] = None ,
913
+ use_slow_upload : Optional [ bool ] = False ) -> 'DecryptedRemoteBoxFile' :
914
914
"""
915
915
Uploads ``PreparedFile`` to the ``RemoteBox``
916
916
or updates already uploaded file in ``RemoteBox``.
@@ -927,6 +927,11 @@ async def _push_file(
927
927
message_to_edit (``Union[int, Message]``, optional):
928
928
If specified, will update existing ``RemoteBox``
929
929
(edit) file instead of uploading new.
930
+
931
+ use_slow_upload (``bool``, optional):
932
+ Will use default upload function from the Telethon
933
+ library instead of function from `fastelethon.py`.
934
+ Use this if you have problems with upload.
930
935
"""
931
936
if message_to_edit :
932
937
logger .info (
@@ -953,6 +958,8 @@ async def _push_file(
953
958
oe = OpenPretender (pf .file , aes_state , pf .filesize )
954
959
oe .concat_metadata (pf .metadata )
955
960
try :
961
+ assert not use_slow_upload , 'use_slow_upload enabled'
962
+
956
963
# Here we will use fast upload function
957
964
ifile = await upload_file (
958
965
self ._tc , oe ,
@@ -965,7 +972,8 @@ async def _push_file(
965
972
# probably because of fast "upload_file(...)" from
966
973
# the custom fastelethon module. We will try to
967
974
# use the slow upload from the Telethon library
968
- logger .warning (f'Fast upload FAILED, falling to SLOW!\n { format_exc ()} ' )
975
+ if not isinstance (e , AssertionError ): # We assert if use_slow_upload
976
+ logger .warning (f'Fast upload FAILED, trying with SLOW!\n { format_exc ()} ' )
969
977
970
978
ifile = await self ._tc .upload_file (
971
979
oe , file_name = urlsafe_b64encode (pf .filesalt .salt ).decode (),
@@ -1017,7 +1025,8 @@ async def _push_file(
1017
1025
1018
1026
async def push_file (
1019
1027
self , pf : 'PreparedFile' ,
1020
- progress_callback : Optional [Callable [[int , int ], None ]] = None
1028
+ progress_callback : Optional [Callable [[int , int ], None ]] = None ,
1029
+ use_slow_upload : Optional [bool ] = False ,
1021
1030
) -> 'DecryptedRemoteBoxFile' :
1022
1031
"""
1023
1032
Uploads ``PreparedFile`` to the ``RemoteBox``.
@@ -1031,15 +1040,19 @@ async def push_file(
1031
1040
A callback function accepting two parameters:
1032
1041
(downloaded_bytes, total).
1033
1042
1043
+ use_slow_upload (``bool``, optional):
1044
+ Will use default upload function from the Telethon
1045
+ library instead of function from `fastelethon.py`.
1046
+ Use this if you have problems with upload.
1034
1047
"""
1035
1048
return await self ._push_file (pf ,
1036
1049
progress_callback = progress_callback )
1037
1050
1038
1051
async def update_file (self ,
1039
1052
rbf : Union ['EncryptedRemoteBoxFile' , 'DecryptedRemoteBoxFile' ],
1040
1053
pf : 'PreparedFile' ,
1041
- progress_callback : Optional [Callable [[int , int ], None ]] = None
1042
- ) -> 'DecryptedRemoteBoxFile' :
1054
+ progress_callback : Optional [Callable [[int , int ], None ]] = None ,
1055
+ use_slow_upload : Optional [ bool ] = False ) -> 'DecryptedRemoteBoxFile' :
1043
1056
"""
1044
1057
Updates already uploaded ``RemoteBox`` file.
1045
1058
This will make a full reupload and ``Message`` edit.
@@ -1057,6 +1070,11 @@ async def update_file(self,
1057
1070
progress_callback (``Callable[[int, int], None]``, optional):
1058
1071
A callback function accepting two parameters:
1059
1072
(downloaded_bytes, total).
1073
+
1074
+ use_slow_upload (``bool``, optional):
1075
+ Will use default upload function from the Telethon
1076
+ library instead of function from `fastelethon.py`.
1077
+ Use this if you have problems with upload.
1060
1078
"""
1061
1079
if rbf is None :
1062
1080
raise RemoteFileNotFound (
@@ -1066,7 +1084,8 @@ async def update_file(self,
1066
1084
)
1067
1085
return await self ._push_file (pf ,
1068
1086
message_to_edit = rbf ._message ,
1069
- progress_callback = progress_callback )
1087
+ progress_callback = progress_callback ,
1088
+ use_slow_upload = use_slow_upload )
1070
1089
1071
1090
async def delete_files (
1072
1091
self ,
@@ -2169,7 +2188,8 @@ async def download(
2169
2188
hide_folder : bool = False , hide_name : bool = False ,
2170
2189
decrypt : bool = True , request_size : int = 524288 ,
2171
2190
offset : Optional [int ] = None ,
2172
- progress_callback : Optional [Callable [[int , int ], None ]] = None ) -> BinaryIO :
2191
+ progress_callback : Optional [Callable [[int , int ], None ]] = None ,
2192
+ use_slow_download : Optional [bool ] = False ) -> BinaryIO :
2173
2193
"""
2174
2194
Downloads and saves remote box file to the ``outfile``.
2175
2195
@@ -2214,6 +2234,11 @@ async def download(
2214
2234
progress_callback (``Callable[[int, int], None]``, optional):
2215
2235
A callback function accepting two parameters:
2216
2236
(downloaded_bytes, total).
2237
+
2238
+ use_slow_download (``bool``, optional):
2239
+ Will use default download function from the Telethon
2240
+ library instead of function from `fastelethon.py`.
2241
+ Use this if you have problems with download.
2217
2242
"""
2218
2243
self .__raise_initialized ()
2219
2244
@@ -2257,7 +2282,9 @@ async def download(
2257
2282
2258
2283
logger .debug (f'outfile is { outfile } ' )
2259
2284
2260
- use_slow_download_switch = 0
2285
+ # '0' is the fast download from the fastelethon.py, and '1'
2286
+ # is the default download from Telethon library.
2287
+ download_error_switch = 1 if use_slow_download else 0
2261
2288
2262
2289
stream_iv = self ._file_iv if not offset else b'' # We know IV if (not offset)
2263
2290
aws = None # Placeholder for AESwState class, we will set it later
@@ -2300,11 +2327,11 @@ async def download(
2300
2327
try :
2301
2328
# By default we will try to download file via the
2302
2329
# fast "download_file" coroutine from fastelethon
2303
- # module. If it fails, the "use_slow_download_switch "
2330
+ # module. If it fails, the "download_error_switch "
2304
2331
# will be incremented and this code will be switched
2305
2332
# to the default "iter_download" from TelegramClient;
2306
2333
# If it will fail too, -- we will raise an error.
2307
- if use_slow_download_switch == 0 :
2334
+ if download_error_switch == 0 :
2308
2335
iter_down = download_file (
2309
2336
client = self ._rb ._tc ,
2310
2337
location = self ._message .document ,
@@ -2357,14 +2384,14 @@ async def download(
2357
2384
break # Download is successfull so we can exit this loop
2358
2385
2359
2386
except Exception as e :
2360
- if use_slow_download_switch < 1 :
2361
- use_slow_download_switch + = 1
2387
+ if download_error_switch == 0 :
2388
+ download_error_switch = 1
2362
2389
logger .warning (
2363
- '''Fast download FAILED. Trying to use SLOW. '''
2364
- f'''Traceback: \n { format_exc ()} ''' )
2390
+ '''Fast download FAILED. Trying with SLOW! \n '''
2391
+ f'''{ format_exc ()} ''' )
2365
2392
continue
2366
2393
else :
2367
- logger .error ('Fast & Slow download methods failed' )
2394
+ logger .error ('Both fast and slow download methods failed' )
2368
2395
raise e
2369
2396
2370
2397
return outfile
0 commit comments