Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
157 lines
4.9 KiB
Python
157 lines
4.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Create one yt-long job for nomad vlog, record >3min, upload, report YPP monetize."""
|
|
import asyncio
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
|
|
REMOTE_PY = r"""
|
|
import asyncio
|
|
import json
|
|
import sqlite3
|
|
import time
|
|
|
|
from app import db, yt_long_db
|
|
from app.timeutil import push_date_from_ts
|
|
from app.yt_long_pipeline import yt_long_pipeline, try_sample_live_rooms
|
|
from app.session_auth import create_session_token, get_admin_credentials, SESSION_COOKIE
|
|
import urllib.request
|
|
|
|
def api(method, path, body=None):
|
|
user, _ = get_admin_credentials()
|
|
token = create_session_token(user)
|
|
req = urllib.request.Request(
|
|
f"http://127.0.0.1:8014{path}",
|
|
data=(json.dumps(body).encode() if body is not None else None),
|
|
method=method,
|
|
headers={"Cookie": f"{SESSION_COOKIE}={token}", "Content-Type": "application/json"},
|
|
)
|
|
with urllib.request.urlopen(req, timeout=120) as resp:
|
|
return json.loads(resp.read().decode())
|
|
|
|
async def main():
|
|
day = push_date_from_ts(time.time())
|
|
target = None
|
|
for ch in yt_long_db.list_yt_long_channels(enabled=None):
|
|
name = str(ch.get("name") or "").strip().lower()
|
|
if "nomad vlog" in name:
|
|
target = ch
|
|
break
|
|
if not target:
|
|
print(json.dumps({"ok": False, "error": "nomad vlog channel not found"}, ensure_ascii=False))
|
|
return
|
|
|
|
ch_pk = str(target["id"])
|
|
print("channel", json.dumps({
|
|
"id": ch_pk,
|
|
"name": target.get("name"),
|
|
"ypp_ok": target.get("ypp_ok"),
|
|
"youtube_channel_id": target.get("youtube_channel_id"),
|
|
}, ensure_ascii=False))
|
|
|
|
db.update_settings_map({
|
|
"yt_long_enabled": True,
|
|
"yt_long_auto_upload": True,
|
|
"yt_long_monetize_when_ypp": True,
|
|
"yt_long_upload_min_gap_sec": 30,
|
|
})
|
|
|
|
rooms = db.list_live_douyin_rooms_for_shorts(limit=50)
|
|
room = None
|
|
for r in rooms:
|
|
if str(r.get("stream_url") or "").strip():
|
|
room = r
|
|
break
|
|
if not room:
|
|
print(json.dumps({"ok": False, "error": "no live douyin room with stream_url"}, ensure_ascii=False))
|
|
return
|
|
|
|
job = yt_long_db.create_yt_long_job(
|
|
room_pk=str(room.get("id") or ""),
|
|
room_id=str(room.get("room_id") or ""),
|
|
source_url=str(room.get("url") or ""),
|
|
anchor_name=str(room.get("last_anchor") or "live"),
|
|
stream_url=str(room.get("stream_url") or ""),
|
|
channel_pk=ch_pk,
|
|
push_date=day,
|
|
)
|
|
jid = str(job.get("id") or "")
|
|
print("created_job", jid, job.get("status"), room.get("room_id"), room.get("last_anchor"))
|
|
|
|
if not yt_long_pipeline.running:
|
|
await yt_long_pipeline.start()
|
|
else:
|
|
api("POST", "/api/yt-long/start")
|
|
|
|
n = await yt_long_pipeline.kick_pending_records([jid])
|
|
print("kick_recording", n)
|
|
|
|
deadline = time.time() + 900
|
|
last = {}
|
|
while time.time() < deadline:
|
|
j = yt_long_db.get_yt_long_job(jid) or {}
|
|
st = str(j.get("status") or "")
|
|
last = {
|
|
"status": st,
|
|
"clip_seconds": j.get("clip_seconds"),
|
|
"error": j.get("error"),
|
|
"youtube_url": j.get("youtube_url"),
|
|
"youtube_video_id": j.get("youtube_video_id"),
|
|
}
|
|
print("poll", json.dumps(last, ensure_ascii=False))
|
|
if st in ("scheduled", "recorded") and j.get("clip_path"):
|
|
# force immediate upload for test
|
|
yt_long_db.update_yt_long_job(jid, upload_at=time.time() - 1, status="scheduled", channel_pk=ch_pk)
|
|
if st == "uploaded":
|
|
break
|
|
if st == "failed":
|
|
break
|
|
await asyncio.sleep(20)
|
|
|
|
j = yt_long_db.get_yt_long_job(jid) or {}
|
|
out = {
|
|
"ok": str(j.get("status") or "") == "uploaded",
|
|
"job_id": jid,
|
|
"status": j.get("status"),
|
|
"channel": target.get("name"),
|
|
"ypp_ok": target.get("ypp_ok"),
|
|
"clip_seconds": j.get("clip_seconds"),
|
|
"youtube_url": j.get("youtube_url"),
|
|
"youtube_video_id": j.get("youtube_video_id"),
|
|
"monetize_note": j.get("error"),
|
|
"anchor": j.get("anchor_name"),
|
|
}
|
|
print("RESULT", json.dumps(out, ensure_ascii=False))
|
|
|
|
asyncio.run(main())
|
|
"""
|
|
|
|
def main() -> None:
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
def run(cmd: str, timeout: int = 960) -> str:
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
return out
|
|
|
|
print("[remote test start]")
|
|
out = run(
|
|
"cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'\n" + REMOTE_PY + "\nPY",
|
|
timeout=960,
|
|
)
|
|
print(out)
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|