douyinWEB/scripts/_probe_monetize_v3.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

66 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
"""Brute-force Studio monetize endpoints and client names."""
from __future__ import annotations
import paramiko
REMOTE = r"""
import asyncio, json, httpx
from app import db, yt_long_db as yldb
from app.shorts_oauth import channel_oauth_creds
from app.shorts_upload import refresh_access_token, _client_kwargs
from app import yt_long_monetize as ym
KEY = ym._STUDIO_KEY
async def post(url, access, body):
async with httpx.AsyncClient(**_client_kwargs(timeout=60.0)) as client:
resp = await client.post(url, headers=ym._studio_headers(access), json=body)
data = resp.json() if resp.content else {}
err = ''
if resp.status_code >= 400:
err = str((data.get('error') or {}).get('message') if isinstance(data, dict) else resp.text[:200])
return resp.status_code, err or 'OK'
async def main():
yl = yldb.get_yt_long_channel('9f51bb18-65dc-4f77-8d88-9c47fe191ad7')
sch = db.get_shorts_channel(str(yl.get('source_shorts_channel_pk') or ''))
creds = channel_oauth_creds(sch)
access = await refresh_access_token(
client_id=str(creds['client_id']),
client_secret=str(creds['client_secret']),
refresh_token=str(creds['refresh_token']),
)
vid = 'w1mrCE6dmnI'
ch_id = str(yl.get('youtube_channel_id') or '')
base = {'encryptedVideoId': vid, 'videoReadMask': {'title': True}, 'monetizationSettings': {'newMonetizeWithAds': True}}
hosts = [
'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key=' + KEY,
'https://www.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key=' + KEY,
'https://studio.youtube.com/youtubei/v1/creator/update_video_monetization?alt=json&key=' + KEY,
]
clients = [
(62, '1.20250815.03.00'),
('WEB_CREATOR', '1.20250815.03.00'),
('YTSTUDIO_ANDROID', '1.20250815.03.00'),
(87, '1.20250815.03.00'),
]
for host in hosts:
ep = host.split('/youtubei/')[1].split('?')[0]
for cn, cv in clients:
ctx = ym._context(channel_id=ch_id, client_name=cn)
ctx['client']['clientVersion'] = cv
body = {**base, 'context': ctx, 'channelId': ch_id}
sc, err = await post(host, access, body)
print(ep, cn, sc, err[:120])
asyncio.run(main())
"""
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)
_, o, e = c.exec_command(f"cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'\n{REMOTE}\nPY", timeout=180)
print(o.read().decode("utf-8", "replace"))
c.close()