-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathvideo_note.py
More file actions
111 lines (94 loc) · 3.65 KB
/
video_note.py
File metadata and controls
111 lines (94 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Hydrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2023 Dan <https://github.com/delivrance>
# Copyright (C) 2023-present Hydrogram <https://hydrogram.org>
#
# This file is part of Hydrogram.
#
# Hydrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hydrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from typing import TYPE_CHECKING
import hydrogram
from hydrogram import raw, types, utils
from hydrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType
from hydrogram.types.object import Object
if TYPE_CHECKING:
from datetime import datetime
class VideoNote(Object):
"""A video note.
Parameters:
file_id (``str``):
Identifier for this file, which can be used to download or reuse the file.
file_unique_id (``str``):
Unique identifier for this file, which is supposed to be the same over time and for different accounts.
Can't be used to download or reuse the file.
length (``int``):
Video width and height as defined by sender.
duration (``int``):
Duration of the video in seconds as defined by sender.
mime_type (``str``, *optional*):
MIME type of the file as defined by sender.
file_size (``int``, *optional*):
File size.
date (:py:obj:`~datetime.datetime`, *optional*):
Date the video note was sent.
thumbs (List of :obj:`~hydrogram.types.Thumbnail`, *optional*):
Video thumbnails.
"""
def __init__(
self,
*,
client: hydrogram.Client = None,
file_id: str,
file_unique_id: str,
length: int,
duration: int,
thumbs: list[types.Thumbnail] | None = None,
mime_type: str | None = None,
file_size: int | None = None,
date: datetime | None = None,
):
super().__init__(client)
self.file_id = file_id
self.file_unique_id = file_unique_id
self.mime_type = mime_type
self.file_size = file_size
self.date = date
self.length = length
self.duration = duration
self.thumbs = thumbs
@staticmethod
def _parse(
client,
video_note: raw.types.Document,
video_attributes: raw.types.DocumentAttributeVideo,
) -> VideoNote:
return VideoNote(
file_id=FileId(
file_type=FileType.VIDEO_NOTE,
dc_id=video_note.dc_id,
media_id=video_note.id,
access_hash=video_note.access_hash,
file_reference=video_note.file_reference,
).encode(),
file_unique_id=FileUniqueId(
file_unique_type=FileUniqueType.DOCUMENT, media_id=video_note.id
).encode(),
length=video_attributes.w,
duration=video_attributes.duration,
file_size=video_note.size,
mime_type=video_note.mime_type,
date=utils.timestamp_to_datetime(video_note.date),
thumbs=types.Thumbnail._parse(client, video_note),
client=client,
)