From 5e6ad299884ed45ad0eabea3399819a06b0d6c28 Mon Sep 17 00:00:00 2001 From: uNickz <52837683+uNickz@users.noreply.github.com> Date: Mon, 7 Oct 2024 11:45:46 +0200 Subject: [PATCH] Add file_name param on InputMedia (#88) * Add file_name param on InputMedia Add file_name param on: - InputMediaVideo - InputMediaAudio - InputMediaDocument --------- Co-authored-by: KurimuzonAkuma <31959970+KurimuzonAkuma@users.noreply.github.com> --- pyrogram/methods/messages/send_media_group.py | 12 ++++++------ pyrogram/types/input_media/input_media_audio.py | 8 +++++++- pyrogram/types/input_media/input_media_document.py | 8 +++++++- pyrogram/types/input_media/input_media_video.py | 6 ++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py index c7b400734b..8c1794bf89 100644 --- a/pyrogram/methods/messages/send_media_group.py +++ b/pyrogram/methods/messages/send_media_group.py @@ -221,7 +221,7 @@ async def send_media_group( w=i.width, h=i.height ), - raw.types.DocumentAttributeFilename(file_name=os.path.basename(i.media)) + raw.types.DocumentAttributeFilename(file_name=i.file_name or os.path.basename(i.media)) ] ), business_connection_id=business_connection_id @@ -275,7 +275,7 @@ async def send_media_group( w=i.width, h=i.height ), - raw.types.DocumentAttributeFilename(file_name=getattr(i.media, "name", "video.mp4")) + raw.types.DocumentAttributeFilename(file_name=i.file_name or getattr(i.media, "name", "video.mp4")) ] ), business_connection_id=business_connection_id @@ -306,7 +306,7 @@ async def send_media_group( performer=i.performer, title=i.title ), - raw.types.DocumentAttributeFilename(file_name=os.path.basename(i.media)) + raw.types.DocumentAttributeFilename(file_name=i.file_name or os.path.basename(i.media)) ] ), business_connection_id=business_connection_id @@ -354,7 +354,7 @@ async def send_media_group( performer=i.performer, title=i.title ), - raw.types.DocumentAttributeFilename(file_name=getattr(i.media, "name", "audio.mp3")) + raw.types.DocumentAttributeFilename(file_name=i.file_name or getattr(i.media, "name", "audio.mp3")) ] ), business_connection_id=business_connection_id @@ -379,7 +379,7 @@ async def send_media_group( file=await self.save_file(i.media), thumb=await self.save_file(i.thumb), attributes=[ - raw.types.DocumentAttributeFilename(file_name=os.path.basename(i.media)) + raw.types.DocumentAttributeFilename(file_name=i.file_name or os.path.basename(i.media)) ] ), business_connection_id=business_connection_id @@ -424,7 +424,7 @@ async def send_media_group( file=await self.save_file(i.media), thumb=await self.save_file(i.thumb), attributes=[ - raw.types.DocumentAttributeFilename(file_name=getattr(i.media, "name", "file.zip")) + raw.types.DocumentAttributeFilename(file_name=i.file_name or getattr(i.media, "name", "file.zip")) ] ), business_connection_id=business_connection_id diff --git a/pyrogram/types/input_media/input_media_audio.py b/pyrogram/types/input_media/input_media_audio.py index cc91e7bd5c..32cc3f0e4d 100644 --- a/pyrogram/types/input_media/input_media_audio.py +++ b/pyrogram/types/input_media/input_media_audio.py @@ -61,6 +61,10 @@ class InputMediaAudio(InputMedia): title (``str``, *optional*): Title of the audio + + file_name (``str``, *optional*): + File name of the audio sent. + Defaults to file's path basename. """ def __init__( @@ -72,7 +76,8 @@ def __init__( caption_entities: List[MessageEntity] = None, duration: int = 0, performer: str = "", - title: str = "" + title: str = "", + file_name: str = None ): super().__init__(media, caption, parse_mode, caption_entities) @@ -80,3 +85,4 @@ def __init__( self.duration = duration self.performer = performer self.title = title + self.file_name = file_name diff --git a/pyrogram/types/input_media/input_media_document.py b/pyrogram/types/input_media/input_media_document.py index 3e4d510b95..665a4aab14 100644 --- a/pyrogram/types/input_media/input_media_document.py +++ b/pyrogram/types/input_media/input_media_document.py @@ -50,6 +50,10 @@ class InputMediaDocument(InputMedia): caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + file_name (``str``, *optional*): + File name of the document sent. + Defaults to file's path basename. """ def __init__( @@ -58,8 +62,10 @@ def __init__( thumb: str = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: List[MessageEntity] = None + caption_entities: List[MessageEntity] = None, + file_name: str = None ): super().__init__(media, caption, parse_mode, caption_entities) self.thumb = thumb + self.file_name = file_name diff --git a/pyrogram/types/input_media/input_media_video.py b/pyrogram/types/input_media/input_media_video.py index 6ab7a1a6e4..fa8b74c954 100644 --- a/pyrogram/types/input_media/input_media_video.py +++ b/pyrogram/types/input_media/input_media_video.py @@ -61,6 +61,10 @@ class InputMediaVideo(InputMedia): duration (``int``, *optional*): Video duration. + file_name (``str``, *optional*): + File name of the video sent. + Defaults to file's path basename. + supports_streaming (``bool``, *optional*): Pass True, if the uploaded video is suitable for streaming. @@ -82,6 +86,7 @@ def __init__( width: int = 0, height: int = 0, duration: int = 0, + file_name: str = None, supports_streaming: bool = True, has_spoiler: bool = None, no_sound: bool = None, @@ -92,6 +97,7 @@ def __init__( self.width = width self.height = height self.duration = duration + self.file_name = file_name self.supports_streaming = supports_streaming self.has_spoiler = has_spoiler self.no_sound = no_sound