1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19+ import io
1920import os
2021import re
2122
@@ -180,6 +181,47 @@ async def send_paid_media(
180181 )
181182 )
182183 elif isinstance (i , types .InputPaidMediaVideo ):
184+ video_cover_file = None
185+ if i .cover :
186+ is_bytes_io = isinstance (i .cover , io .BytesIO )
187+ is_uploaded_file = is_bytes_io or os .path .isfile (i .cover )
188+ is_external_url = not is_uploaded_file and re .match ("^https?://" , i .cover )
189+ if is_bytes_io and not hasattr (i .cover , "name" ):
190+ cover .name = "cover.jpg"
191+
192+ if is_uploaded_file :
193+ video_cover_file = await self .invoke (
194+ raw .functions .messages .UploadMedia (
195+ business_connection_id = business_connection_id ,
196+ peer = await self .resolve_peer (chat_id ),
197+ media = raw .types .InputMediaUploadedPhoto (
198+ file = await self .save_file (i .cover )
199+ )
200+ )
201+ )
202+ video_cover_file = raw .types .InputPhoto (
203+ id = video_cover_file .photo .id ,
204+ access_hash = video_cover_file .photo .access_hash ,
205+ file_reference = video_cover_file .photo .file_reference
206+ )
207+ elif is_external_url :
208+ video_cover_file = await self .invoke (
209+ raw .functions .messages .UploadMedia (
210+ business_connection_id = business_connection_id ,
211+ peer = await self .resolve_peer (chat_id ),
212+ media = raw .types .InputMediaPhotoExternal (
213+ url = i .cover
214+ )
215+ )
216+ )
217+ video_cover_file = raw .types .InputPhoto (
218+ id = video_cover_file .photo .id ,
219+ access_hash = video_cover_file .photo .access_hash ,
220+ file_reference = video_cover_file .photo .file_reference
221+ )
222+ else :
223+ video_cover_file = (utils .get_input_media_from_file_id (i .cover , FileType .PHOTO )).id
224+
183225 if isinstance (i .media , str ):
184226 if os .path .isfile (i .media ):
185227 attributes = [
@@ -200,7 +242,7 @@ async def send_paid_media(
200242 mime_type = self .guess_mime_type (i .media ) or "video/mp4" ,
201243 nosound_video = True ,
202244 attributes = attributes ,
203- video_cover = await self . save_file ( i . cover ) ,
245+ video_cover = video_cover_file ,
204246 video_timestamp = i .start_timestamp
205247 )
206248 )
@@ -219,7 +261,7 @@ async def send_paid_media(
219261 peer = await self .resolve_peer (chat_id ),
220262 media = raw .types .InputMediaDocumentExternal (
221263 url = i .media ,
222- video_cover = await self . save_file ( i . cover ) ,
264+ video_cover = video_cover_file ,
223265 video_timestamp = i .start_timestamp
224266 )
225267 )
@@ -234,6 +276,8 @@ async def send_paid_media(
234276 )
235277 else :
236278 media = utils .get_input_media_from_file_id (i .media , FileType .VIDEO )
279+ media .video_cover = video_cover_file
280+ media .video_timestamp = i .start_timestamp
237281 else :
238282 media = await self .invoke (
239283 raw .functions .messages .UploadMedia (
@@ -251,7 +295,7 @@ async def send_paid_media(
251295 ),
252296 raw .types .DocumentAttributeFilename (file_name = getattr (i .media , "name" , "video.mp4" ))
253297 ],
254- video_cover = await self . save_file ( i . cover ) ,
298+ video_cover = video_cover_file ,
255299 video_timestamp = i .start_timestamp
256300 )
257301 )
0 commit comments