Browse Source

Workaround for LimitInvalidError

master
blank X 1 year ago
parent
commit
d695dd9e9b
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
  1. 9
      streamtg.py

9
streamtg.py

@ -6,6 +6,7 @@ import yaml
from aiohttp import web
from telethon import TelegramClient
from telethon.utils import _get_file_info
from telethon.client.downloads import _GenericDownloadIter
with open('config.yaml') as file:
config = yaml.safe_load(file)
@ -61,7 +62,13 @@ async def handler(request):
if tmp_offset > size:
tmp_offset -= size
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]
tmp_length -= len(chunk)
if tmp_length < 1:

Loading…
Cancel
Save