2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Refactor Animation, Video and VideoNote

This commit is contained in:
Dan 2018-12-15 21:40:44 +01:00
parent 905f4b8e62
commit 11ed26b318
3 changed files with 100 additions and 34 deletions

View File

@ -16,7 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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(
"<iiqq",
10,
animation.dc_id,
animation.id,
animation.access_hash
)
),
width=getattr(video_attributes, "w", 0),
height=getattr(video_attributes, "h", 0),
duration=getattr(video_attributes, "duration", 0),
thumb=PhotoSize.parse(client, animation.thumb),
mime_type=animation.mime_type,
file_size=animation.size,
file_name=file_name,
date=animation.date,
client=client,
raw=animation
)

View File

@ -16,7 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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(
"<iiqq",
4,
video.dc_id,
video.id,
video.access_hash
)
),
width=video_attributes.w,
height=video_attributes.h,
duration=video_attributes.duration,
thumb=PhotoSize.parse(client, video.thumb),
mime_type=video.mime_type,
file_size=video.size,
file_name=file_name,
date=video.date
)

View File

@ -16,7 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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(
"<iiqq",
13,
video_note.dc_id,
video_note.id,
video_note.access_hash
)
),
length=video_attributes.w,
duration=video_attributes.duration,
thumb=PhotoSize.parse(client, video_note.thumb),
file_size=video_note.size,
mime_type=video_note.mime_type,
date=video_note.date
)