Skip to content

Commit 782e6cd

Browse files
authored
Warn user if a video note will be treated as a video (#201)
1 parent e6afae1 commit 782e6cd

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

pyrogram/methods/messages/send_video_note.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
log = logging.getLogger(__name__)
3030

31+
# Maximum file size for local video note (10 MB)
32+
_MAX_VIDEO_NOTE_SIZE_BYTES: int = 10 * 1024 * 1024
33+
3134
class SendVideoNote:
3235
async def send_video_note(
3336
self: "pyrogram.Client",
@@ -80,6 +83,10 @@ async def send_video_note(
8083
pass a file path as string to upload a new video note that exists on your local machine, or
8184
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
8285
Sending video notes by a URL is currently unsupported.
86+
87+
.. note::
88+
When uploading from local file: if the file is larger than 10 MB, Telegram will upload
89+
it as a regular video instead of a video note.
8390
8491
duration (``int``, *optional*):
8592
Duration of sent video in seconds.
@@ -238,6 +245,16 @@ async def send_video_note(
238245
try:
239246
if isinstance(video_note, str):
240247
if os.path.isfile(video_note):
248+
249+
# Notify user why the sent video is not video note
250+
file_size = os.path.getsize(video_note)
251+
if file_size > _MAX_VIDEO_NOTE_SIZE_BYTES:
252+
log.warning(
253+
"Video note file size (%.1f MB) exceeds 10 MB limit. "
254+
"Telegram will treat it as a regular video instead of a video note.",
255+
file_size / (1024 * 1024),
256+
)
257+
241258
thumb = await self.save_file(thumb)
242259
file = await self.save_file(video_note, progress=progress, progress_args=progress_args)
243260
media = raw.types.InputMediaUploadedDocument(
@@ -306,4 +323,4 @@ async def send_video_note(
306323

307324
return messages[0] if messages else None
308325
except StopTransmission:
309-
return None
326+
return None

0 commit comments

Comments
 (0)