added supports video-albums in send_file

This commit is contained in:
Alexhol 2020-01-17 01:26:38 +03:00
parent d09f6a50b0
commit 5e6d33e104

View File

@ -271,6 +271,7 @@ class UploadMethods:
if utils.is_list_like(file):
image_captions = []
document_captions = []
video_captions = []
if utils.is_list_like(caption):
captions = caption
else:
@ -278,6 +279,7 @@ class UploadMethods:
# TODO Fix progress_callback
images = []
videos = []
if force_document:
documents = file
else:
@ -286,6 +288,9 @@ class UploadMethods:
if utils.is_image(doc):
images.append(doc)
image_captions.append(cap)
elif utils.is_video(doc):
videos.append(doc)
video_captions.append(cap)
else:
documents.append(doc)
document_captions.append(cap)
@ -300,6 +305,16 @@ class UploadMethods:
images = images[10:]
image_captions = image_captions[10:]
while videos:
result += await self._send_album(
entity, videos[:10], caption=video_captions[:10],
progress_callback=progress_callback, reply_to=reply_to,
parse_mode=parse_mode, silent=silent, schedule=schedule,
supports_streaming=supports_streaming
)
videos = videos[10:]
video_captions = video_captions[10:]
for doc, cap in zip(documents, captions):
result.append(await self.send_file(
entity, doc, allow_cache=allow_cache,
@ -349,7 +364,8 @@ class UploadMethods:
async def _send_album(self: 'TelegramClient', entity, files, caption='',
progress_callback=None, reply_to=None,
parse_mode=(), silent=None, schedule=None):
parse_mode=(), silent=None, schedule=None,
supports_streaming=None):
"""Specialized version of .send_file for albums"""
# We don't care if the user wants to avoid cache, we will use it
# anyway. Why? The cached version will be exactly the same thing
@ -377,7 +393,8 @@ class UploadMethods:
# :tl:`InputMediaUploadedPhoto`. However using that will
# make it `raise MediaInvalidError`, so we need to upload
# it as media and then convert that to :tl:`InputMediaPhoto`.
fh, fm, _ = await self._file_to_media(file)
fh, fm, _ = await self._file_to_media(
file, supports_streaming=supports_streaming)
if isinstance(fm, types.InputMediaUploadedPhoto):
r = await self(functions.messages.UploadMediaRequest(
entity, media=fm
@ -386,6 +403,12 @@ class UploadMethods:
fh.md5, fh.size, utils.get_input_photo(r.photo))
fm = utils.get_input_media(r.photo)
elif isinstance(fm, types.InputMediaUploadedDocument):
r = await self(functions.messages.UploadMediaRequest(
entity, media=fm
))
fm = utils.get_input_media(
r.document, supports_streaming=supports_streaming)
if captions:
caption, msg_entities = captions.pop()