Skip to content

Commit 283278a

Browse files
Added the class VideoQuality and the field qualities to the class Video allowing bots to get information about other available qualities of a video.
1 parent 78158ba commit 283278a

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

telebot/types.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,9 @@ class Video(JsonDeserializable):
21852185
:param start_timestamp: Optional. Timestamp in seconds from which the video will play in the message
21862186
:type start_timestamp: :obj:`int`
21872187

2188+
:param qualities: Optional. List of available qualities of the video
2189+
:type qualities: List[:class:`telebot.types.VideoQuality`]
2190+
21882191
:param file_name: Optional. Original filename as defined by sender
21892192
:type file_name: :obj:`str`
21902193

@@ -2207,10 +2210,12 @@ def de_json(cls, json_string):
22072210
obj['thumbnail'] = PhotoSize.de_json(obj['thumbnail'])
22082211
if 'cover' in obj:
22092212
obj['cover'] = [PhotoSize.de_json(c) for c in obj['cover']]
2213+
if 'qualities' in obj:
2214+
obj['qualities'] = [VideoQuality.de_json(q) for q in obj['qualities']]
22102215
return cls(**obj)
22112216

22122217
def __init__(self, file_id, file_unique_id, width, height, duration, thumbnail=None, file_name=None, mime_type=None, file_size=None,
2213-
cover=None, start_timestamp=None, **kwargs):
2218+
cover=None, start_timestamp=None, qualities=None, **kwargs):
22142219
self.file_id: str = file_id
22152220
self.file_unique_id: str = file_unique_id
22162221
self.width: int = width
@@ -2222,7 +2227,8 @@ def __init__(self, file_id, file_unique_id, width, height, duration, thumbnail=N
22222227
self.file_size: Optional[int] = file_size
22232228
self.cover: Optional[List[PhotoSize]] = cover
22242229
self.start_timestamp: Optional[int] = start_timestamp
2225-
2230+
self.qualities: Optional[List[VideoQuality]] = qualities
2231+
22262232
@property
22272233
def thumb(self) -> Optional[PhotoSize]:
22282234
log_deprecation_warning('The parameter "thumb" is deprecated, use "thumbnail" instead')
@@ -13565,3 +13571,45 @@ def de_json(cls, json_string):
1356513571
obj['new_owner'] = User.de_json(obj['new_owner'])
1356613572
return cls(**obj)
1356713573

13574+
class VideoQuality(JsonDeserializable):
13575+
"""
13576+
This object represents a video file of a specific quality.
13577+
13578+
Telegram documentation: https://core.telegram.org/bots/api#videoquality
13579+
13580+
:param file_id: Identifier for this file, which can be used to download or reuse the file
13581+
:type file_id: :obj:`str`
13582+
13583+
:param file_unique_id: Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
13584+
:type file_unique_id: :obj:`str`
13585+
13586+
:param width: Video width
13587+
:type width: :obj:`int`
13588+
13589+
:param height: Video height
13590+
:type height: :obj:`int`
13591+
13592+
:param codec: Codec that was used to encode the video, for example, “h264”, “h265”, or “av01”
13593+
:type codec: :obj:`str`
13594+
13595+
:param file_size: Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it.
13596+
But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value.
13597+
:type file_size: :obj:`int`
13598+
13599+
:return: Instance of the class
13600+
:rtype: :class:`VideoQuality`
13601+
"""
13602+
def __init__(self, file_id: str, file_unique_id: str, width: int, height: int, codec: str, file_size: Optional[int] = None, **kwargs):
13603+
self.file_id: str = file_id
13604+
self.file_unique_id: str = file_unique_id
13605+
self.width: int = width
13606+
self.height: int = height
13607+
self.codec: str = codec
13608+
self.file_size: Optional[int] = file_size
13609+
13610+
@classmethod
13611+
def de_json(cls, json_string):
13612+
if json_string is None: return None
13613+
obj = cls.check_json(json_string)
13614+
return cls(**obj)
13615+

0 commit comments

Comments
 (0)