# -*- coding: utf-8 -*- """Try more monetize payload variants + Data API monetizationDetails.""" 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 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 '') # Data API: try monetizationDetails update for body in [ {'id': vid, 'monetizationDetails': {'access': {'type': 'allowed'}}}, {'id': vid, 'status': {'selfDeclaredMadeForKids': False}, 'monetizationDetails': {'access': {'type': 'allowed'}}}, ]: async with httpx.AsyncClient(**_client_kwargs(timeout=45.0)) as client: resp = await client.put( 'https://www.googleapis.com/youtube/v3/videos', params={'part': 'monetizationDetails,status'}, headers={'Authorization': f'Bearer {access}', 'Content-Type': 'application/json'}, json=body, ) data = resp.json() if resp.content else {} print('data_api_put', resp.status_code, str(data)[:350]) # get video monetization state via creator API ctx = ym._context(channel_id=ch_id, client_name=62) ctx['client']['clientVersion'] = '1.20250815.03.00' body = { 'context': ctx, 'failOnError': True, 'videoIds': [vid], 'mask': {'monetization': {'all': True}, 'title': True, 'status': True, 'selfCertification': {'all': True}}, } url = f'https://studio.youtube.com/youtubei/v1/creator/get_creator_videos?alt=json&key={ym._STUDIO_KEY}' async with httpx.AsyncClient(**_client_kwargs(timeout=45.0)) as client: resp = await client.post(url, headers=ym._studio_headers(access), json=body) data = resp.json() if resp.content else {} print('get_creator_videos', resp.status_code) if isinstance(data, dict): vids = (((data.get('videos') or data.get('creatorVideos') or []) ) or []) if not vids and 'videos' in str(data): pass # dump keys print('keys', list(data.keys())[:15]) # try nested for k,v in data.items(): if isinstance(v, list) and v: print('list', k, json.dumps(v[0], ensure_ascii=False)[:800]) break if isinstance(v, dict): for k2,v2 in v.items(): if isinstance(v2, list) and v2: print('nested', k, k2, json.dumps(v2[0], ensure_ascii=False)[:800]) break # adasq-style exact payload with newer clientVersion cert = ym._self_cert_skipped() ad_formats = { 'newHasOverlayAds': 'ENABLED', 'newHasProductListingAds': 'ENABLED', 'newHasSkippableVideoAds': 'ENABLED', 'newHasNonSkippableVideoAds': 'ENABLED', } ad_breaks = { 'newHasPrerolls': 'DISABLED', 'newHasMidrollAds': 'DISABLED', 'newHasManualMidrolls': 'DISABLED', 'newHasPostrolls': 'ENABLED', } for cv in ['1.20250815.03.00', '1.20250218.01.00', '1.20210104.03.01']: ctx = { 'client': { 'clientName': 62, 'clientVersion': cv, 'hl': 'en-GB', 'gl': 'US', 'utcOffsetMinutes': 0, 'osName': 'Android', 'androidSdkVersion': 33, 'deviceMake': 'Google', 'deviceModel': 'Pixel 6 Pro', }, 'request': {'returnLogEntry': True, 'internalExperimentFlags': []}, 'user': { 'delegationContext': { 'externalChannelId': ch_id, 'roleType': {'channelRoleType': 'CREATOR_CHANNEL_ROLE_TYPE_OWNER'}, }, 'serializedDelegationContext': '', }, 'clientScreenNonce': '', } body = { 'encryptedVideoId': vid, 'videoReadMask': {}, 'monetizationSettings': {'newMonetizeWithAds': True}, 'adFormats': ad_formats, 'adBreaks': ad_breaks, 'selfCertification': cert, 'context': ctx, } r = await ym._post_studio(access_token=access, body=body) print('adasq_cv', cv, 'OK' if r.get('ok') else (r.get('error') or '')[:200]) 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")) err = e.read().decode("utf-8", "replace").strip() if err: print('ERR', err[:500]) c.close()