webapp1 commited on
Commit
017414d
·
verified ·
1 Parent(s): 398cb65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -57,7 +57,8 @@ print("--- BOOT SEQUENCE INITIATED ---", flush=True)
57
  app = Flask(__name__)
58
 
59
  ALERT_EMAIL_SENDER = "gowreeshgowri50@gmail.com"
60
- ALERT_EMAIL_PASSWORD = "oynu ulet pynk xsza"
 
61
  ALERT_EMAIL_RECEIVER = "mcblackdevil12342@gmail.com"
62
  ENABLE_EMAIL_ALERTS = True
63
 
@@ -154,13 +155,12 @@ def process_accident_async(stream_id, frame, location, confidence, severity):
154
  except Exception as ve:
155
  print(f"Failed to attach video: {ve}")
156
 
157
- # Using Port 587 (TLS) which is much more reliable in cloud environments like HuggingFace
158
- server = smtplib.SMTP('smtp.gmail.com', 587)
159
- server.ehlo()
160
- server.starttls()
161
- server.login(ALERT_EMAIL_SENDER, ALERT_EMAIL_PASSWORD)
162
- server.send_message(msg)
163
- server.quit()
164
  print(f"📧 Dispatch Email Sent Successfully for Stream {stream_id}", flush=True)
165
  except Exception as e:
166
  print(f"📧 Email Failed to Send: {str(e)}", flush=True)
@@ -230,6 +230,18 @@ def init_upload():
230
  @app.route('/init_stream', methods=['POST'])
231
  def init_stream():
232
  url = request.json.get('url')
 
 
 
 
 
 
 
 
 
 
 
 
233
  loc, wx = get_geo_info(url)
234
  v_time = datetime.datetime.now().strftime("%H:%M:%S")
235
  stream_id = f"live_{uuid.uuid4().hex}"
 
57
  app = Flask(__name__)
58
 
59
  ALERT_EMAIL_SENDER = "gowreeshgowri50@gmail.com"
60
+ # FIX: Automatically strip spaces from Google App Password
61
+ ALERT_EMAIL_PASSWORD = "oynu ulet pynk xsza".replace(" ", "")
62
  ALERT_EMAIL_RECEIVER = "mcblackdevil12342@gmail.com"
63
  ENABLE_EMAIL_ALERTS = True
64
 
 
155
  except Exception as ve:
156
  print(f"Failed to attach video: {ve}")
157
 
158
+ # FIX: Using Port 465 (Implicit SSL) with explicit timeout to prevent hanging in strict environments
159
+ context = ssl.create_default_context()
160
+ with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context, timeout=15) as server:
161
+ server.login(ALERT_EMAIL_SENDER, ALERT_EMAIL_PASSWORD)
162
+ server.send_message(msg)
163
+
 
164
  print(f"📧 Dispatch Email Sent Successfully for Stream {stream_id}", flush=True)
165
  except Exception as e:
166
  print(f"📧 Email Failed to Send: {str(e)}", flush=True)
 
230
  @app.route('/init_stream', methods=['POST'])
231
  def init_stream():
232
  url = request.json.get('url')
233
+
234
+ # --- YouTube Live Stream Resolution ---
235
+ if 'youtube.com' in url or 'youtu.be' in url:
236
+ try:
237
+ ydl_opts = {'format': 'best', 'quiet': True, 'noplaylist': True}
238
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
239
+ info = ydl.extract_info(url, download=False)
240
+ # Overwrite the YouTube link with the raw hidden media stream link
241
+ url = info.get('url', url)
242
+ except Exception as e:
243
+ print(f"yt-dlp extraction failed: {e}", flush=True)
244
+
245
  loc, wx = get_geo_info(url)
246
  v_time = datetime.datetime.now().strftime("%H:%M:%S")
247
  stream_id = f"live_{uuid.uuid4().hex}"