mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Allowing nosound_video to be specified (#4090)
This commit is contained in:
		
							parent
							
								
									7b1b33f805
								
							
						
					
					
						commit
						6e7423e894
					
				| 
						 | 
					@ -640,7 +640,8 @@ class MessageMethods:
 | 
				
			||||||
            background: bool = None,
 | 
					            background: bool = None,
 | 
				
			||||||
            supports_streaming: bool = False,
 | 
					            supports_streaming: bool = False,
 | 
				
			||||||
            schedule: 'hints.DateLike' = None,
 | 
					            schedule: 'hints.DateLike' = None,
 | 
				
			||||||
            comment_to: 'typing.Union[int, types.Message]' = None
 | 
					            comment_to: 'typing.Union[int, types.Message]' = None,
 | 
				
			||||||
 | 
					            nosound_video: bool = None,
 | 
				
			||||||
    ) -> 'types.Message':
 | 
					    ) -> 'types.Message':
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Sends a message to the specified user, chat or channel.
 | 
					        Sends a message to the specified user, chat or channel.
 | 
				
			||||||
| 
						 | 
					@ -754,6 +755,15 @@ class MessageMethods:
 | 
				
			||||||
                This parameter takes precedence over ``reply_to``. If there is
 | 
					                This parameter takes precedence over ``reply_to``. If there is
 | 
				
			||||||
                no linked chat, `telethon.errors.sgIdInvalidError` is raised.
 | 
					                no linked chat, `telethon.errors.sgIdInvalidError` is raised.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            nosound_video (`bool`, optional):
 | 
				
			||||||
 | 
					                Only applicable when sending a video file without an audio
 | 
				
			||||||
 | 
					                track. If set to ``True``, the video will be displayed in
 | 
				
			||||||
 | 
					                Telegram as a video. If set to ``False``, Telegram will attempt
 | 
				
			||||||
 | 
					                to display the video as an animated gif. (It may still display
 | 
				
			||||||
 | 
					                as a video due to other factors.) The value is ignored if set
 | 
				
			||||||
 | 
					                on non-video files. This is set to ``True`` for albums, as gifs
 | 
				
			||||||
 | 
					                cannot be sent in albums.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Returns
 | 
					        Returns
 | 
				
			||||||
            The sent `custom.Message <telethon.tl.custom.message.Message>`.
 | 
					            The sent `custom.Message <telethon.tl.custom.message.Message>`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -821,7 +831,8 @@ class MessageMethods:
 | 
				
			||||||
                buttons=buttons, clear_draft=clear_draft, silent=silent,
 | 
					                buttons=buttons, clear_draft=clear_draft, silent=silent,
 | 
				
			||||||
                schedule=schedule, supports_streaming=supports_streaming,
 | 
					                schedule=schedule, supports_streaming=supports_streaming,
 | 
				
			||||||
                formatting_entities=formatting_entities,
 | 
					                formatting_entities=formatting_entities,
 | 
				
			||||||
                comment_to=comment_to, background=background
 | 
					                comment_to=comment_to, background=background,
 | 
				
			||||||
 | 
					                nosound_video=nosound_video,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        entity = await self.get_input_entity(entity)
 | 
					        entity = await self.get_input_entity(entity)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -117,6 +117,7 @@ class UploadMethods:
 | 
				
			||||||
            schedule: 'hints.DateLike' = None,
 | 
					            schedule: 'hints.DateLike' = None,
 | 
				
			||||||
            comment_to: 'typing.Union[int, types.Message]' = None,
 | 
					            comment_to: 'typing.Union[int, types.Message]' = None,
 | 
				
			||||||
            ttl: int = None,
 | 
					            ttl: int = None,
 | 
				
			||||||
 | 
					            nosound_video: bool = None,
 | 
				
			||||||
            **kwargs) -> 'types.Message':
 | 
					            **kwargs) -> 'types.Message':
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Sends message with the given file to the specified entity.
 | 
					        Sends message with the given file to the specified entity.
 | 
				
			||||||
| 
						 | 
					@ -286,6 +287,15 @@ class UploadMethods:
 | 
				
			||||||
                Not all types of media can be used with this parameter, such
 | 
					                Not all types of media can be used with this parameter, such
 | 
				
			||||||
                as text documents, which will fail with ``TtlMediaInvalidError``.
 | 
					                as text documents, which will fail with ``TtlMediaInvalidError``.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            nosound_video (`bool`, optional):
 | 
				
			||||||
 | 
					                Only applicable when sending a video file without an audio
 | 
				
			||||||
 | 
					                track. If set to ``True``, the video will be displayed in
 | 
				
			||||||
 | 
					                Telegram as a video. If set to ``False``, Telegram will attempt
 | 
				
			||||||
 | 
					                to display the video as an animated gif. (It may still display
 | 
				
			||||||
 | 
					                as a video due to other factors.) The value is ignored if set
 | 
				
			||||||
 | 
					                on non-video files. This is set to ``True`` for albums, as gifs
 | 
				
			||||||
 | 
					                cannot be sent in albums.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Returns
 | 
					        Returns
 | 
				
			||||||
            The `Message <telethon.tl.custom.message.Message>` (or messages)
 | 
					            The `Message <telethon.tl.custom.message.Message>` (or messages)
 | 
				
			||||||
            containing the sent file, or messages if a list of them was passed.
 | 
					            containing the sent file, or messages if a list of them was passed.
 | 
				
			||||||
| 
						 | 
					@ -389,7 +399,8 @@ class UploadMethods:
 | 
				
			||||||
            progress_callback=progress_callback,
 | 
					            progress_callback=progress_callback,
 | 
				
			||||||
            attributes=attributes,  allow_cache=allow_cache, thumb=thumb,
 | 
					            attributes=attributes,  allow_cache=allow_cache, thumb=thumb,
 | 
				
			||||||
            voice_note=voice_note, video_note=video_note,
 | 
					            voice_note=voice_note, video_note=video_note,
 | 
				
			||||||
            supports_streaming=supports_streaming, ttl=ttl
 | 
					            supports_streaming=supports_streaming, ttl=ttl,
 | 
				
			||||||
 | 
					            nosound_video=nosound_video,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # e.g. invalid cast from :tl:`MessageMediaWebPage`
 | 
					        # e.g. invalid cast from :tl:`MessageMediaWebPage`
 | 
				
			||||||
| 
						 | 
					@ -439,13 +450,13 @@ class UploadMethods:
 | 
				
			||||||
        media = []
 | 
					        media = []
 | 
				
			||||||
        for sent_count, file in enumerate(files):
 | 
					        for sent_count, file in enumerate(files):
 | 
				
			||||||
            # Albums want :tl:`InputMedia` which, in theory, includes
 | 
					            # Albums want :tl:`InputMedia` which, in theory, includes
 | 
				
			||||||
            # :tl:`InputMediaUploadedPhoto`. However using that will
 | 
					            # :tl:`InputMediaUploadedPhoto`. However, using that will
 | 
				
			||||||
            # make it `raise MediaInvalidError`, so we need to upload
 | 
					            # make it `raise MediaInvalidError`, so we need to upload
 | 
				
			||||||
            # it as media and then convert that to :tl:`InputMediaPhoto`.
 | 
					            # it as media and then convert that to :tl:`InputMediaPhoto`.
 | 
				
			||||||
            fh, fm, _ = await self._file_to_media(
 | 
					            fh, fm, _ = await self._file_to_media(
 | 
				
			||||||
                file, supports_streaming=supports_streaming,
 | 
					                file, supports_streaming=supports_streaming,
 | 
				
			||||||
                force_document=force_document, ttl=ttl,
 | 
					                force_document=force_document, ttl=ttl,
 | 
				
			||||||
                progress_callback=used_callback)
 | 
					                progress_callback=used_callback, nosound_video=True)
 | 
				
			||||||
            if isinstance(fm, (types.InputMediaUploadedPhoto, types.InputMediaPhotoExternal)):
 | 
					            if isinstance(fm, (types.InputMediaUploadedPhoto, types.InputMediaPhotoExternal)):
 | 
				
			||||||
                r = await self(functions.messages.UploadMediaRequest(
 | 
					                r = await self(functions.messages.UploadMediaRequest(
 | 
				
			||||||
                    entity, media=fm
 | 
					                    entity, media=fm
 | 
				
			||||||
| 
						 | 
					@ -675,7 +686,7 @@ class UploadMethods:
 | 
				
			||||||
            progress_callback=None, attributes=None, thumb=None,
 | 
					            progress_callback=None, attributes=None, thumb=None,
 | 
				
			||||||
            allow_cache=True, voice_note=False, video_note=False,
 | 
					            allow_cache=True, voice_note=False, video_note=False,
 | 
				
			||||||
            supports_streaming=False, mime_type=None, as_image=None,
 | 
					            supports_streaming=False, mime_type=None, as_image=None,
 | 
				
			||||||
            ttl=None):
 | 
					            ttl=None, nosound_video=None):
 | 
				
			||||||
        if not file:
 | 
					        if not file:
 | 
				
			||||||
            return None, None, None
 | 
					            return None, None, None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -762,7 +773,7 @@ class UploadMethods:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # setting `nosound_video` to `True` doesn't affect videos with sound
 | 
					            # setting `nosound_video` to `True` doesn't affect videos with sound
 | 
				
			||||||
            # instead it prevents sending silent videos as GIFs
 | 
					            # instead it prevents sending silent videos as GIFs
 | 
				
			||||||
            nosound_video = True if mime_type.split("/")[0] == 'video' else None
 | 
					            nosound_video = nosound_video if mime_type.split("/")[0] == 'video' else None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            media = types.InputMediaUploadedDocument(
 | 
					            media = types.InputMediaUploadedDocument(
 | 
				
			||||||
                file=file_handle,
 | 
					                file=file_handle,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
# Versions should comply with PEP440.
 | 
					# Versions should comply with PEP440.
 | 
				
			||||||
# This line is parsed in setup.py:
 | 
					# This line is parsed in setup.py:
 | 
				
			||||||
__version__ = '1.28.4'
 | 
					__version__ = '1.28.5'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user