douyinWEB/scripts/_diag_monetize_payloads.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
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>
2026-09-04 22:42:40 -05:00

115 lines
4.2 KiB
Python

# -*- coding: utf-8 -*-
"""Try each monetize payload on server and print per-attempt errors."""
from __future__ import annotations
import asyncio
import json
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = r"""
import asyncio, json
from app import db
from app.shorts_oauth import channel_oauth_creds
from app.shorts_upload import refresh_access_token
from app import yt_long_monetize as ym
async def main():
target = None
for ch in db.list_shorts_channels(enabled=None):
n = str(ch.get("name") or "").lower()
if "nomad vlog" in n:
target = ch
break
creds = channel_oauth_creds(target)
access = await refresh_access_token(
client_id=str(creds["client_id"]),
client_secret=str(creds["client_secret"]),
refresh_token=str(creds["refresh_token"]),
)
vid = "ch1MMlZMfU0"
ch_id = str(target.get("youtube_channel_id") or "")
base = {"encryptedVideoId": vid, "videoReadMask": {"title": True}}
cert_skipped = ym._self_cert_skipped()
ad_formats = {
"newHasOverlayAds": "ENABLED",
"newHasProductListingAds": "ENABLED",
"newHasSkippableVideoAds": "ENABLED",
"newHasNonSkippableVideoAds": "ENABLED",
}
payloads = [
("exact-adasq", {
"encryptedVideoId": vid,
"videoReadMask": {},
"monetizationSettings": {"newMonetizeWithAds": True},
"selfCertification": cert_skipped,
"context": {
"client": {
"clientName": 62,
"clientVersion": "1.20210104.03.01",
"hl": "en-GB",
"gl": "PL",
"utcOffsetMinutes": 60,
},
"request": {"returnLogEntry": True, "internalExperimentFlags": []},
"user": {
"delegationContext": {
"externalChannelId": ch_id,
"roleType": {"channelRoleType": "CREATOR_CHANNEL_ROLE_TYPE_OWNER"},
},
"serializedDelegationContext": "",
},
"clientScreenNonce": "",
},
}),
("skipped+ads+62", {**base, "monetizationSettings": {"newMonetizeWithAds": True}, "adFormats": ad_formats, "selfCertification": cert_skipped, "context": ym._context(channel_id=ch_id, client_name=62)}),
("skipped+62", {**base, "monetizationSettings": {"newMonetizeWithAds": True}, "selfCertification": cert_skipped, "context": ym._context(channel_id=ch_id, client_name=62)}),
("plain+62", {**base, "monetizationSettings": {"newMonetizeWithAds": True}, "context": ym._context(channel_id=ch_id, client_name=62)}),
]
for name, body in payloads:
r = await ym._post_studio(access_token=access, body=body)
print(name, "OK" if r.get("ok") else (r.get("error") or "")[:220])
# creator API with OAuth bearer
import httpx
from app.shorts_upload import _client_kwargs
tmpl = {
"context": ym._context(channel_id=ch_id, client_name=62),
"failOnError": True,
"videoIds": [vid],
"mask": {"monetization": {"all": True}, "title": True, "status": True},
}
async with httpx.AsyncClient(**_client_kwargs(timeout=45.0)) as client:
resp = await client.post(
"https://studio.youtube.com/youtubei/v1/creator/get_creator_videos?alt=json&key=AIzaSyBUPetSUmoZL-OhlxA7ZlfWJRJKBa7VFkE",
headers=ym._studio_headers(access),
json=tmpl,
)
data = resp.json() if resp.content else {}
print("get_creator_videos", resp.status_code, str(data)[:500])
asyncio.run(main())
"""
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
_, out, err = c.exec_command(
f"cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'\n{REMOTE}\nPY",
timeout=120,
)
print(out.read().decode("utf-8", "replace"))
e = err.read().decode("utf-8", "replace").strip()
if e:
print("ERR", e[:800])
c.close()
if __name__ == "__main__":
main()