Refetch the message in case of reference expiration
This commit is contained in:
parent
962cfdbef7
commit
0d299fe84f
@ -13,6 +13,7 @@ from concurrent.futures.thread import ThreadPoolExecutor
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
from telethon.errors import BadRequestError
|
||||||
from telethon.helpers import generate_random_long
|
from telethon.helpers import generate_random_long
|
||||||
from telethon import TelegramClient, connection
|
from telethon import TelegramClient, connection
|
||||||
from telethon.tl.custom.message import Message
|
from telethon.tl.custom.message import Message
|
||||||
@ -27,7 +28,7 @@ MESSAGE_HEADER = f'TeleCup File Uploader https://lnurl.ru/telecup'
|
|||||||
MESSAGE_BLOCK_END = '_cup_end_'
|
MESSAGE_BLOCK_END = '_cup_end_'
|
||||||
|
|
||||||
UploadInfo = namedtuple('UploadInfo', ['file_list', 'real_size'])
|
UploadInfo = namedtuple('UploadInfo', ['file_list', 'real_size'])
|
||||||
DownloadInfo = namedtuple('DownloadInfo', ['message', 'part_info'])
|
DownloadInfo = typing.NamedTuple('DownloadInfo', [('message', Message), ('part_info', dict)])
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -227,6 +228,7 @@ async def download_part(client: TelegramClient, dest: typing.BinaryIO, dInfo: Do
|
|||||||
extraBytes = pow(2, 12) - limit % pow(2, 12)
|
extraBytes = pow(2, 12) - limit % pow(2, 12)
|
||||||
limit += extraBytes
|
limit += extraBytes
|
||||||
|
|
||||||
|
try:
|
||||||
downloadResult: File = await client(GetFileRequest(
|
downloadResult: File = await client(GetFileRequest(
|
||||||
inputFileLocation,
|
inputFileLocation,
|
||||||
offset,
|
offset,
|
||||||
@ -234,6 +236,12 @@ async def download_part(client: TelegramClient, dest: typing.BinaryIO, dInfo: Do
|
|||||||
precise=False,
|
precise=False,
|
||||||
cdn_supported=False
|
cdn_supported=False
|
||||||
))
|
))
|
||||||
|
except BadRequestError as e:
|
||||||
|
if 'expire' in str(e.message).lower():
|
||||||
|
click.echo('Reloading message...', err=True)
|
||||||
|
newMessage = await client.get_messages(ids=dInfo.message.id)
|
||||||
|
dcId, inputFileLocation = get_input_location(newMessage)
|
||||||
|
continue
|
||||||
buffer = downloadResult.bytes
|
buffer = downloadResult.bytes
|
||||||
bufLen = len(buffer)
|
bufLen = len(buffer)
|
||||||
totalBytesDownloaded += bufLen
|
totalBytesDownloaded += bufLen
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user