mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
parent
a942b021bc
commit
33c5ee9be4
|
@ -352,6 +352,11 @@ class UploadMethods:
|
||||||
# First check if the user passed an iterable, in which case
|
# First check if the user passed an iterable, in which case
|
||||||
# we may want to send grouped.
|
# we may want to send grouped.
|
||||||
if utils.is_list_like(file):
|
if utils.is_list_like(file):
|
||||||
|
sent_count = 0
|
||||||
|
used_callback = None if not progress_callback else (
|
||||||
|
lambda s, t: progress_callback(sent_count + s, len(file))
|
||||||
|
)
|
||||||
|
|
||||||
if utils.is_list_like(caption):
|
if utils.is_list_like(caption):
|
||||||
captions = caption
|
captions = caption
|
||||||
else:
|
else:
|
||||||
|
@ -361,19 +366,20 @@ class UploadMethods:
|
||||||
while file:
|
while file:
|
||||||
result += await self._send_album(
|
result += await self._send_album(
|
||||||
entity, file[:10], caption=captions[:10],
|
entity, file[:10], caption=captions[:10],
|
||||||
progress_callback=progress_callback, reply_to=reply_to,
|
progress_callback=used_callback, reply_to=reply_to,
|
||||||
parse_mode=parse_mode, silent=silent, schedule=schedule,
|
parse_mode=parse_mode, silent=silent, schedule=schedule,
|
||||||
supports_streaming=supports_streaming, clear_draft=clear_draft,
|
supports_streaming=supports_streaming, clear_draft=clear_draft,
|
||||||
force_document=force_document, background=background,
|
force_document=force_document, background=background,
|
||||||
)
|
)
|
||||||
file = file[10:]
|
file = file[10:]
|
||||||
captions = captions[10:]
|
captions = captions[10:]
|
||||||
|
sent_count += 10
|
||||||
|
|
||||||
for doc, cap in zip(file, captions):
|
for doc, cap in zip(file, captions):
|
||||||
result.append(await self.send_file(
|
result.append(await self.send_file(
|
||||||
entity, doc, allow_cache=allow_cache,
|
entity, doc, allow_cache=allow_cache,
|
||||||
caption=cap, force_document=force_document,
|
caption=cap, force_document=force_document,
|
||||||
progress_callback=progress_callback, reply_to=reply_to,
|
progress_callback=used_callback, reply_to=reply_to,
|
||||||
attributes=attributes, thumb=thumb, voice_note=voice_note,
|
attributes=attributes, thumb=thumb, voice_note=voice_note,
|
||||||
video_note=video_note, buttons=buttons, silent=silent,
|
video_note=video_note, buttons=buttons, silent=silent,
|
||||||
supports_streaming=supports_streaming, schedule=schedule,
|
supports_streaming=supports_streaming, schedule=schedule,
|
||||||
|
@ -436,16 +442,22 @@ class UploadMethods:
|
||||||
|
|
||||||
reply_to = utils.get_message_id(reply_to)
|
reply_to = utils.get_message_id(reply_to)
|
||||||
|
|
||||||
|
used_callback = None if not progress_callback else (
|
||||||
|
# use an integer when sent matches total, to easily determine a file has been fully sent
|
||||||
|
lambda s, t: progress_callback(sent_count + 1 if s == t else sent_count + s / t, len(files))
|
||||||
|
)
|
||||||
|
|
||||||
# Need to upload the media first, but only if they're not cached yet
|
# Need to upload the media first, but only if they're not cached yet
|
||||||
media = []
|
media = []
|
||||||
for file in files:
|
for sent_count, file in enumerate(files):
|
||||||
# Albums want :tl:`InputMedia` which, in theory, includes
|
# Albums want :tl:`InputMedia` which, in theory, includes
|
||||||
# :tl:`InputMediaUploadedPhoto`. However using that will
|
# :tl:`InputMediaUploadedPhoto`. However using that will
|
||||||
# make it `raise MediaInvalidError`, so we need to upload
|
# make it `raise MediaInvalidError`, so we need to upload
|
||||||
# it as media and then convert that to :tl:`InputMediaPhoto`.
|
# it as media and then convert that to :tl:`InputMediaPhoto`.
|
||||||
fh, fm, _ = await self._file_to_media(
|
fh, fm, _ = await self._file_to_media(
|
||||||
file, supports_streaming=supports_streaming,
|
file, supports_streaming=supports_streaming,
|
||||||
force_document=force_document, ttl=ttl)
|
force_document=force_document, ttl=ttl,
|
||||||
|
progress_callback=used_callback)
|
||||||
if isinstance(fm, (types.InputMediaUploadedPhoto, types.InputMediaPhotoExternal)):
|
if isinstance(fm, (types.InputMediaUploadedPhoto, types.InputMediaPhotoExternal)):
|
||||||
r = await self(functions.messages.UploadMediaRequest(
|
r = await self(functions.messages.UploadMediaRequest(
|
||||||
entity, media=fm
|
entity, media=fm
|
||||||
|
@ -546,6 +558,13 @@ class UploadMethods:
|
||||||
A callback function accepting two parameters:
|
A callback function accepting two parameters:
|
||||||
``(sent bytes, total)``.
|
``(sent bytes, total)``.
|
||||||
|
|
||||||
|
When sending an album, the callback will receive a number
|
||||||
|
between 0 and the amount of files as the "sent" parameter,
|
||||||
|
and the amount of files as the "total". Note that the first
|
||||||
|
parameter will be a floating point number to indicate progress
|
||||||
|
within a file (e.g. ``2.5`` means it has sent 50% of the third
|
||||||
|
file, because it's between 2 and 3).
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
:tl:`InputFileBig` if the file size is larger than 10MB,
|
:tl:`InputFileBig` if the file size is larger than 10MB,
|
||||||
`InputSizedFile <telethon.tl.custom.inputsizedfile.InputSizedFile>`
|
`InputSizedFile <telethon.tl.custom.inputsizedfile.InputSizedFile>`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user