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>
150 lines
4.5 KiB
Python
150 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Upload one existing >3min clip to nomad vlog yt-long channel and verify YPP monetize."""
|
|
import sys
|
|
import paramiko
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
|
|
REMOTE = r"""
|
|
import asyncio
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import time
|
|
import uuid
|
|
|
|
from app import db, yt_long_db
|
|
from app.timeutil import push_date_from_ts
|
|
from app.yt_long_pipeline import yt_long_pipeline
|
|
|
|
CLIP_DIR = "/opt/douyinWEB/backend/data/clips/yt_long"
|
|
|
|
|
|
def ffprobe_sec(path: str) -> float:
|
|
try:
|
|
out = subprocess.check_output(
|
|
["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", path],
|
|
stderr=subprocess.DEVNULL,
|
|
timeout=30,
|
|
)
|
|
return float(out.decode().strip() or 0)
|
|
except Exception:
|
|
return 0.0
|
|
|
|
|
|
async def main():
|
|
day = push_date_from_ts(time.time())
|
|
target = None
|
|
for ch in yt_long_db.list_yt_long_channels(enabled=None):
|
|
if "nomad vlog" in str(ch.get("name") or "").lower():
|
|
target = ch
|
|
break
|
|
if not target:
|
|
print(json.dumps({"ok": False, "error": "nomad vlog not found"}))
|
|
return
|
|
|
|
ch_pk = str(target["id"])
|
|
# Temporarily allow one more upload today for this test
|
|
yt_long_db.update_yt_long_channel(ch_pk, daily_max=max(10, int(target.get("daily_max") or 4) + 2))
|
|
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": 15,
|
|
})
|
|
yt_long_db.reconcile_yt_long_upload_caps(db.get_settings_map())
|
|
|
|
clip_path = ""
|
|
clip_sec = 0.0
|
|
for name in sorted(os.listdir(CLIP_DIR), key=lambda n: -os.path.getsize(os.path.join(CLIP_DIR, n))):
|
|
if not name.endswith(".mp4"):
|
|
continue
|
|
p = os.path.join(CLIP_DIR, name)
|
|
if os.path.getsize(p) < 500_000:
|
|
continue
|
|
sec = ffprobe_sec(p)
|
|
if sec >= 180:
|
|
clip_path = p
|
|
clip_sec = sec
|
|
break
|
|
if not clip_path:
|
|
print(json.dumps({"ok": False, "error": "no clip >= 180s in yt_long clips dir"}))
|
|
return
|
|
|
|
jid = str(uuid.uuid4())
|
|
now = time.time()
|
|
with yt_long_db._lock:
|
|
conn = yt_long_db._connect()
|
|
try:
|
|
yt_long_db.ensure_yt_long_tables(conn)
|
|
conn.execute(
|
|
'''
|
|
INSERT INTO yt_long_jobs (
|
|
id, room_pk, room_id, source_url, anchor_name, stream_url,
|
|
channel_pk, push_date, status, clip_path, clip_seconds,
|
|
upload_at, created_at, updated_at, error
|
|
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|
''',
|
|
(
|
|
jid,
|
|
"",
|
|
f"test:ypp:{int(now)}",
|
|
"https://live.douyin.com/test",
|
|
"YPP获利测试",
|
|
"",
|
|
ch_pk,
|
|
day,
|
|
"scheduled",
|
|
clip_path,
|
|
clip_sec,
|
|
now - 1,
|
|
now,
|
|
now,
|
|
"",
|
|
),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
print("using_clip", clip_path, "sec", round(clip_sec, 1))
|
|
print("channel", target.get("name"), "ypp_ok", target.get("ypp_ok"))
|
|
|
|
job = yt_long_db.get_yt_long_job(jid) or {}
|
|
await yt_long_pipeline._do_upload(job)
|
|
|
|
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"),
|
|
"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"),
|
|
"ypp_ok": target.get("ypp_ok"),
|
|
}
|
|
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)
|
|
_, o, e = c.exec_command(
|
|
"cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'\n" + REMOTE + "\nPY",
|
|
timeout=600,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|