From 1fdb3386ff0e8b03ae2e954857373aa5da593464 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 Apr 2018 20:41:23 +0200 Subject: [PATCH] Enhance send_video by accepting file_ids and URLs --- pyrogram/client/client.py | 75 +++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index b23e3cda..1f9365ee 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1620,7 +1620,9 @@ class Client: video (``str``): Video to send. - Pass a file path as string to send a video that exists on your local machine. + Pass a file_id as string to send a video that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get a video from the Internet, or + pass a file path as string to upload a new video that exists on your local machine. caption (``str``, optional): Video caption, 0-200 characters. @@ -1666,34 +1668,64 @@ class Client: The size of the file. Returns: - On success, the sent Message is returned. + On success, the sent :obj:`Message ` is returned. Raises: :class:`Error ` """ + file = None style = self.html if parse_mode.lower() == "html" else self.markdown - file = self.save_file(video, progress=progress) - file_thumb = None if thumb is None else self.save_file(thumb) + + if os.path.exists(video): + thumb = None if thumb is None else self.save_file(thumb) + file = self.save_file(video, progress=progress) + media = types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map[".mp4"], + file=file, + thumb=thumb, + attributes=[ + types.DocumentAttributeVideo( + supports_streaming=supports_streaming or None, + duration=duration, + w=width, + h=height + ), + types.DocumentAttributeFilename(os.path.basename(video)) + ] + ) + elif video.startswith("http"): + media = types.InputMediaDocumentExternal( + url=video + ) + else: + try: + decoded = utils.decode(video) + fmt = " 24 else "