mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-24 08:14:14 +03:00
Fix .download_media() not accepting Document
This commit is contained in:
parent
81c95b5a60
commit
58d90e7e34
|
@ -67,7 +67,7 @@ from .tl.types import (
|
||||||
PeerUser, InputPeerUser, InputPeerChat, InputPeerChannel, MessageEmpty,
|
PeerUser, InputPeerUser, InputPeerChat, InputPeerChannel, MessageEmpty,
|
||||||
ChatInvite, ChatInviteAlready, PeerChannel, Photo, InputPeerSelf,
|
ChatInvite, ChatInviteAlready, PeerChannel, Photo, InputPeerSelf,
|
||||||
InputSingleMedia, InputMediaPhoto, InputPhoto, InputFile, InputFileBig,
|
InputSingleMedia, InputMediaPhoto, InputPhoto, InputFile, InputFileBig,
|
||||||
InputDocument, InputMediaDocument
|
InputDocument, InputMediaDocument, Document
|
||||||
)
|
)
|
||||||
from .tl.types.messages import DialogsSlice
|
from .tl.types.messages import DialogsSlice
|
||||||
from .extensions import markdown, html
|
from .extensions import markdown, html
|
||||||
|
@ -1308,7 +1308,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
return self._download_photo(
|
return self._download_photo(
|
||||||
media, file, date, progress_callback
|
media, file, date, progress_callback
|
||||||
)
|
)
|
||||||
elif isinstance(media, MessageMediaDocument):
|
elif isinstance(media, (MessageMediaDocument, Document)):
|
||||||
return self._download_document(
|
return self._download_document(
|
||||||
media, file, date, progress_callback
|
media, file, date, progress_callback
|
||||||
)
|
)
|
||||||
|
@ -1319,7 +1319,6 @@ class TelegramClient(TelegramBareClient):
|
||||||
|
|
||||||
def _download_photo(self, photo, file, date, progress_callback):
|
def _download_photo(self, photo, file, date, progress_callback):
|
||||||
"""Specialized version of .download_media() for photos"""
|
"""Specialized version of .download_media() for photos"""
|
||||||
|
|
||||||
# Determine the photo and its largest size
|
# Determine the photo and its largest size
|
||||||
if isinstance(photo, MessageMediaPhoto):
|
if isinstance(photo, MessageMediaPhoto):
|
||||||
photo = photo.photo
|
photo = photo.photo
|
||||||
|
@ -1345,9 +1344,13 @@ class TelegramClient(TelegramBareClient):
|
||||||
)
|
)
|
||||||
return file
|
return file
|
||||||
|
|
||||||
def _download_document(self, mm_doc, file, date, progress_callback):
|
def _download_document(self, document, file, date, progress_callback):
|
||||||
"""Specialized version of .download_media() for documents"""
|
"""Specialized version of .download_media() for documents"""
|
||||||
document = mm_doc.document
|
if isinstance(document, MessageMediaDocument):
|
||||||
|
document = document.document
|
||||||
|
if not isinstance(document, Document):
|
||||||
|
return
|
||||||
|
|
||||||
file_size = document.size
|
file_size = document.size
|
||||||
|
|
||||||
possible_names = []
|
possible_names = []
|
||||||
|
@ -1361,7 +1364,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
))
|
))
|
||||||
|
|
||||||
file = self._get_proper_filename(
|
file = self._get_proper_filename(
|
||||||
file, 'document', utils.get_extension(mm_doc),
|
file, 'document', utils.get_extension(document),
|
||||||
date=date, possible_names=possible_names
|
date=date, possible_names=possible_names
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,13 @@ def get_extension(media):
|
||||||
|
|
||||||
# Documents will come with a mime type
|
# Documents will come with a mime type
|
||||||
if isinstance(media, MessageMediaDocument):
|
if isinstance(media, MessageMediaDocument):
|
||||||
if isinstance(media.document, Document):
|
media = media.document
|
||||||
if media.document.mime_type == 'application/octet-stream':
|
if isinstance(media, Document):
|
||||||
|
if media.mime_type == 'application/octet-stream':
|
||||||
# Octet stream are just bytes, which have no default extension
|
# Octet stream are just bytes, which have no default extension
|
||||||
return ''
|
return ''
|
||||||
else:
|
else:
|
||||||
extension = guess_extension(media.document.mime_type)
|
return guess_extension(media.mime_type) or ''
|
||||||
return extension if extension else ''
|
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user