# -*- coding: utf-8 -*- """Diagnose dylive Shorts: why daily_min 9 not met (esp YPP).""" from __future__ import annotations import json import sys import time import http.cookiejar import urllib.request from datetime import datetime, timezone, timedelta import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") BJ = timezone(timedelta(hours=8)) def session(base: str): cj = http.cookiejar.CookieJar() op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) data = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode() req = urllib.request.Request( base + "/api/auth/login", data=data, method="POST", headers={"Content-Type": "application/json"} ) op.open(req, timeout=30) return op def call(op, base, path, method="GET", body=None, timeout=60): data = None if body is None else json.dumps(body).encode() req = urllib.request.Request( base + path, data=data, method=method, headers={"Content-Type": "application/json"} if body is not None else {}, ) with op.open(req, timeout=timeout) as r: return json.loads(r.read().decode()) base = "https://dylive.nomadro.com" op = session(base) now = time.time() print("now_bj", datetime.now(BJ).isoformat()) st = call(op, base, "/api/shorts/status") board = st.get("board") or {} print( "enabled=", st.get("enabled"), "busy=", st.get("busy"), "active_up=", st.get("active_uploads"), "active_rec=", st.get("active_records"), "gap=", st.get("quota_gap") or board.get("total_gap"), "min_unmet=", board.get("min_unmet"), "ch_gap=", st.get("channel_min_gap_sec"), "yt_blocked=", st.get("upload_quota_blocked"), "yt_blocked_profiles=", st.get("upload_quota_blocked_profiles"), "yt_hint=", st.get("yt_quota_exhausted_hint"), "yt_by_profile=", st.get("yt_quota_by_profile"), "day_progress=", board.get("day_progress"), "seconds_left=", board.get("seconds_left"), ) chans = board.get("channels") or [] print("\n=== channels under min ===") for c in chans: if not c.get("enabled"): continue if c.get("min_met"): continue print( f" {c.get('name')} ypp={c.get('ypp_ok')} used={c.get('used')}/{c.get('daily_min')} " f"up={c.get('uploaded')} sch={c.get('scheduled')} pend={c.get('pending')} " f"behind={c.get('behind_pace')} oauth={c.get('oauth_profile_id')}" ) # jobs today by status jobs = call(op, base, "/api/shorts/jobs?limit=200") items = jobs.get("jobs") or [] from collections import Counter ctr = Counter(str(j.get("status") or "") for j in items if str(j.get("push_date") or "") == str(board.get("push_date") or "")) print("\n=== job status today ===", dict(ctr)) # scheduled upload_at distribution sched = [j for j in items if str(j.get("status")) in {"scheduled", "recorded"} and str(j.get("push_date")) == str(board.get("push_date") or "")] due = [j for j in sched if float(j.get("upload_at") or 0) <= now] future = [j for j in sched if float(j.get("upload_at") or 0) > now] print("scheduled/recorded=", len(sched), "due_now=", len(due), "future=", len(future)) if future: waits = sorted(float(j.get("upload_at") or 0) - now for j in future)[:10] print("next_waits_sec", [int(w) for w in waits]) # failed today failed = [j for j in items if str(j.get("status")) == "failed"] print("failed_sample=", len(failed)) for j in failed[:8]: print(" FAIL", j.get("channel_pk"), (j.get("error") or "")[:120]) # trigger fill fill = call(op, base, "/api/shorts/fill-quota", method="POST", body={}) print("\nfill just=", fill.get("just_quota_filled"), "gap_after=", fill.get("quota_gap")) # SSH deep: live rooms, claim blockers, yt quota c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False) _, o, e = c.exec_command( r"""python3 <<'PY' import sqlite3, time, json from pathlib import Path p=Path('/opt/douyinWEB/backend/data/monitor.db') conn=sqlite3.connect(str(p)); conn.row_factory=sqlite3.Row # live rooms live=conn.execute("SELECT COUNT(*) c FROM rooms WHERE enabled=1 AND last_status='live' AND room_id NOT LIKE 'yt:%'").fetchone()['c'] print('live_douyin', live) # today import datetime BJ=datetime.timezone(datetime.timedelta(hours=8)) day=datetime.datetime.now(BJ).strftime('%Y-%m-%d') print('day', day) rows=conn.execute('''SELECT status, COUNT(*) c FROM shorts_jobs WHERE push_date=? GROUP BY status''',(day,)).fetchall() print('jobs', {r['status']:r['c'] for r in rows}) # due scheduled now=time.time() due=conn.execute('''SELECT COUNT(*) c FROM shorts_jobs WHERE push_date=? AND status IN ('scheduled','recorded') AND upload_at>0 AND upload_at<=?''',(day,now)).fetchone()['c'] fut=conn.execute('''SELECT COUNT(*) c FROM shorts_jobs WHERE push_date=? AND status IN ('scheduled','recorded') AND upload_at>?''',(day,now)).fetchone()['c'] print('due', due, 'future', fut) # per channel used vs min for ypp-ish (join) chs=conn.execute('SELECT id,name,daily_min,daily_max,oauth_profile_id,enabled FROM shorts_channels WHERE enabled=1').fetchall() for ch in chs: used=conn.execute('''SELECT COUNT(*) c FROM shorts_jobs WHERE channel_pk=? AND push_date=? AND status IN ('pending','recording','recorded','scheduled','uploading','uploaded','done')''',(ch['id'],day)).fetchone()['c'] up=conn.execute('''SELECT COUNT(*) c FROM shorts_jobs WHERE channel_pk=? AND push_date=? AND status IN ('uploaded','done')''',(ch['id'],day)).fetchone()['c'] sch=conn.execute('''SELECT COUNT(*) c FROM shorts_jobs WHERE channel_pk=? AND push_date=? AND status IN ('scheduled','recorded')''',(ch['id'],day)).fetchone()['c'] if used < int(ch['daily_min'] or 9): print(f"UNDER {ch['name']} prof={ch['oauth_profile_id']} used={used} up={up} sch={sch} min={ch['daily_min']}") # settings gaps for k in ('shorts_enabled','shorts_channel_min_gap_sec','shorts_upload_min_gap_sec','shorts_max_concurrent','shorts_upload_max_concurrent'): r=conn.execute('SELECT value FROM kv_settings WHERE key=?',(k,)).fetchone() print('kv', k, r['value'] if r else None) # recent errors errs=conn.execute('''SELECT channel_pk,error,updated_at FROM shorts_jobs WHERE push_date=? AND error!='' ORDER BY updated_at DESC LIMIT 8''',(day,)).fetchall() for r in errs: print('err', r['channel_pk'], (r['error'] or '')[:100]) conn.close() PY""", timeout=60, ) print("\n=== ssh ===") print((o.read() + e.read()).decode("utf-8", "replace")) c.close() print("done")