Skip to content

Commit

Permalink
Add file_name param on InputMedia (#88)
Browse files Browse the repository at this point in the history
* Add file_name param on InputMedia

Add file_name param on:
 - InputMediaVideo
 - InputMediaAudio
 - InputMediaDocument

---------

Co-authored-by: KurimuzonAkuma <31959970+KurimuzonAkuma@users.noreply.github.com>
  • Loading branch information
uNickz and KurimuzonAkuma authored Oct 7, 2024
1 parent 1a9458f commit 5e6ad29
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
12 changes: 6 additions & 6 deletions pyrogram/methods/messages/send_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion pyrogram/types/input_media/input_media_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -72,11 +76,13 @@ 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)

self.thumb = thumb
self.duration = duration
self.performer = performer
self.title = title
self.file_name = file_name
8 changes: 7 additions & 1 deletion pyrogram/types/input_media/input_media_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -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
6 changes: 6 additions & 0 deletions pyrogram/types/input_media/input_media_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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

0 comments on commit 5e6ad29

Please sign in to comment.