Fix
This commit is contained in:
parent
9fab87b045
commit
a685dd427a
@ -216,17 +216,14 @@ async def upload_file(client: TelegramClient, source: typing.BinaryIO, expectedS
|
||||
|
||||
async def download_part(client: TelegramClient, dest: typing.BinaryIO, dInfo: DownloadInfo):
|
||||
dcId, inputFileLocation = get_input_location(dInfo.message)
|
||||
chunkSize = pow(2, 20)
|
||||
chunkSize = pow(2, 19)
|
||||
realSize = int(dInfo.part_info['real_size'])
|
||||
totalBytesDownloaded = 0
|
||||
lastRealTimeMeasurement = time.time()
|
||||
|
||||
while totalBytesDownloaded < realSize:
|
||||
offset = totalBytesDownloaded
|
||||
limit = chunkSize if offset + chunkSize < realSize else realSize - offset
|
||||
if limit % pow(2, 12) != 0:
|
||||
extraBytes = pow(2, 12) - limit % pow(2, 12)
|
||||
limit += extraBytes
|
||||
limit = chunkSize
|
||||
|
||||
try:
|
||||
downloadResult: File = await client(GetFileRequest(
|
||||
@ -242,6 +239,8 @@ async def download_part(client: TelegramClient, dest: typing.BinaryIO, dInfo: Do
|
||||
newMessage = await client.get_messages(dInfo.dialog, ids=dInfo.message.id)
|
||||
dcId, inputFileLocation = get_input_location(newMessage)
|
||||
continue
|
||||
else:
|
||||
raise e
|
||||
buffer = downloadResult.bytes
|
||||
bufLen = len(buffer)
|
||||
totalBytesDownloaded += bufLen
|
||||
@ -377,11 +376,13 @@ async def download(config: Config, filename):
|
||||
destination = sys.stdout.buffer
|
||||
await check_logged_in(config)
|
||||
|
||||
try:
|
||||
filename = filename.strip()
|
||||
nameHash = hashlib.sha256(filename.encode('utf-8')).hexdigest()
|
||||
fileMessages = await config.client.get_messages(config.dialog, search=f'#telecup_file_{nameHash}')
|
||||
if len(fileMessages) == 0:
|
||||
click.echo(f'`{filename}` not found', err=True)
|
||||
return
|
||||
msg = fileMessages[0]
|
||||
fileInfo = parse_message(msg.message)
|
||||
if fileInfo and fileInfo['name'] == filename:
|
||||
@ -389,4 +390,9 @@ async def download(config: Config, filename):
|
||||
click.echo('OK', err=True)
|
||||
else:
|
||||
click.echo('Message FileInfo corrupt', err=True)
|
||||
finally:
|
||||
await config.client.disconnect()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user