From 11ed26b3186a1576536cc0f3bee48ce3b10c0805 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 15 Dec 2018 21:40:44 +0100 Subject: [PATCH] Refactor Animation, Video and VideoNote --- .../types/messages_and_media/animation.py | 48 ++++++++++++++----- .../client/types/messages_and_media/video.py | 45 ++++++++++++----- .../types/messages_and_media/video_note.py | 41 ++++++++++++---- 3 files changed, 100 insertions(+), 34 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/animation.py b/pyrogram/client/types/messages_and_media/animation.py index a8641e9e..0e36d5cf 100644 --- a/pyrogram/client/types/messages_and_media/animation.py +++ b/pyrogram/client/types/messages_and_media/animation.py @@ -16,7 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from struct import pack + +from pyrogram.api import types from pyrogram.api.core import Object +from .photo_size import PhotoSize +from ...ext.utils import encode class Animation(Object): @@ -53,18 +58,9 @@ class Animation(Object): ID = 0xb0700025 - def __init__( - self, - file_id: str, - width: int, - height: int, - duration: int, - thumb=None, - file_name: str = None, - mime_type: str = None, - file_size: int = None, - date: int = None - ): + def __init__(self, file_id: str, width: int, height: int, duration: int, *, + thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None, + client=None, raw=None): self.file_id = file_id self.thumb = thumb self.file_name = file_name @@ -74,3 +70,31 @@ class Animation(Object): self.width = width self.height = height self.duration = duration + + self._client = client + self._raw = raw + + @staticmethod + def parse(client, animation: types.Document, video_attributes: types.DocumentAttributeVideo, + file_name: str) -> "Animation": + return Animation( + file_id=encode( + pack( + ". +from struct import pack + +from pyrogram.api import types from pyrogram.api.core import Object +from .photo_size import PhotoSize +from ...ext.utils import encode class Video(Object): @@ -53,18 +58,9 @@ class Video(Object): ID = 0xb0700008 - def __init__( - self, - file_id: str, - width: int, - height: int, - duration: int, - thumb=None, - file_name: str = None, - mime_type: str = None, - file_size: int = None, - date: int = None - ): + def __init__(self, file_id: str, width: int, height: int, duration: int, *, + thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None, + client=None, raw=None): self.file_id = file_id self.thumb = thumb self.file_name = file_name @@ -74,3 +70,28 @@ class Video(Object): self.width = width self.height = height self.duration = duration + + self._client = client + self._raw = raw + + @staticmethod + def parse(client, video: types.Document, video_attributes: types.DocumentAttributeVideo, file_name: str) -> "Video": + return Video( + file_id=encode( + pack( + ". +from struct import pack + +from pyrogram.api import types from pyrogram.api.core import Object +from .photo_size import PhotoSize +from ...ext.utils import encode class VideoNote(Object): @@ -47,16 +52,9 @@ class VideoNote(Object): ID = 0xb0700010 - def __init__( - self, - file_id: str, - length: int, - duration: int, - thumb=None, - mime_type: str = None, - file_size: int = None, - date: int = None - ): + def __init__(self, file_id: str, length: int, duration: int, *, + thumb=None, mime_type: str = None, file_size: int = None, date: int = None, + client=None, raw=None): self.file_id = file_id self.thumb = thumb self.mime_type = mime_type @@ -64,3 +62,26 @@ class VideoNote(Object): self.date = date self.length = length self.duration = duration + + self._client = client + self._raw = raw + + @staticmethod + def parse(client, video_note: types.Document, video_attributes: types.DocumentAttributeVideo) -> "VideoNote": + return VideoNote( + file_id=encode( + pack( + "