more stuff

This commit is contained in:
blank X 2021-04-09 21:34:48 +07:00
parent cf83bbab73
commit c222f91ef9
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 7 additions and 6 deletions

View File

@ -29,7 +29,7 @@ class CappedBufferedReader(io.BufferedReader):
elif whence == os.SEEK_SET:
current_pos = self.tell()
if current_pos > offset:
self.capped_size += current_pos
self.capped_size += current_pos - offset
return super().seek(offset, whence)
@property

View File

@ -224,13 +224,13 @@ async def _upload_worker():
tempdir = tempdir_obj.name
base_filename = video_json['id'] + '.mkv'
video_filename = os.path.join(tempdir, base_filename)
total_size = os.path.getsize(video_filename)
is_big = total_size > size_limit
files_sent = size_sent = 0
messages = []
file = bopen(video_filename, None)
file.seek(0, os.SEEK_END)
total_size = file.tell()
is_big = total_size > size_limit
while total_size > 0:
file.capped_size = None
file.seek(size_sent)
file.capped_size = size_limit
if is_big:
@ -238,12 +238,13 @@ async def _upload_worker():
else:
file.name = base_filename
messages.append((await client.send_message(config['config']['storage_chat_id'], f'Uploading {file.name}...', parse_mode=None)).id)
message = await client.send_file(config['config']['storage_chat_id'], file, caption=file.name, parse_mode=None)
message = await client.send_file(config['config']['storage_chat_id'], file, caption=file.name, parse_mode=None, file_size=size_limit if total_size > size_limit else total_size)
total_size -= message.document.size
if total_size > 0:
size_sent += message.document.size
files_sent += 1
file = bopen(video_filename, None)
file.capped_size = None
file.close()
if messages:
await client.delete_messages(config['config']['storage_chat_id'], messages)
finally: