mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Send video files as video by default instead as document (#601)
This commit is contained in:
parent
0633e204c2
commit
9abeefac7f
|
@ -70,7 +70,7 @@ from .tl.types import (
|
|||
ChatInvite, ChatInviteAlready, PeerChannel, Photo, InputPeerSelf,
|
||||
InputSingleMedia, InputMediaPhoto, InputPhoto, InputFile, InputFileBig,
|
||||
InputDocument, InputMediaDocument, Document, MessageEntityTextUrl,
|
||||
InputMessageEntityMentionName
|
||||
InputMessageEntityMentionName, DocumentAttributeVideo
|
||||
)
|
||||
from .tl.types.messages import DialogsSlice
|
||||
from .extensions import markdown, html
|
||||
|
@ -922,8 +922,8 @@ class TelegramClient(TelegramBareClient):
|
|||
|
||||
force_document (:obj:`bool`, optional):
|
||||
If left to ``False`` and the file is a path that ends with
|
||||
``.png``, ``.jpg`` and such, the file will be sent as a photo.
|
||||
Otherwise always as a document.
|
||||
the extension of an image file or a video file, it will be
|
||||
sent as such. Otherwise always as a document.
|
||||
|
||||
progress_callback (:obj:`callable`, optional):
|
||||
A callback function accepting two parameters:
|
||||
|
@ -1015,6 +1015,9 @@ class TelegramClient(TelegramBareClient):
|
|||
# TODO If the input file is an audio, find out:
|
||||
# Performer and song title and add DocumentAttributeAudio
|
||||
}
|
||||
if not force_document and utils.is_video(file):
|
||||
attr_dict[DocumentAttributeVideo] = \
|
||||
DocumentAttributeVideo(0, 0, 0)
|
||||
else:
|
||||
attr_dict = {
|
||||
DocumentAttributeFilename:
|
||||
|
|
|
@ -3,10 +3,10 @@ Utilities for working with the Telegram API itself (such as handy methods
|
|||
to convert between an entity like an User, Chat, etc. into its Input version)
|
||||
"""
|
||||
import math
|
||||
import mimetypes
|
||||
import re
|
||||
from mimetypes import add_type, guess_extension
|
||||
|
||||
from .tl.types.contacts import ResolvedPeer
|
||||
from .tl.types import (
|
||||
Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull,
|
||||
ChatPhoto, InputPeerChannel, InputPeerChat, InputPeerUser, InputPeerEmpty,
|
||||
|
@ -24,6 +24,7 @@ from .tl.types import (
|
|||
InputMediaUploadedPhoto, DocumentAttributeFilename, photos,
|
||||
TopPeer, InputNotifyPeer
|
||||
)
|
||||
from .tl.types.contacts import ResolvedPeer
|
||||
|
||||
USERNAME_RE = re.compile(
|
||||
r'@|(?:https?://)?(?:telegram\.(?:me|dog)|t\.me)/(joinchat/)?'
|
||||
|
@ -322,8 +323,12 @@ def get_input_media(media, user_caption=None, is_photo=False):
|
|||
|
||||
def is_image(file):
|
||||
"""Returns True if the file extension looks like an image file"""
|
||||
return (isinstance(file, str) and
|
||||
bool(re.search(r'\.(png|jpe?g|gif)$', file, re.IGNORECASE)))
|
||||
return (mimetypes.guess_type(file)[0] or '').startswith('image/')
|
||||
|
||||
|
||||
def is_video(file):
|
||||
"""Returns True if the file extension looks like a video file"""
|
||||
return (mimetypes.guess_type(file)[0] or '').startswith('video/')
|
||||
|
||||
|
||||
def parse_phone(phone):
|
||||
|
|
Loading…
Reference in New Issue
Block a user