diff --git a/bot/configuration.py b/bot/configuration.py index f4d0b45..30f95aa 100644 --- a/bot/configuration.py +++ b/bot/configuration.py @@ -208,6 +208,7 @@ def __init__(self, config: configparser.ConfigParser): self.ssl_verify: bool = self._get_boolean("ssl_verify", default=True) self.port: int = self._get_int("port", default=80) self.api_url: str = self._get_str("api_url", default="https://api.telegram.org/bot") + self.max_upload_file_size: int = 50 if self.api_url == "https://api.telegram.org/bot" else 2000 self.socks_proxy: str = self._get_str("socks_proxy", default="") self.light_device_name: str = self._get_str("light_device", default="") self.poweroff_device_name: str = self._get_str("power_device", default="") diff --git a/bot/main.py b/bot/main.py index 5ce1264..ddd09a6 100644 --- a/bot/main.py +++ b/bot/main.py @@ -233,8 +233,9 @@ async def get_video(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: loop_loc = asyncio.get_running_loop() (video_bio, thumb_bio, width, height) = await loop_loc.run_in_executor(executors_pool, cameraWrap.take_video) await info_reply.edit_text(text="Uploading video") - if video_bio.getbuffer().nbytes > 52428800: - await info_reply.edit_text(text="Telegram has a 50mb restriction...") + max_upload_file_size: int = configWrap.bot_config.max_upload_file_size + if video_bio.getbuffer().nbytes > max_upload_file_size * 1024 * 1024: + await info_reply.edit_text(text=f"Telegram has a {max_upload_file_size}mb restriction...") else: await update.effective_message.reply_video( video=video_bio, diff --git a/bot/notifications.py b/bot/notifications.py index 05214cd..e7e0111 100644 --- a/bot/notifications.py +++ b/bot/notifications.py @@ -44,6 +44,7 @@ def __init__( self._interval: int = config.notifications.interval self._notify_groups: List[int] = config.notifications.notify_groups self._group_only: bool = config.notifications.group_only + self._max_upload_file_size: int = config.bot_config.max_upload_file_size self._progress_update_message = config.telegram_ui.progress_update_message self._silent_progress: bool = config.telegram_ui.silent_progress @@ -554,8 +555,8 @@ async def _send_video(self, paths: List[str], message: str) -> None: with open(path_obj, "rb") as fh: bio.write(fh.read()) bio.seek(0) - if bio.getbuffer().nbytes > 52428800: - await self._bot.send_message(self._chat_id, text=f"Telegram bots have a 50mb filesize restriction, video couldn't be uploaded: `{path}`") + if bio.getbuffer().nbytes > self._max_upload_file_size * 1024 * 1024: + await self._bot.send_message(self._chat_id, text=f"Telegram bots have a {self._max_upload_file_size}mb filesize restriction, video couldn't be uploaded: `{path}`") else: if not photos_list: photos_list.append(InputMediaVideo(bio, filename=bio.name, caption=message)) @@ -599,8 +600,8 @@ async def _send_document(self, paths: List[str], message: str) -> None: with open(path_obj, "rb") as fh: bio.write(fh.read()) bio.seek(0) - if bio.getbuffer().nbytes > 52428800: - await self._bot.send_message(self._chat_id, text=f"Telegram bots have a 50mb filesize restriction, document couldn't be uploaded: `{path}`") + if bio.getbuffer().nbytes > self._max_upload_file_size * 1024 * 1024: + await self._bot.send_message(self._chat_id, text=f"Telegram bots have a {self._max_upload_file_size}mb filesize restriction, document couldn't be uploaded: `{path}`") else: if not photos_list: photos_list.append(InputMediaDocument(bio, filename=bio.name, caption=message)) diff --git a/bot/timelapse.py b/bot/timelapse.py index 39bf4b9..3f8543c 100644 --- a/bot/timelapse.py +++ b/bot/timelapse.py @@ -42,6 +42,7 @@ def __init__( self._limit_fps: bool = config.timelapse.limit_fps self._min_lapse_duration: int = config.timelapse.min_lapse_duration self._max_lapse_duration: int = config.timelapse.max_lapse_duration + self._max_upload_file_size: int = config.bot_config.max_upload_file_size self._last_frame_duration: int = config.timelapse.last_frame_duration self._after_lapse_gcode: str = config.timelapse.after_lapse_gcode @@ -251,8 +252,8 @@ async def upload_timelapse(self, lapse_filename: str, info_mess, gcode_name_out: if self._send_finished_lapse: await info_mess.edit_text(text="Uploading time-lapse") - if len(video_bytes) > 52428800: - await info_mess.edit_text(text=f"Telegram bots have a 50mb filesize restriction, please retrieve the timelapse from the configured folder\n{video_path}") + if len(video_bytes) > self._max_upload_file_size * 1024 * 1024: + await info_mess.edit_text(text=f"Telegram bots have a {self._max_upload_file_size}mb filesize restriction, please retrieve the timelapse from the configured folder\n{video_path}") else: lapse_caption = f"time-lapse of {gcode_name}" if self._camera.lapse_missed_frames > 0: @@ -264,7 +265,7 @@ async def upload_timelapse(self, lapse_filename: str, info_mess, gcode_name_out: width=width, height=height, caption=lapse_caption, - write_timeout=120, + write_timeout=600, disable_notification=self._silent_progress, ) try: