Update app.py
Browse files
app.py
CHANGED
@@ -78,14 +78,17 @@ list_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(messa
|
|
78 |
logger.addHandler(list_handler)
|
79 |
|
80 |
# -------------------------------------------------------------------
|
81 |
-
# Helper Function: Compose Streaming Message
|
82 |
# -------------------------------------------------------------------
|
83 |
def compose_streaming_message():
|
84 |
-
global live_log_display, error_notification
|
|
|
85 |
msg = ""
|
86 |
if error_notification:
|
87 |
msg += "<b>ERROR:</b> " + error_notification + "\n\n"
|
88 |
-
msg += "π <b>Streaming in progress!</b>\n
|
|
|
|
|
89 |
return msg
|
90 |
|
91 |
# -------------------------------------------------------------------
|
@@ -236,7 +239,7 @@ def handle_setting(chat_id):
|
|
236 |
user_inputs = {}
|
237 |
current_step = conversation_fields[0]
|
238 |
text = ("βοΈ *Advanced Mode Activated!*\n\n"
|
239 |
-
"Please enter the *input url*:")
|
240 |
logging.info(f"/setting command from chat {chat_id} - advanced mode enabled")
|
241 |
return {
|
242 |
"method": "sendMessage",
|
@@ -410,6 +413,7 @@ def start_streaming(chat_id):
|
|
410 |
stream_thread.daemon = True
|
411 |
stream_thread.start()
|
412 |
logging.info("Streaming thread started.")
|
|
|
413 |
return {
|
414 |
"method": "sendMessage",
|
415 |
"chat_id": chat_id,
|
@@ -531,15 +535,13 @@ async def telegram_webhook(request: Request):
|
|
531 |
else:
|
532 |
response = send_guide_message(chat_id, "β Unknown callback command.")
|
533 |
|
534 |
-
#
|
535 |
if callback_data in ["pause", "resume", "abort", "status", "start_stream"]:
|
536 |
response["method"] = "editMessageText"
|
537 |
response["message_id"] = message_id
|
538 |
response["text"] = compose_streaming_message()
|
539 |
response["parse_mode"] = "HTML"
|
540 |
-
|
541 |
-
if streaming_state in ["streaming", "paused"]:
|
542 |
-
response["reply_markup"] = get_inline_keyboard_for_stream()
|
543 |
return response
|
544 |
|
545 |
return {"status": "ok"}
|
|
|
78 |
logger.addHandler(list_handler)
|
79 |
|
80 |
# -------------------------------------------------------------------
|
81 |
+
# Helper Function: Compose Streaming Message (with extra stats)
|
82 |
# -------------------------------------------------------------------
|
83 |
def compose_streaming_message():
|
84 |
+
global live_log_display, error_notification, streaming_state, frames_encoded, bytes_sent
|
85 |
+
stats = f"State: {streaming_state} | Uptime: {get_uptime()} | Frames: {frames_encoded} | Bytes: {bytes_sent}\n"
|
86 |
msg = ""
|
87 |
if error_notification:
|
88 |
msg += "<b>ERROR:</b> " + error_notification + "\n\n"
|
89 |
+
msg += "π <b>Streaming in progress!</b>\n"
|
90 |
+
msg += stats + "\n"
|
91 |
+
msg += "Live Logs:\n" + live_log_display + "\n\nUse the inline keyboard to control the stream."
|
92 |
return msg
|
93 |
|
94 |
# -------------------------------------------------------------------
|
|
|
239 |
user_inputs = {}
|
240 |
current_step = conversation_fields[0]
|
241 |
text = ("βοΈ *Advanced Mode Activated!*\n\n"
|
242 |
+
"Please enter the *input url*:")
|
243 |
logging.info(f"/setting command from chat {chat_id} - advanced mode enabled")
|
244 |
return {
|
245 |
"method": "sendMessage",
|
|
|
413 |
stream_thread.daemon = True
|
414 |
stream_thread.start()
|
415 |
logging.info("Streaming thread started.")
|
416 |
+
# Immediately return a message that includes the live log display via compose_streaming_message()
|
417 |
return {
|
418 |
"method": "sendMessage",
|
419 |
"chat_id": chat_id,
|
|
|
535 |
else:
|
536 |
response = send_guide_message(chat_id, "β Unknown callback command.")
|
537 |
|
538 |
+
# Always update the message text with the latest live logs and keep the inline keyboard
|
539 |
if callback_data in ["pause", "resume", "abort", "status", "start_stream"]:
|
540 |
response["method"] = "editMessageText"
|
541 |
response["message_id"] = message_id
|
542 |
response["text"] = compose_streaming_message()
|
543 |
response["parse_mode"] = "HTML"
|
544 |
+
response["reply_markup"] = get_inline_keyboard_for_stream()
|
|
|
|
|
545 |
return response
|
546 |
|
547 |
return {"status": "ok"}
|