diff --git a/pyrogram/api/core/primitives/string.py b/pyrogram/api/core/primitives/string.py index 5c05e5b0..3584d1b9 100644 --- a/pyrogram/api/core/primitives/string.py +++ b/pyrogram/api/core/primitives/string.py @@ -24,7 +24,7 @@ from . import Bytes class String(Bytes): @staticmethod def read(b: BytesIO, *args) -> str: - return super(String, String).read(b).decode() + return super(String, String).read(b).decode(errors="replace") def __new__(cls, value: str) -> bytes: return super().__new__(cls, value.encode()) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index a3cbd93b..97002e79 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -218,28 +218,33 @@ class Client(Methods, BaseClient): self.session.start() self.is_started = True - if self.user_id is None: + try: + if self.user_id is None: + if self.bot_token is None: + self.authorize_user() + else: + self.authorize_bot() + + self.save_session() + if self.bot_token is None: - self.authorize_user() + now = time.time() + + if abs(now - self.date) > Client.OFFLINE_SLEEP: + self.peers_by_username = {} + self.peers_by_phone = {} + + self.get_initial_dialogs() + self.get_contacts() + else: + self.send(functions.messages.GetPinnedDialogs()) + self.get_initial_dialogs_chunk() else: - self.authorize_bot() - - self.save_session() - - if self.bot_token is None: - now = time.time() - - if abs(now - self.date) > Client.OFFLINE_SLEEP: - self.peers_by_username = {} - self.peers_by_phone = {} - - self.get_initial_dialogs() - self.get_contacts() - else: - self.send(functions.messages.GetPinnedDialogs()) - self.get_initial_dialogs_chunk() - else: - self.send(functions.updates.GetState()) + self.send(functions.updates.GetState()) + except Exception as e: + self.is_started = False + self.session.stop() + raise e for i in range(self.UPDATES_WORKERS): self.updates_workers_list.append( diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index f31ffa21..3bb23afb 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -35,6 +35,7 @@ class SendAudio(BaseClient): duration: int = 0, performer: str = None, title: str = None, + thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None, @@ -73,6 +74,12 @@ class SendAudio(BaseClient): title (``str``, *optional*): Track name. + thumb (``str``, *optional*): + Thumbnail of the music file album cover. + The thumbnail should be in JPEG format and less than 200 KB in size. + A thumbnail's width and height should not exceed 90 pixels. + Thumbnails can't be reused and can be only uploaded as a new file. + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -117,10 +124,12 @@ class SendAudio(BaseClient): style = self.html if parse_mode.lower() == "html" else self.markdown if os.path.exists(audio): + thumb = None if thumb is None else self.save_file(thumb) file = self.save_file(audio, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"), file=file, + thumb=thumb, attributes=[ types.DocumentAttributeAudio( duration=duration, diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index 87063ee3..4317d88b 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -74,9 +74,10 @@ class SendVideo(BaseClient): Video height. thumb (``str``, *optional*): - Video thumbnail. - Pass a file path as string to send an image that exists on your local machine. - Thumbnail should have 90 or less pixels of width and 90 or less pixels of height. + Thumbnail of the video sent. + The thumbnail should be in JPEG format and less than 200 KB in size. + A thumbnail's width and height should not exceed 90 pixels. + Thumbnails can't be reused and can be only uploaded as a new file. supports_streaming (``bool``, *optional*): Pass True, if the uploaded video is suitable for streaming. diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 4ca32733..0d513430 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -199,6 +199,7 @@ class Session: i.join() self.net_worker_list.clear() + self.recv_queue.queue.clear() for i in self.results.values(): i.event.set()