Skip to content

Commit

Permalink
Pyrofork: Move duplicated codes to separate method
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Jan 4, 2024
1 parent a882a99 commit 61790fb
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions pyrogram/methods/users/send_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ class SendStory:
def _split(self, message, entities, *args, **kwargs):
return message, entities

async def _parse_uploaded_video(
self: "pyrogram.Client",
file_name: str,
video: Union[str, BinaryIO]
):
file = await self.save_file(video)
media = raw.types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(file_name or video.name) or "video/mp4",
file=file,
attributes=[
raw.types.DocumentAttributeVideo(
supports_streaming=True,
duration=0,
w=0,
h=0
)
]
)
return media

async def send_story(
self: "pyrogram.Client",
chat_id: Union[int,str] = None,
Expand Down Expand Up @@ -185,33 +205,9 @@ async def send_story(
)
else:
video = await self.download_media(video, in_memory=True)
file = await self.save_file(video)
media = raw.types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(file_name or video.name) or "video/mp4",
file=file,
attributes=[
raw.types.DocumentAttributeVideo(
supports_streaming=True,
duration=0,
w=0,
h=0
)
]
)
media = await self._parse_uploaded_video(file_name,video)
else:
file = await self.save_file(video)
media = raw.types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(file_name or video.name) or "video/mp4",
file=file,
attributes=[
raw.types.DocumentAttributeVideo(
supports_streaming=True,
duration=0,
w=0,
h=0
)
]
)
media = await self._parse_uploaded_video(file_name,video)
else:
if forward_from_chat_id is None:
raise ValueError("You need to pass one of the following parameter photo/video/forward_from_chat_id!")
Expand Down

0 comments on commit 61790fb

Please sign in to comment.