Remove fake_start
This commit is contained in:
parent
02ad4d6d6b
commit
d0d7009886
|
@ -2,10 +2,9 @@ import io
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class CappedBufferedReader(io.BufferedReader):
|
class CappedBufferedReader(io.BufferedReader):
|
||||||
def __init__(self, raw, buffer_size=io.DEFAULT_BUFFER_SIZE, capped_size=None, fake_start=None):
|
def __init__(self, raw, buffer_size=io.DEFAULT_BUFFER_SIZE, capped_size=None):
|
||||||
super().__init__(raw, buffer_size)
|
super().__init__(raw, buffer_size)
|
||||||
self.capped_size = capped_size
|
self.capped_size = capped_size
|
||||||
self.fake_start = fake_start
|
|
||||||
|
|
||||||
def read(self, size=None):
|
def read(self, size=None):
|
||||||
if self.capped_size is not None:
|
if self.capped_size is not None:
|
||||||
|
@ -25,8 +24,6 @@ class CappedBufferedReader(io.BufferedReader):
|
||||||
else:
|
else:
|
||||||
offset = self.capped_size
|
offset = self.capped_size
|
||||||
whence = os.SEEK_SET
|
whence = os.SEEK_SET
|
||||||
elif whence == os.SEEK_SET and self.fake_start is not None:
|
|
||||||
offset += self.fake_start
|
|
||||||
return super().seek(offset, whence)
|
return super().seek(offset, whence)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -40,5 +37,5 @@ class CappedBufferedReader(io.BufferedReader):
|
||||||
def name(self, new_name):
|
def name(self, new_name):
|
||||||
self._name = new_name
|
self._name = new_name
|
||||||
|
|
||||||
def bopen(file, capped_size, fake_start):
|
def bopen(file, capped_size):
|
||||||
return CappedBufferedReader(open(file, 'rb', buffering=0), capped_size=capped_size, fake_start=fake_start)
|
return CappedBufferedReader(open(file, 'rb', buffering=0), capped_size=capped_size)
|
||||||
|
|
|
@ -228,9 +228,9 @@ async def _upload_worker():
|
||||||
is_big = total_size > size_limit
|
is_big = total_size > size_limit
|
||||||
files_sent = size_sent = 0
|
files_sent = size_sent = 0
|
||||||
messages = []
|
messages = []
|
||||||
file = bopen(video_filename, size_limit, None)
|
file = bopen(video_filename, size_limit)
|
||||||
while total_size > 0:
|
while total_size > 0:
|
||||||
file.fake_start = size_sent
|
file.seek(size_sent)
|
||||||
if is_big:
|
if is_big:
|
||||||
file.name = f'{base_filename}.part{str(files_sent).rjust(2, "0")}'
|
file.name = f'{base_filename}.part{str(files_sent).rjust(2, "0")}'
|
||||||
messages.append((await client.send_message(config['config']['storage_chat_id'], f'Uploading {file.name}...', parse_mode=None)).id)
|
messages.append((await client.send_message(config['config']['storage_chat_id'], f'Uploading {file.name}...', parse_mode=None)).id)
|
||||||
|
@ -239,7 +239,7 @@ async def _upload_worker():
|
||||||
if total_size > 0:
|
if total_size > 0:
|
||||||
size_sent += message.document.size
|
size_sent += message.document.size
|
||||||
files_sent += 1
|
files_sent += 1
|
||||||
file = bopen(video_filename, size_limit, None)
|
file = bopen(video_filename, size_limit)
|
||||||
if messages:
|
if messages:
|
||||||
await client.delete_messages(config['config']['storage_chat_id'], messages)
|
await client.delete_messages(config['config']['storage_chat_id'], messages)
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in New Issue