mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-04-16 15:12:00 +03:00
Reduce calls to utils.is_image
This commit is contained in:
parent
758556cd30
commit
3d72c10ea5
|
@ -247,7 +247,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
caption, msg_entities =\
|
caption, msg_entities =\
|
||||||
await self._parse_message_text(caption, parse_mode)
|
await self._parse_message_text(caption, parse_mode)
|
||||||
|
|
||||||
file_handle, media = await self._file_to_media(
|
file_handle, media, image = await self._file_to_media(
|
||||||
file, force_document=force_document,
|
file, force_document=force_document,
|
||||||
progress_callback=progress_callback,
|
progress_callback=progress_callback,
|
||||||
attributes=attributes, allow_cache=allow_cache, thumb=thumb,
|
attributes=attributes, allow_cache=allow_cache, thumb=thumb,
|
||||||
|
@ -265,7 +265,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
entities=msg_entities, reply_markup=markup, silent=silent
|
entities=msg_entities, reply_markup=markup, silent=silent
|
||||||
)
|
)
|
||||||
msg = self._get_response_message(request, await self(request), entity)
|
msg = self._get_response_message(request, await self(request), entity)
|
||||||
await self._cache_media(msg, file, file_handle, force_document=force_document)
|
await self._cache_media(msg, file, file_handle, image=image)
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
# :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(file)
|
fh, fm, _ = await self._file_to_media(file)
|
||||||
if isinstance(fm, types.InputMediaUploadedPhoto):
|
if isinstance(fm, types.InputMediaUploadedPhoto):
|
||||||
r = await self(functions.messages.UploadMediaRequest(
|
r = await self(functions.messages.UploadMediaRequest(
|
||||||
entity, media=fm
|
entity, media=fm
|
||||||
|
@ -487,7 +487,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
allow_cache=True, voice_note=False, video_note=False,
|
allow_cache=True, voice_note=False, video_note=False,
|
||||||
supports_streaming=False):
|
supports_streaming=False):
|
||||||
if not file:
|
if not file:
|
||||||
return None, None
|
return None, None, None
|
||||||
|
|
||||||
if isinstance(file, pathlib.Path):
|
if isinstance(file, pathlib.Path):
|
||||||
file = str(file.absolute())
|
file = str(file.absolute())
|
||||||
|
@ -510,9 +510,10 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
voice_note=voice_note,
|
voice_note=voice_note,
|
||||||
video_note=video_note,
|
video_note=video_note,
|
||||||
supports_streaming=supports_streaming
|
supports_streaming=supports_streaming
|
||||||
))
|
), as_image)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return None, None # Can't turn whatever was given into media
|
# Can't turn whatever was given into media
|
||||||
|
return None, None, as_image
|
||||||
|
|
||||||
media = None
|
media = None
|
||||||
file_handle = None
|
file_handle = None
|
||||||
|
@ -572,16 +573,15 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
attributes=attributes,
|
attributes=attributes,
|
||||||
**input_kw
|
**input_kw
|
||||||
)
|
)
|
||||||
return file_handle, media
|
return file_handle, media, as_image
|
||||||
|
|
||||||
async def _cache_media(self, msg, file, file_handle,
|
async def _cache_media(self, msg, file, file_handle, image):
|
||||||
force_document=False):
|
|
||||||
if file and msg and isinstance(file_handle,
|
if file and msg and isinstance(file_handle,
|
||||||
custom.InputSizedFile):
|
custom.InputSizedFile):
|
||||||
# There was a response message and we didn't use cached
|
# There was a response message and we didn't use cached
|
||||||
# version, so cache whatever we just sent to the database.
|
# version, so cache whatever we just sent to the database.
|
||||||
md5, size = file_handle.md5, file_handle.size
|
md5, size = file_handle.md5, file_handle.size
|
||||||
if utils.is_image(file) and not force_document:
|
if image:
|
||||||
to_cache = utils.get_input_photo(msg.media.photo)
|
to_cache = utils.get_input_photo(msg.media.photo)
|
||||||
else:
|
else:
|
||||||
to_cache = utils.get_input_document(msg.media.document)
|
to_cache = utils.get_input_document(msg.media.document)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user