Reooiq commited on
Commit
588fea7
·
1 Parent(s): 03b4a43

QUICKTEST: temporary manual-key relay harness for live validation (to be removed)

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py CHANGED
@@ -507,6 +507,69 @@ def safe_file(name):
507
  def download(name:str):return FileResponse(safe_file(name),filename=name)
508
  @app.delete('/api/files/{name}')
509
  def delete(name:str):safe_file(name).unlink();return {'ok':True}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  @app.on_event('startup')
511
  def startup():
512
  load_tokens()
 
507
  def download(name:str):return FileResponse(safe_file(name),filename=name)
508
  @app.delete('/api/files/{name}')
509
  def delete(name:str):safe_file(name).unlink();return {'ok':True}
510
+ # ---- QUICKTEST — temporary live-validation harness (REMOVE after test) -----
511
+ # Pushes the top ranked TikTok source of one account to a MANUAL rtmps key with
512
+ # the exact same Sender/relay.py pipeline the manager uses (YOUTUBE_SEND_MODE
513
+ # applies), so a real stream key can be validated before OAuth automation.
514
+ QT={'running':False,'status':'','restarts':0,'started_at':None,'log':[],'sender':{}}
515
+ _qt_stop=threading.Event()
516
+ def qt_log(msg):
517
+ QT['log'].append('%s %s'%(time.strftime('%H:%M:%S'),msg))
518
+ QT['log']=QT['log'][-80:]
519
+ log('quicktest',msg)
520
+ class QuickTestBody(BaseModel):
521
+ user:str
522
+ rtmp:str
523
+ def qt_run(user,destination):
524
+ from relay import Sender
525
+ from flv_bridge import FormatChanged
526
+ sender=Sender(FFMPEG,qt_log,headers_for=tiktok_headers)
527
+ def reporter():
528
+ while not _qt_stop.is_set():
529
+ QT['sender']=sender.snapshot()
530
+ _qt_stop.wait(2)
531
+ threading.Thread(target=reporter,daemon=True).start()
532
+ while not _qt_stop.is_set():
533
+ try:
534
+ sources=extract(user)
535
+ if not sources:
536
+ QT['status']='المصدر غير مباشر حاليًا';_qt_stop.wait(15);continue
537
+ top=[s for s in sources if any(c in s['label'].lower() for c in ('h264','avc','h265','hevc'))][:1] or sources[:1]
538
+ QT['status']='الإرسال إلى يوتيوب'
539
+ sender.send(user,top[0],destination,_qt_stop)
540
+ if _qt_stop.is_set():break
541
+ QT['restarts']+=1
542
+ QT['status']='انقطع الإرسال؛ إعادة الاتصال'
543
+ _qt_stop.wait(2)
544
+ except FormatChanged:
545
+ QT['restarts']+=1
546
+ qt_log('تغيّرت أبعاد المصدر (بداية/نهاية جولة PK؟)؛ إعادة الاتصال بمقاس جديد')
547
+ except Exception as e:
548
+ QT['status']='تعثر: '+str(e)[:140]
549
+ _qt_stop.wait(5)
550
+ QT['running']=False
551
+ QT['status']='متوقف'
552
+ @app.post('/api/quicktest')
553
+ def quicktest_start(b:QuickTestBody):
554
+ if QT['running']:raise HTTPException(400,'التجربة تعمل بالفعل')
555
+ if not b.rtmp.startswith(('rtmp://','rtmps://')):raise HTTPException(400,'عنوان الإرسال غير صالح')
556
+ try:u=clean_user(b.user)
557
+ except ValueError as e:raise HTTPException(400,str(e))
558
+ _qt_stop.clear()
559
+ QT.update(running=True,status='بدء التجربة',restarts=0,started_at=time.time(),log=[],sender={})
560
+ threading.Thread(target=qt_run,args=(u,b.rtmp),daemon=True).start()
561
+ qt_log('بدأت التجربة السريعة نحو مفتاح يدوي للحساب '+u)
562
+ return {'ok':True}
563
+ @app.get('/api/quicktest')
564
+ def quicktest_state():
565
+ return QT
566
+ @app.post('/api/quicktest/stop')
567
+ def quicktest_stop():
568
+ _qt_stop.set()
569
+ qt_log('طلب إيقاف التجربة')
570
+ return {'ok':True}
571
+ # ---- end QUICKTEST ----------------------------------------------------------
572
+
573
  @app.on_event('startup')
574
  def startup():
575
  load_tokens()