Spaces:
Running
Running
Keep FFmpeg pushing during liveStarting; do not finish a bound event on soft 403 rateLimit
Browse files- youtube_manager.py +13 -4
youtube_manager.py
CHANGED
|
@@ -322,13 +322,20 @@ class ManagedYouTube:
|
|
| 322 |
صلاحية/حساب = قفل طويل. سقف متزامن أو خطأ عابر = قفل قصير يُفرَّغ عندما ينتهي
|
| 323 |
حدث شقيق حتى يُفتح copy للمذيع المنتظر دون ترميز.
|
| 324 |
"""
|
|
|
|
|
|
|
| 325 |
_keys=[k for k,ev in self.journal.read()['events'].items() if ev.get('username')==user and not ev.get('closing')]
|
| 326 |
for _k in _keys:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
self.event_note(_k,'يوتيوب رفض إنشاء/تحديث الحدث (%s): تحقّق من صلاحية البث المباشر وسقف الأحداث في حسابك' % reason)
|
| 328 |
try:self.finish_event(_k)
|
| 329 |
except Exception:self.archive_event(_k,'local_cancelled_'+str(reason))
|
| 330 |
_rid=str(room_id or '')
|
| 331 |
-
hard=self._403_is_hard(reason)
|
| 332 |
limit=float(os.getenv('YOUTUBE_403_BLOCK_SECONDS') or (600 if hard else 90))
|
| 333 |
if _rid:
|
| 334 |
self._blocked403[user+':'+_rid]={'t':time.monotonic(),'reason':str(reason or ''),'hard':hard}
|
|
@@ -1716,11 +1723,13 @@ class ManagedYouTube:
|
|
| 1716 |
|
| 1717 |
if life in ('complete','revoked'):
|
| 1718 |
self.event_update(key,closing=True);self.finish_event(key);return
|
| 1719 |
-
if life
|
| 1720 |
-
if not ev['was_live']:
|
| 1721 |
self.event_update(key,was_live=True,phase='live')
|
| 1722 |
self.log(user,'[LIVE] يوتيوب أكد أن الحدث مباشر: '+ev['broadcast_id'])
|
| 1723 |
-
#
|
|
|
|
|
|
|
| 1724 |
self.start_sender(key)
|
| 1725 |
self.stream_health(key,user,ev)
|
| 1726 |
ev=self.journal.read()['events'].get(key) or ev
|
|
|
|
| 322 |
صلاحية/حساب = قفل طويل. سقف متزامن أو خطأ عابر = قفل قصير يُفرَّغ عندما ينتهي
|
| 323 |
حدث شقيق حتى يُفتح copy للمذيع المنتظر دون ترميز.
|
| 324 |
"""
|
| 325 |
+
hard=self._403_is_hard(reason)
|
| 326 |
+
keep=('ready','testing','live','liveStarting')
|
| 327 |
_keys=[k for k,ev in self.journal.read()['events'].items() if ev.get('username')==user and not ev.get('closing')]
|
| 328 |
for _k in _keys:
|
| 329 |
+
ev=self.journal.read()['events'].get(_k) or {}
|
| 330 |
+
# Soft 403 (quota/rateLimit) must not tear down a bound event that already
|
| 331 |
+
# needs FFmpeg. Finish only planned/unbound shells that cannot ingest.
|
| 332 |
+
if (not hard) and ev.get('bound') and ev.get('broadcast_id') and str(ev.get('youtube_status') or '') in keep:
|
| 333 |
+
self.log(user,'[MONITOR] 403/%s على إنشاء جديد؛ نبقي الحدث القائم %s والحالة %s'%(reason, ev.get('broadcast_id'), ev.get('youtube_status')))
|
| 334 |
+
continue
|
| 335 |
self.event_note(_k,'يوتيوب رفض إنشاء/تحديث الحدث (%s): تحقّق من صلاحية البث المباشر وسقف الأحداث في حسابك' % reason)
|
| 336 |
try:self.finish_event(_k)
|
| 337 |
except Exception:self.archive_event(_k,'local_cancelled_'+str(reason))
|
| 338 |
_rid=str(room_id or '')
|
|
|
|
| 339 |
limit=float(os.getenv('YOUTUBE_403_BLOCK_SECONDS') or (600 if hard else 90))
|
| 340 |
if _rid:
|
| 341 |
self._blocked403[user+':'+_rid]={'t':time.monotonic(),'reason':str(reason or ''),'hard':hard}
|
|
|
|
| 1723 |
|
| 1724 |
if life in ('complete','revoked'):
|
| 1725 |
self.event_update(key,closing=True);self.finish_event(key);return
|
| 1726 |
+
if life in ('live','liveStarting'):
|
| 1727 |
+
if life=='live' and not ev['was_live']:
|
| 1728 |
self.event_update(key,was_live=True,phase='live')
|
| 1729 |
self.log(user,'[LIVE] يوتيوب أكد أن الحدث مباشر: '+ev['broadcast_id'])
|
| 1730 |
+
# liveStarting = transition already requested. Stopping FFmpeg here is the
|
| 1731 |
+
# spinner: YouTube waits for ingest, we refuse to send. Measured On @a3dam_111
|
| 1732 |
+
# 2026-09-28: youtube_status=liveStarting, relay_pid=None, events=1.
|
| 1733 |
self.start_sender(key)
|
| 1734 |
self.stream_health(key,user,ev)
|
| 1735 |
ev=self.journal.read()['events'].get(key) or ev
|