Add GUEST_HOSTS explicit guest-to-host pairing for co-host sessions not exposed by public endpoints
Browse files
app.py
CHANGED
|
@@ -307,9 +307,32 @@ def observe_session(user,force=False):
|
|
| 307 |
_observation_cache[user]=(time.monotonic(),result)
|
| 308 |
return result
|
| 309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
def _guest_observation(user):
|
| 311 |
-
"""Account is not live in its own room.
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
uid=str(_uid_cache.get(user) or '')
|
| 314 |
if not uid.isdigit():return None
|
| 315 |
for other in enabled_accounts():
|
|
|
|
| 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():
|