@@ -153,6 +153,52 @@ async def edit_message_media(
153153 media = utils .get_input_media_from_file_id (media .media , FileType .PHOTO , has_spoiler = media .has_spoiler )
154154 elif isinstance (media , types .InputMediaVideo ):
155155 show_caption_above_media .append (media .show_caption_above_media )
156+ coverfile = None
157+ start_timestamp = None
158+ # TODO: remove this duplicate code
159+ if media .start_timestamp :
160+ start_timestamp = media .start_timestamp
161+ if media .cover :
162+ cover = media .cover
163+
164+ cover_is_bytes_io = isinstance (cover , io .BytesIO )
165+ cover_is_uploaded_file = cover_is_bytes_io or os .path .isfile (cover )
166+ cover_is_external_url = not cover_is_uploaded_file and re .match ("^https?://" , cover )
167+
168+ if cover_is_bytes_io and not hasattr (cover , "name" ):
169+ cover .name = "cover.jpg"
170+ if cover_is_uploaded_file :
171+ coverfile = await self .invoke (
172+ raw .functions .messages .UploadMedia (
173+ business_connection_id = business_connection_id ,
174+ peer = await self .resolve_peer (chat_id ),
175+ media = raw .types .InputMediaUploadedPhoto (
176+ file = await self .save_file (cover )
177+ )
178+ )
179+ )
180+ coverfile = raw .types .InputPhoto (
181+ id = coverfile .photo .id ,
182+ access_hash = coverfile .photo .access_hash ,
183+ file_reference = coverfile .photo .file_reference
184+ )
185+ elif cover_is_external_url :
186+ coverfile = await self .invoke (
187+ raw .functions .messages .UploadMedia (
188+ business_connection_id = business_connection_id ,
189+ peer = await self .resolve_peer (chat_id ),
190+ media = raw .types .InputMediaPhotoExternal (
191+ url = cover
192+ )
193+ )
194+ )
195+ coverfile = raw .types .InputPhoto (
196+ id = coverfile .photo .id ,
197+ access_hash = coverfile .photo .access_hash ,
198+ file_reference = coverfile .photo .file_reference
199+ )
200+ else :
201+ coverfile = (utils .get_input_media_from_file_id (cover , FileType .PHOTO )).id
156202 if is_uploaded_file :
157203 uploaded_media = await self .invoke (
158204 raw .functions .messages .UploadMedia (
@@ -183,15 +229,21 @@ async def edit_message_media(
183229 access_hash = uploaded_media .document .access_hash ,
184230 file_reference = uploaded_media .document .file_reference
185231 ),
186- spoiler = media .has_spoiler
232+ spoiler = media .has_spoiler ,
233+ video_cover = coverfile ,
234+ video_timestamp = start_timestamp
187235 )
188236 elif is_external_url :
189237 media = raw .types .InputMediaDocumentExternal (
190238 url = media .media ,
191- spoiler = media .has_spoiler
239+ spoiler = media .has_spoiler ,
240+ video_cover = coverfile ,
241+ video_timestamp = start_timestamp
192242 )
193243 else :
194244 media = utils .get_input_media_from_file_id (media .media , FileType .VIDEO , has_spoiler = media .has_spoiler )
245+ media .video_cover = coverfile
246+ media .video_timestamp = start_timestamp
195247 elif isinstance (media , types .InputMediaAudio ):
196248 if is_uploaded_file :
197249 media = await self .invoke (
0 commit comments