Reoo88 commited on
Commit
7f8a3cc
ยท
1 Parent(s): 250bffb

On: same copy engine as Prayer-Time-Bot.

Browse files

Restore v2.12 relay (copy H264; stall 12). Keep tick unlocked.
matchgop only after out>=20 like Prayer. Not default 720.

Files changed (2) hide show
  1. relay.py +23 -36
  2. youtube_manager.py +1 -6
relay.py CHANGED
@@ -565,9 +565,7 @@ class Sender:
565
  except queue.Empty:
566
  silent = time.monotonic() - sess['last']
567
  if self._stall_seconds() and silent > self._stall_seconds():
568
- # End this HTTP pump only. Killing FFmpeg here is the viewer freeze
569
- # (YouTube holds the last frame, then a new ingest). Watchdog splices.
570
- sess['source_gap'] = True
571
  return
572
  continue
573
  pending = None
@@ -588,8 +586,6 @@ class Sender:
588
  sess['timeouts'] = 0
589
  if not chunk:
590
  continue
591
- sess['source_gap'] = False
592
- sess['reattach_fails'] = 0
593
  sess['last'] = time.monotonic()
594
  with self.lock:
595
  self.data['source_bytes'] += len(chunk)
@@ -628,6 +624,8 @@ class Sender:
628
  """
629
  if not refresh or p is None or p.stdin is None or p.poll() is not None:
630
  return None
 
 
631
  sess['swapping'] = True
632
  sess['swap_source'] = True
633
  sess['swap_started'] = time.monotonic()
@@ -887,29 +885,22 @@ class Sender:
887
  self.sticky_mode=None
888
  self.sticky_since=0.0
889
  self._recovering_copy=False
890
- stalled_src = bool(
891
- (stall_limit and now - _fresh > stall_limit and (not sess.get('swapping') or swap_for > stall_limit))
892
- or sess.get('source_gap') or sess.get('ended')
893
- or (pump is not None and not pump.is_alive() and response is not None and not stop.is_set()
894
- and not sess.get('force_stop') and p.poll() is None)
895
- )
896
- if stalled_src:
897
- last_try = float(sess.get('reattach_try') or 0)
898
- if now - last_try >= max(1.0, stall_limit or 12.0):
899
- sess['reattach_try'] = now
900
- attached = self._try_reattach(user, p, bridge, sess, stop, refresh,
901
- read_timeout, retries, response, pump)
902
- if attached:
903
- response, pump = attached
904
- sess['source_gap'] = False
905
- sess['ended'] = False
906
- sess['error'] = ''
907
- sess['reattach_fails'] = 0
908
- continue
909
- sess['reattach_fails'] = int(sess.get('reattach_fails') or 0) + 1
910
- if now - float(sess.get('hold_log_at') or 0) > 60:
911
- self.log(user, '[RELAY] ุชูŠูƒ ุชูˆูƒ ุตุงู…ุช ู…ู†ุฐ %.0f ุซุ› ู†ูุจู‚ูŠ ู†ุณุฎ FFmpeg ุนู„ู‰ ูŠูˆุชูŠูˆุจ ุจู„ุง ู‚ุชู„'% (now - _fresh))
912
- sess['hold_log_at'] = now
913
  rc = p.poll()
914
  if rc is not None:
915
  if sess['format_changed']:
@@ -926,17 +917,13 @@ class Sender:
926
  self.log(user, 'FFmpeg ุฎุฑุฌ ุจุฑู…ุฒ %s%s%s%s' % (
927
  rc, ' โ€” ' + 'ุ› '.join(diagnostics[-3:]) if diagnostics else 'ุ› ู„ู… ูŠุธู‡ุฑ ุณุจุจ ู…ุตู†ู‘ู', blame, tail))
928
  break
929
- if now - progress['last'] > progress_limit and not stalled_src:
930
  raise SourceStalled('ู„ู… ูŠุชู‚ุฏู‘ู… FFmpeg ู…ู†ุฐ %.0f ุซ' % (now - progress['last']))
931
  if sess['ended'] and not sess['error']:
932
- # HTTP closed: splice a new TikTok FLV into the same FFmpeg (copy).
933
- sess['ended'] = False
934
- sess['source_gap'] = True
935
  if sess['error']:
936
- # TikTok read fault is not a YouTube ingest fault โ€” hold copy, retry source.
937
- self.log(user, '[RELAY] ู…ุตุฏุฑ ุชูŠูƒ ุชูˆูƒ: %s โ€” ู†ูุจู‚ูŠ ุฌู„ุณุฉ ูŠูˆุชูŠูˆุจ' % str(sess['error'])[:120])
938
- sess['error'] = ''
939
- sess['source_gap'] = True
940
  if response is not None and now >= next_report:
941
  # ุจู…ุนุฏู„ ู…ุถุจูˆุท: ู„ุง logging ู„ูƒู„ ุจุงูŠุช (ูƒุงู† ุณูŠู…ู„ุฃ ุงู„ุณุฌู„ ููŠ ุฏู‚ุงุฆู‚).
942
  next_report = now + max(15, int(os.getenv('YOUTUBE_WATCHDOG_REPORT_SECONDS', '60')))
 
565
  except queue.Empty:
566
  silent = time.monotonic() - sess['last']
567
  if self._stall_seconds() and silent > self._stall_seconds():
568
+ sess['error'] = 'ุตู…ุช ู…ู† ุชูŠูƒ ุชูˆูƒ (%.0f ุซ ุจู„ุง ุจุงูŠุช)' % silent
 
 
569
  return
570
  continue
571
  pending = None
 
586
  sess['timeouts'] = 0
587
  if not chunk:
588
  continue
 
 
589
  sess['last'] = time.monotonic()
590
  with self.lock:
591
  self.data['source_bytes'] += len(chunk)
 
624
  """
625
  if not refresh or p is None or p.stdin is None or p.poll() is not None:
626
  return None
627
+ if int(sess.get('reattaches') or 0) >= 8:
628
+ return None
629
  sess['swapping'] = True
630
  sess['swap_source'] = True
631
  sess['swap_started'] = time.monotonic()
 
885
  self.sticky_mode=None
886
  self.sticky_since=0.0
887
  self._recovering_copy=False
888
+ if stall_limit and now - _fresh > stall_limit and (not sess.get('swapping') or swap_for > stall_limit):
889
+ attached = self._try_reattach(user, p, bridge, sess, stop, refresh,
890
+ read_timeout, retries, response, pump)
891
+ if attached:
892
+ response, pump = attached
893
+ continue
894
+ # ู†ูููŠู‚ ุงู„ุฎูŠุท ุฃูˆู„ู‹ุง (ู‚ุฏ ูŠูƒูˆู† ู…ุญุจูˆุณู‹ุง ููŠ write ุนู„ู‰ ุฃู†ุจูˆุจ ู…ู…ุชู„ุฆ)ุŒ ุซู… ู†ุฑูุน:
895
+ # ุฅุบู„ุงู‚ stdin ูŠุฌุนู„ FFmpeg ูŠุฑู‰ EOF ูˆูŠุชูˆู‚ู ุจู„ุทู ุจุฏู„ SIGKILL.
896
+ sess['force_stop'] = True
897
+ if p.stdin:
898
+ try:
899
+ p.stdin.close()
900
+ except (OSError, ValueError):
901
+ pass
902
+ raise SourceStalled('ุงู†ู‚ุทุน ุชุฏูู‚ ุงู„ู…ุตุฏุฑ ู…ู†ุฐ %.0f ุซ (FFmpeg ู…ุง ุฒุงู„ ุญูŠู‹ุงุŒ '
903
+ 'ูˆูŠูˆุชูŠูˆุจ ูŠุจู‚ู‰ ุนู„ู‰ ุขุฎุฑ ุซุงู†ูŠุฉ ูˆุตู„ุชู‡)' % (now - _fresh))
 
 
 
 
 
 
 
904
  rc = p.poll()
905
  if rc is not None:
906
  if sess['format_changed']:
 
917
  self.log(user, 'FFmpeg ุฎุฑุฌ ุจุฑู…ุฒ %s%s%s%s' % (
918
  rc, ' โ€” ' + 'ุ› '.join(diagnostics[-3:]) if diagnostics else 'ุ› ู„ู… ูŠุธู‡ุฑ ุณุจุจ ู…ุตู†ู‘ู', blame, tail))
919
  break
920
+ if now - progress['last'] > progress_limit:
921
  raise SourceStalled('ู„ู… ูŠุชู‚ุฏู‘ู… FFmpeg ู…ู†ุฐ %.0f ุซ' % (now - progress['last']))
922
  if sess['ended'] and not sess['error']:
923
+ self.log(user, '[MONITOR] ุฃุบู„ู‚ ุชูŠูƒ ุชูˆูƒ ุงู„ุงุณุชุฌุงุจุฉุ› ุงู„ุฌู„ุณุฉ ุชูุนุงุฏ ู…ู† ุฌุฏูŠุฏ')
924
+ break
 
925
  if sess['error']:
926
+ raise SourceStalled(sess['error'])
 
 
 
927
  if response is not None and now >= next_report:
928
  # ุจู…ุนุฏู„ ู…ุถุจูˆุท: ู„ุง logging ู„ูƒู„ ุจุงูŠุช (ูƒุงู† ุณูŠู…ู„ุฃ ุงู„ุณุฌู„ ููŠ ุฏู‚ุงุฆู‚).
929
  next_report = now + max(15, int(os.getenv('YOUTUBE_WATCHDOG_REPORT_SECONDS', '60')))
youtube_manager.py CHANGED
@@ -1664,7 +1664,6 @@ class ManagedYouTube:
1664
  issues.append('%s [%s] %s'%(i.get('type',''),sev,i.get('reason','')))
1665
  text=' | '.join(issues)
1666
  prev=ev.get('last_issues')
1667
- prev_health=str(ev.get('youtube_health') or '')
1668
  status=str(health.get('status') or '')
1669
  self.event_update(key,youtube_health=status,youtube_issues=text,last_issues=text)
1670
  if text and text!=prev:
@@ -1680,11 +1679,7 @@ class ManagedYouTube:
1680
  snap=sender.snapshot() or {}
1681
  out=float(snap.get('output_seconds') or 0)
1682
  mode=(snap.get('send_mode') or sender.send_mode() or '')
1683
- copy_like=mode in ('','auto','copy') and not sender.sticky_mode
1684
- # out>=20 skips the first noData of a fresh ingest. It also blocked the
1685
- # measured failure: copy stall-restarts with out=0 after YouTube had been good.
1686
- ready=out>=20 or (nodata and prev_health.lower()=='good')
1687
- if copy_like and ready:
1688
  sender.request_sticky('matchgop', user, 'YouTube %s (out=%.0fs copy not ingesting for viewers)'%(status or text[:40], out))
1689
  def run_manager(self):
1690
  checked=False
 
1664
  issues.append('%s [%s] %s'%(i.get('type',''),sev,i.get('reason','')))
1665
  text=' | '.join(issues)
1666
  prev=ev.get('last_issues')
 
1667
  status=str(health.get('status') or '')
1668
  self.event_update(key,youtube_health=status,youtube_issues=text,last_issues=text)
1669
  if text and text!=prev:
 
1679
  snap=sender.snapshot() or {}
1680
  out=float(snap.get('output_seconds') or 0)
1681
  mode=(snap.get('send_mode') or sender.send_mode() or '')
1682
+ if out>=20 and mode in ('','auto','copy') and not sender.sticky_mode:
 
 
 
 
1683
  sender.request_sticky('matchgop', user, 'YouTube %s (out=%.0fs copy not ingesting for viewers)'%(status or text[:40], out))
1684
  def run_manager(self):
1685
  checked=False