mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-16 19:41:07 +03:00
Add utils.get_input_location
This commit is contained in:
parent
f16289cf93
commit
dc273ab6bc
|
@ -2235,6 +2235,7 @@ class TelegramClient(TelegramBareClient):
|
|||
# The used client will change if FileMigrateError occurs
|
||||
client = self
|
||||
cdn_decrypter = None
|
||||
input_location = utils.get_input_location(input_location)
|
||||
|
||||
__log__.info('Downloading file in chunks of %d bytes', part_size)
|
||||
try:
|
||||
|
|
|
@ -25,7 +25,8 @@ from .tl.types import (
|
|||
InputPhotoEmpty, FileLocation, ChatPhotoEmpty, UserProfilePhotoEmpty,
|
||||
FileLocationUnavailable, InputMediaUploadedDocument, ChannelFull,
|
||||
InputMediaUploadedPhoto, DocumentAttributeFilename, photos,
|
||||
TopPeer, InputNotifyPeer, InputMessageID
|
||||
TopPeer, InputNotifyPeer, InputMessageID, InputFileLocation,
|
||||
InputDocumentFileLocation, PhotoSizeEmpty
|
||||
)
|
||||
from .tl.types.contacts import ResolvedPeer
|
||||
|
||||
|
@ -352,6 +353,39 @@ def get_input_message(message):
|
|||
_raise_cast_fail(message, 'InputMedia')
|
||||
|
||||
|
||||
def get_input_location(location):
|
||||
"""Similar to :meth:`get_input_peer`, but for input messages."""
|
||||
try:
|
||||
if location.SUBCLASS_OF_ID == 0x1523d462:
|
||||
return location # crc32(b'InputFileLocation'):
|
||||
except AttributeError:
|
||||
_raise_cast_fail(location, 'InputFileLocation')
|
||||
|
||||
if isinstance(location, Message):
|
||||
location = location.media
|
||||
|
||||
if isinstance(location, MessageMediaDocument):
|
||||
location = location.document
|
||||
elif isinstance(location, MessageMediaPhoto):
|
||||
location = location.photo
|
||||
|
||||
if isinstance(location, Document):
|
||||
return InputDocumentFileLocation(
|
||||
location.id, location.access_hash, location.version)
|
||||
elif isinstance(location, Photo):
|
||||
try:
|
||||
location = next(x for x in reversed(location.sizes)
|
||||
if not isinstance(x, PhotoSizeEmpty)).location
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
if isinstance(location, (FileLocation, FileLocationUnavailable)):
|
||||
return InputFileLocation(
|
||||
location.volume_id, location.local_id, location.secret)
|
||||
|
||||
_raise_cast_fail(location, 'InputFileLocation')
|
||||
|
||||
|
||||
def is_image(file):
|
||||
"""
|
||||
Returns ``True`` if the file extension looks like an image file to Telegram.
|
||||
|
|
Loading…
Reference in New Issue
Block a user