AstraOS commited on
Commit
f422899
·
verified ·
1 Parent(s): 4f3ea19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -157,6 +157,20 @@ def validate_inputs():
157
  return False, f"Missing fields: {', '.join(missing)}"
158
  return True, ""
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  # -------------------------------------------------------------------
161
  # Live Logging Updater (Background Thread)
162
  # -------------------------------------------------------------------
@@ -379,10 +393,11 @@ def stream_to_youtube(input_url, quality_settings, video_codec, audio_codec, out
379
  logging.info("Streaming complete, resources cleaned up.")
380
  streaming_state = "idle"
381
  except Exception as e:
382
- error_message = f"An error occurred during streaming: {str(e)}"
383
  logging.error(error_message)
384
- logging.error(traceback.format_exc())
385
  streaming_state = "idle"
 
 
386
 
387
  def start_streaming(chat_id):
388
  global stream_thread, live_log_thread, stream_chat_id
@@ -414,16 +429,18 @@ def start_streaming(chat_id):
414
  live_log_thread.start()
415
  logging.info("Live log updater started.")
416
 
 
417
  return {
418
  "method": "sendMessage",
419
  "chat_id": chat_id,
420
- "text": "🚀 *Streaming initiated!* Use the inline keyboard to control the stream.",
421
  "reply_markup": get_inline_keyboard_for_stream(),
422
  "parse_mode": "Markdown"
423
  }
424
  except Exception as e:
425
  error_message = f"Failed to start streaming: {str(e)}"
426
  logging.error(error_message)
 
427
  return send_guide_message(chat_id, error_message)
428
 
429
  # -------------------------------------------------------------------
 
157
  return False, f"Missing fields: {', '.join(missing)}"
158
  return True, ""
159
 
160
+ # -------------------------------------------------------------------
161
+ # Notify Error Helper
162
+ # -------------------------------------------------------------------
163
+ def notify_error(chat_id, error_message):
164
+ payload = {
165
+ "chat_id": chat_id,
166
+ "text": f"⚠️ *Streaming Error Occurred:*\n\n{error_message}\n\nPlease check logs for details.",
167
+ "parse_mode": "Markdown"
168
+ }
169
+ try:
170
+ requests.post(f"{TELEGRAM_API_URL}/sendMessage", json=payload)
171
+ except Exception as e:
172
+ logging.error(f"Failed to notify error to user: {e}")
173
+
174
  # -------------------------------------------------------------------
175
  # Live Logging Updater (Background Thread)
176
  # -------------------------------------------------------------------
 
393
  logging.info("Streaming complete, resources cleaned up.")
394
  streaming_state = "idle"
395
  except Exception as e:
396
+ error_message = f"An error occurred during streaming: {str(e)}\n\n{traceback.format_exc()}"
397
  logging.error(error_message)
 
398
  streaming_state = "idle"
399
+ # Notify the user about the error using the logs
400
+ notify_error(chat_id, error_message)
401
 
402
  def start_streaming(chat_id):
403
  global stream_thread, live_log_thread, stream_chat_id
 
429
  live_log_thread.start()
430
  logging.info("Live log updater started.")
431
 
432
+ # Immediately show the live log (initial update will appear in 1 second)
433
  return {
434
  "method": "sendMessage",
435
  "chat_id": chat_id,
436
+ "text": "🚀 *Streaming initiated!* Live logs are now updating below. Use the inline keyboard to control the stream.",
437
  "reply_markup": get_inline_keyboard_for_stream(),
438
  "parse_mode": "Markdown"
439
  }
440
  except Exception as e:
441
  error_message = f"Failed to start streaming: {str(e)}"
442
  logging.error(error_message)
443
+ notify_error(chat_id, error_message)
444
  return send_guide_message(chat_id, error_message)
445
 
446
  # -------------------------------------------------------------------