Restore project to its state before this session's changes (revert 816e671, e472ead, 621e0cf, d8046a9)
Browse files- Dockerfile +1 -1
- app.py +0 -62
- youtube_manager.py +1 -3
Dockerfile
CHANGED
|
@@ -41,7 +41,7 @@ ENV TZ=Asia/Baghdad \
|
|
| 41 |
YOUTUBE_OBS_HOLD_SECONDS=900 \
|
| 42 |
YOUTUBE_SOURCE_RETRY=15 \
|
| 43 |
YOUTUBE_FORCE_GAP=5 \
|
| 44 |
-
YOUTUBE_END_GRACE=
|
| 45 |
YOUTUBE_REUSE_IDLE=90 \
|
| 46 |
YOUTUBE_STABLE_SECONDS=25 \
|
| 47 |
YOUTUBE_FFMPEG_LOGLEVEL=info \
|
|
|
|
| 41 |
YOUTUBE_OBS_HOLD_SECONDS=900 \
|
| 42 |
YOUTUBE_SOURCE_RETRY=15 \
|
| 43 |
YOUTUBE_FORCE_GAP=5 \
|
| 44 |
+
YOUTUBE_END_GRACE=40 \
|
| 45 |
YOUTUBE_REUSE_IDLE=90 \
|
| 46 |
YOUTUBE_STABLE_SECONDS=25 \
|
| 47 |
YOUTUBE_FFMPEG_LOGLEVEL=info \
|
app.py
CHANGED
|
@@ -280,8 +280,6 @@ def get_json(url,params,user=None):
|
|
| 280 |
_observation_cache={}
|
| 281 |
_observation_locks={}
|
| 282 |
_observation_guard=threading.Lock()
|
| 283 |
-
_uid_cache={} # user -> numeric TikTok id (من user/room)
|
| 284 |
-
_guest_logged={} # user -> غرفة المذيع المضيف التي سُجّل الدخول إليها
|
| 285 |
|
| 286 |
def _as_dict(x):
|
| 287 |
return x if isinstance(x, dict) else {}
|
|
@@ -297,68 +295,9 @@ def observe_session(user,force=False):
|
|
| 297 |
cached=_observation_cache.get(user)
|
| 298 |
if cached and not force and time.monotonic()-cached[0]<15:return cached[1]
|
| 299 |
result=_observe_session(user)
|
| 300 |
-
if result.get('status')!='live':
|
| 301 |
-
# الحساب قد يكون ضيفًا داخل بث مذيع آخر: غرفته الخاصة تبقى «منتهية» بينما البث الحي في غرفة الضيوف
|
| 302 |
-
try:
|
| 303 |
-
guest=_guest_observation(user)
|
| 304 |
-
except Exception:
|
| 305 |
-
guest=None
|
| 306 |
-
if guest:result=guest
|
| 307 |
_observation_cache[user]=(time.monotonic(),result)
|
| 308 |
return result
|
| 309 |
|
| 310 |
-
def _guest_hosts_map():
|
| 311 |
-
"""GUEST_HOSTS='guest:host,guest2:host2' (Space Variable). Explicit pairing for a guest whose
|
| 312 |
-
co-host session TikTok's public endpoints do not expose."""
|
| 313 |
-
out={}
|
| 314 |
-
for part in (os.getenv('GUEST_HOSTS') or '').split(','):
|
| 315 |
-
if ':' in part:
|
| 316 |
-
g,h=part.split(':',1)
|
| 317 |
-
if g.strip() and h.strip():out[g.strip().lstrip('@').lower()]=h.strip().lstrip('@').lower()
|
| 318 |
-
return out
|
| 319 |
-
|
| 320 |
-
def _guest_observation(user):
|
| 321 |
-
"""Account is not live in its own room. (1) Explicit GUEST_HOSTS pairing: if the paired host
|
| 322 |
-
is live, follow that room. (2) Otherwise check whether TikTok lists the account in the
|
| 323 |
-
linked users of another monitored live host."""
|
| 324 |
-
forced=_guest_hosts_map().get(str(user).lower())
|
| 325 |
-
if forced and forced!=str(user).lower():
|
| 326 |
-
try:
|
| 327 |
-
hobs=_observe_session(forced)
|
| 328 |
-
except Exception:
|
| 329 |
-
hobs=None
|
| 330 |
-
if hobs and hobs.get('status')=='live' and hobs.get('sources'):
|
| 331 |
-
if _guest_logged.get(user)!=hobs.get('room_id'):
|
| 332 |
-
_guest_logged[user]=hobs.get('room_id')
|
| 333 |
-
log(user,'[GUEST] @%s مقترن بالمذيع @%s (GUEST_HOSTS)؛ نرصد غرفة المضيف'%(user,forced))
|
| 334 |
-
return {'status':'live','room_id':str(hobs.get('room_id') or ''),'sources':hobs.get('sources') or [],
|
| 335 |
-
'nickname':user,'live_title':str(hobs.get('live_title') or ''),'guest_of':forced}
|
| 336 |
-
uid=str(_uid_cache.get(user) or '')
|
| 337 |
-
if not uid.isdigit():return None
|
| 338 |
-
for other in enabled_accounts():
|
| 339 |
-
if other==user:continue
|
| 340 |
-
cached=_observation_cache.get(other)
|
| 341 |
-
if not cached or (cached[1] or {}).get('status')!='live':continue
|
| 342 |
-
host_room=str((cached[1] or {}).get('room_id') or '')
|
| 343 |
-
if not host_room.isdigit() or host_room=='0':continue
|
| 344 |
-
j=_as_dict(get_json('https://webcast.tiktok.com/webcast/room/info/',{'aid':1988,'room_id':host_room},other))
|
| 345 |
-
info=_as_dict(j.get('data'))
|
| 346 |
-
if str(info.get('status'))!='2':continue
|
| 347 |
-
if str(_as_dict(info.get('owner')).get('id_str') or info.get('owner_user_id') or '')==uid:continue
|
| 348 |
-
# الضيوف المرتبطون داخل الغرفة يظهرون في link_mic.linked_user_list (وقد يظهرون في linker_map أيضًا)
|
| 349 |
-
linked=_as_dict(info.get('link_mic')).get('linked_user_list') or []
|
| 350 |
-
linkers=[info.get('linker_map') or {}, linked]
|
| 351 |
-
if not any(linkers) or uid not in json.dumps(linkers,ensure_ascii=False):continue
|
| 352 |
-
sources=rank_sources(_as_dict(info.get('stream_url')))
|
| 353 |
-
if not sources:continue
|
| 354 |
-
if _guest_logged.get(user)!=host_room:
|
| 355 |
-
_guest_logged[user]=host_room
|
| 356 |
-
log(user,'[GUEST] @%s داخل بث @%s كضيف؛ نرصد غرفة المذيع المضيف'%(user,other))
|
| 357 |
-
return {'status':'live','room_id':host_room,'sources':sources,'nickname':user,
|
| 358 |
-
'live_title':str(info.get('title') or '').strip(),'guest_of':other}
|
| 359 |
-
_guest_logged.pop(user,None)
|
| 360 |
-
return None
|
| 361 |
-
|
| 362 |
def _observe_session(user):
|
| 363 |
"""TikTok room lookup. Null liveRoom/user/data must be Offline, not a crash.
|
| 364 |
|
|
@@ -369,7 +308,6 @@ def _observe_session(user):
|
|
| 369 |
j=_as_dict(get_json('https://www.tiktok.com/api-live/user/room',{'aid':1988,'uniqueId':user,'sourceType':54,'staleTime':0},user))
|
| 370 |
d=_as_dict(j.get('data')); live=_as_dict(d.get('liveRoom')); person=_as_dict(d.get('user'))
|
| 371 |
status=live.get('status')
|
| 372 |
-
if str(person.get('id') or '').isdigit():_uid_cache[user]=str(person.get('id'))
|
| 373 |
room=str(person.get('roomId') or person.get('room_id') or live.get('roomId') or live.get('room_id') or '')
|
| 374 |
nickname=str(person.get('nickname') or live.get('nickname') or '').strip()
|
| 375 |
live_title=str(live.get('title') or '').strip()
|
|
|
|
| 280 |
_observation_cache={}
|
| 281 |
_observation_locks={}
|
| 282 |
_observation_guard=threading.Lock()
|
|
|
|
|
|
|
| 283 |
|
| 284 |
def _as_dict(x):
|
| 285 |
return x if isinstance(x, dict) else {}
|
|
|
|
| 295 |
cached=_observation_cache.get(user)
|
| 296 |
if cached and not force and time.monotonic()-cached[0]<15:return cached[1]
|
| 297 |
result=_observe_session(user)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
_observation_cache[user]=(time.monotonic(),result)
|
| 299 |
return result
|
| 300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
def _observe_session(user):
|
| 302 |
"""TikTok room lookup. Null liveRoom/user/data must be Offline, not a crash.
|
| 303 |
|
|
|
|
| 308 |
j=_as_dict(get_json('https://www.tiktok.com/api-live/user/room',{'aid':1988,'uniqueId':user,'sourceType':54,'staleTime':0},user))
|
| 309 |
d=_as_dict(j.get('data')); live=_as_dict(d.get('liveRoom')); person=_as_dict(d.get('user'))
|
| 310 |
status=live.get('status')
|
|
|
|
| 311 |
room=str(person.get('roomId') or person.get('room_id') or live.get('roomId') or live.get('room_id') or '')
|
| 312 |
nickname=str(person.get('nickname') or live.get('nickname') or '').strip()
|
| 313 |
live_title=str(live.get('title') or '').strip()
|
youtube_manager.py
CHANGED
|
@@ -33,9 +33,7 @@ class ManagedYouTube:
|
|
| 33 |
self.destinations={} # username -> rtmps url (in-memory only, never persisted)
|
| 34 |
self._ingest_routes={};self._ingest_preferred={}
|
| 35 |
self.scan=max(8,int(os.getenv('YOUTUBE_SCAN_SECONDS') or os.getenv('CHECK_INTERVAL','20')))
|
| 36 |
-
|
| 37 |
-
# 22:29→22:30 أنهى الحدث بعد 40 ث بينما البث لم ينتهِ). الإنهاء الحقيقي يبقى مؤكدًا بعد هذه المهلة.
|
| 38 |
-
self.end_grace=max(15,int(os.getenv('YOUTUBE_END_GRACE','180')))
|
| 39 |
self._unstable={}
|
| 40 |
self._live_confirm={}
|
| 41 |
self._rendition_pin={}
|
|
|
|
| 33 |
self.destinations={} # username -> rtmps url (in-memory only, never persisted)
|
| 34 |
self._ingest_routes={};self._ingest_preferred={}
|
| 35 |
self.scan=max(8,int(os.getenv('YOUTUBE_SCAN_SECONDS') or os.getenv('CHECK_INTERVAL','20')))
|
| 36 |
+
self.end_grace=max(15,int(os.getenv('YOUTUBE_END_GRACE','40')))
|
|
|
|
|
|
|
| 37 |
self._unstable={}
|
| 38 |
self._live_confirm={}
|
| 39 |
self._rendition_pin={}
|