mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-29 12:53:44 +03:00
parent
68438f4621
commit
ccfd7a1015
|
@ -637,6 +637,14 @@ class UploadMethods:
|
||||||
if as_image is None:
|
if as_image is None:
|
||||||
as_image = utils.is_image(file) and not force_document
|
as_image = utils.is_image(file) and not force_document
|
||||||
|
|
||||||
|
if as_image or not thumb:
|
||||||
|
# Images don't have thumb so don't bother uploading it
|
||||||
|
thumb = None
|
||||||
|
else:
|
||||||
|
if isinstance(thumb, pathlib.Path):
|
||||||
|
thumb = str(thumb.absolute())
|
||||||
|
thumb = await self.upload_file(thumb)
|
||||||
|
|
||||||
# `aiofiles` do not base `io.IOBase` but do have `read`, so we
|
# `aiofiles` do not base `io.IOBase` but do have `read`, so we
|
||||||
# just check for the read attribute to see if it's file-like.
|
# just check for the read attribute to see if it's file-like.
|
||||||
if not isinstance(file, (str, bytes)) and not hasattr(file, 'read'):
|
if not isinstance(file, (str, bytes)) and not hasattr(file, 'read'):
|
||||||
|
@ -654,7 +662,8 @@ class UploadMethods:
|
||||||
force_document=force_document,
|
force_document=force_document,
|
||||||
voice_note=voice_note,
|
voice_note=voice_note,
|
||||||
video_note=video_note,
|
video_note=video_note,
|
||||||
supports_streaming=supports_streaming
|
supports_streaming=supports_streaming,
|
||||||
|
thumb=thumb,
|
||||||
), as_image)
|
), as_image)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Can't turn whatever was given into media
|
# Can't turn whatever was given into media
|
||||||
|
@ -699,17 +708,11 @@ class UploadMethods:
|
||||||
supports_streaming=supports_streaming
|
supports_streaming=supports_streaming
|
||||||
)
|
)
|
||||||
|
|
||||||
input_kw = {}
|
|
||||||
if thumb:
|
|
||||||
if isinstance(thumb, pathlib.Path):
|
|
||||||
thumb = str(thumb.absolute())
|
|
||||||
input_kw['thumb'] = await self.upload_file(thumb)
|
|
||||||
|
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
file=file_handle,
|
file=file_handle,
|
||||||
mime_type=mime_type,
|
mime_type=mime_type,
|
||||||
attributes=attributes,
|
attributes=attributes,
|
||||||
**input_kw
|
thumb=thumb
|
||||||
)
|
)
|
||||||
return file_handle, media, as_image
|
return file_handle, media, as_image
|
||||||
|
|
||||||
|
|
|
@ -427,7 +427,8 @@ def get_input_geo(geo):
|
||||||
def get_input_media(
|
def get_input_media(
|
||||||
media, *,
|
media, *,
|
||||||
is_photo=False, attributes=None, force_document=False,
|
is_photo=False, attributes=None, force_document=False,
|
||||||
voice_note=False, video_note=False, supports_streaming=False
|
voice_note=False, video_note=False, supports_streaming=False,
|
||||||
|
thumb=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Similar to :meth:`get_input_peer`, but for media.
|
Similar to :meth:`get_input_peer`, but for media.
|
||||||
|
@ -481,7 +482,7 @@ def get_input_media(
|
||||||
supports_streaming=supports_streaming
|
supports_streaming=supports_streaming
|
||||||
)
|
)
|
||||||
return types.InputMediaUploadedDocument(
|
return types.InputMediaUploadedDocument(
|
||||||
file=media, mime_type=mime, attributes=attrs)
|
file=media, mime_type=mime, attributes=attrs, thumb=thumb)
|
||||||
|
|
||||||
if isinstance(media, types.MessageMediaGame):
|
if isinstance(media, types.MessageMediaGame):
|
||||||
return types.InputMediaGame(id=types.InputGameID(
|
return types.InputMediaGame(id=types.InputGameID(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user