Workaround for LimitInvalidError

This commit is contained in:
blank X 2021-03-04 17:47:59 +07:00
parent 599eb29c4c
commit d695dd9e9b
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 8 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import yaml
from aiohttp import web from aiohttp import web
from telethon import TelegramClient from telethon import TelegramClient
from telethon.utils import _get_file_info from telethon.utils import _get_file_info
from telethon.client.downloads import _GenericDownloadIter
with open('config.yaml') as file: with open('config.yaml') as file:
config = yaml.safe_load(file) config = yaml.safe_load(file)
@ -61,7 +62,13 @@ async def handler(request):
if tmp_offset > size: if tmp_offset > size:
tmp_offset -= size tmp_offset -= size
continue continue
async for chunk in client._iter_download(i, offset=tmp_offset, msg_data=(chat_id, i.id)): stream = client._iter_download(i, offset=tmp_offset, request_size=131072, msg_data=(chat_id, i.id))
if isinstance(stream, _GenericDownloadIter):
__load_next_chunk = stream._load_next_chunk
def _load_next_chunk(mask=131071):
return __load_next_chunk(mask=mask)
stream._load_next_chunk = _load_next_chunk
async for chunk in stream:
yield chunk[:tmp_length] yield chunk[:tmp_length]
tmp_length -= len(chunk) tmp_length -= len(chunk)
if tmp_length < 1: if tmp_length < 1: