publishport-opencli 1.0.57 → 1.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import{readChapters as v,setXhsChapters as x}from"./publish-editors.js";import*as s from"node:fs";import*as a from"node:path";import{setInputFiles as f}from"../../_shared/file-inject.js";import{ArgumentError as l,CommandExecutionError as m}from"@jackwener/opencli/errors";import{clickControl as c,control as w,fillControl as u,verifyControl as r,publicationTime as q,resolveDeclaration as b}from"../../_shared/publish-controls.js";async function y(t,e){const o=await w(t,".d-select",e);await t.evaluate(`(() => {const el=document.querySelectorAll('.d-select')[${o.nth}].closest('.d-select-wrapper'); el.focus();return true;})()`);await t.wait({time:0.2})}async function h(t,e,o){const n=await w(t,e,o);await t.evaluate(`(() => {document.querySelectorAll(${JSON.stringify(e)})[${n.nth}].click();return true;})()`);await t.wait({time:0.2})}export const XHS_DECLARATIONS={ai:"笔记含AI合成内容",fiction:"虚构演绎,仅供娱乐",marketing:"内容包含营销广告",reprint:"来源转载","self-shot":"自主拍摄"};const d={public:"公开可见",private:"仅自己可见",friends:"仅互关好友可见",include:"只给谁看",exclude:"不给谁看"};export const XHS_PUBLISH_ARGS=[{name:"declaration",choices:Object.keys(XHS_DECLARATIONS),help:"内容声明:ai / fiction / marketing / reprint / self-shot"},{name:"source",help:"转载来源媒体名称(declaration=reprint 必填)"},{name:"shot-location",help:"自主拍摄地点(使用平台候选地点的完整名称)"},{name:"shot-date",help:"自主拍摄日期 YYYY-MM-DD"},{name:"original",type:"boolean",help:"声明原创;true 同意平台原创声明须知,false 取消"},{name:"visibility",choices:Object.keys(d),help:"可见范围;include/exclude 需同时指定 --audience"},{name:"audience",help:"定向可见用户昵称,逗号分隔(最多200人,须在平台可选列表中)"},{name:"schedule",help:"北京时间 YYYY-MM-DD HH:mm / 带时区 ISO8601 / Unix秒;1小时至14天后"},{name:"allow-duet",type:"boolean",help:"允许合拍(true/false,不传保留平台默认)"},{name:"allow-copy",type:"boolean",help:"允许正文复制(true/false,不传保留平台默认)"},{name:"location",help:"地点完整名称,按平台搜索结果精确选择"},{name:"location-address",help:"地点完整地址,使用 xiaohongshu location 返回的地址区分重名"},{name:"activity",help:"关联活动完整名称(平台会自动添加活动话题)"},{name:"quote-note",help:"引用笔记链接(小红书完整链接,包含访问所需参数)"},{name:"quote-title",help:"引用自己已发布笔记的完整标题,与 --quote-note 二选一"},{name:"attachment",help:"文件附件路径:pdf/doc/docx/ppt/pptx,最多100MB"}],XHS_VIDEO_ARGS=[...XHS_PUBLISH_ARGS.filter((t)=>!["allow-duet","allow-copy","attachment"].includes(t.name)),{name:"chapters",help:"章节 JSON 文件路径:[{time:整数秒,title:章节名,description:描述}],视频须至少15秒"},{name:"summary",help:"视频内容总结(最多100字)"},{name:"cover",help:"自定义视频封面图片路径(jpg/png/webp)"},{name:"cover-ratio",choices:["original","1:1","3:4","4:3"],help:"封面裁剪比例,需同时提供 --cover"}];export function validateXhsSettings(t){if(t["location-address"]&&!t.location)throw new l("--location-address 需要 --location");const e=v(t.chapters);if(t.summary!==void 0&&[...String(t.summary)].length>100)throw new l("--summary 最多100字");if(t["cover-ratio"]&&!t.cover)throw new l("--cover-ratio 需要 --cover");if(t.cover){const i=a.resolve(t.cover);if(!s.existsSync(i)||!s.statSync(i).isFile()||![".jpg",".jpeg",".png",".webp"].includes(a.extname(i).toLowerCase()))throw new l("封面需为存在的 jpg/png/webp 文件")}if(t["quote-note"]&&t["quote-title"])throw new l("--quote-note 与 --quote-title 二选一");if(t["quote-note"]){let i;try{i=new URL(t["quote-note"])}catch{throw new l("--quote-note 需要完整的小红书笔记链接")}if(i.protocol!=="https:"||!["xiaohongshu.com","www.xiaohongshu.com","xhslink.com"].includes(i.hostname))throw new l("--quote-note 需要 HTTPS 小红书笔记链接")}if(t.attachment){const i=a.resolve(t.attachment);if(!s.existsSync(i)||!s.statSync(i).isFile())throw new l("附件文件不存在: "+i);if(![".pdf",".doc",".docx",".ppt",".pptx"].includes(a.extname(i).toLowerCase())||s.statSync(i).size>104857600)throw new l("附件需为100MB以内的 pdf/doc/docx/ppt/pptx")}const o=b(t,XHS_DECLARATIONS);if(o==="reprint"&&!String(t.source||"").trim())throw new l("--declaration reprint 需要 --source 媒体名称");if(t.source&&o!=="reprint")throw new l("--source 仅用于 --declaration reprint");if(o==="reprint"&&t.original)throw new l("转载来源声明不能与 --original true 同时使用");if(o==="self-shot"&&(!t["shot-location"]||!/^\d{4}-\d{2}-\d{2}$/.test(t["shot-date"]||"")))throw new l("自主拍摄需 --shot-location 和 --shot-date YYYY-MM-DD");if((t["shot-date"]||t["shot-location"])&&o!=="self-shot")throw new l("拍摄地点和日期仅用于 --declaration self-shot");if(t.visibility!==void 0&&!Object.hasOwn(d,t.visibility))throw new l("不支持的 --visibility");const n=String(t.audience||"").split(",").map((i)=>i.trim()).filter(Boolean);if(["include","exclude"].includes(t.visibility)&&(!n.length||n.length>200||new Set(n).size!==n.length))throw new l("定向可见需要1至200个不重复的 --audience 用户");if(n.length&&!["include","exclude"].includes(t.visibility))throw new l("--audience 仅用于 include/exclude 可见范围");return{declaration:o,schedule:q(t.schedule,1),audience:n,chapters:e}}async function p(t,e,o){return t.evaluate(`([...document.querySelectorAll(${JSON.stringify(e)})].filter(e=>e.getClientRects().length && e.textContent.trim()===${JSON.stringify(o)}).length === 1)`)}export async function xhsSwitch(t,e,o){const i=await(()=>t.evaluate(`((label)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);if(rows.length!==1)return null; const input=rows[0].querySelector('input[type="checkbox"]');return input ? {checked:input.checked,nth:[...document.querySelectorAll('.custom-switch-card .d-switch')].indexOf(rows[0].querySelector('.d-switch'))}:null;})(${JSON.stringify(e)})`))();if(!i||i.nth<0)throw new m("未找到发布设置开关:"+e+";已停止提交");if(i?.checked===o)return;await t.click(".custom-switch-card .d-switch",{nth:i.nth});await t.wait({time:0.2});if(e==="原创声明"&&o&&await t.evaluate("!!document.querySelector('.originalContainer')")){await c(t,".originalContainer .d-checkbox");await c(t,".originalContainer button","声明原创")}await r(t,`((label,value)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);return rows.length===1 && rows[0].querySelector('input[type="checkbox"]')?.checked===value;})(${JSON.stringify(e)},${o})`,e)}async function C(t,e,o){const n=XHS_DECLARATIONS[o],i=await p(t,".d-select-description",n);if(i&&!["reprint","self-shot"].includes(o))return;await c(t,".d-select",i?n:"添加内容类型声明");if(o==="reprint"||o==="self-shot")await c(t,".declaration-drop-down .d-option-name","内容来源声明");await c(t,".d-popover .d-option-content",n);if(o==="reprint"){await u(t,'input[placeholder="请输入媒体名称"]',e.source);await c(t,".self-shooting-contain button","确认")}if(o==="self-shot"){await u(t,'input[placeholder="下拉选择地点"]',e["shot-location"],!1);await r(t,`!![...document.querySelectorAll('.el-autocomplete-suggestion .name')].find(e=>e.textContent.trim()===${JSON.stringify(e["shot-location"])})`,"拍摄地点候选");await c(t,".el-autocomplete-suggestion .name",e["shot-location"],!1);await u(t,".self-shooting-contain .d-datepicker-input-filter input",e["shot-date"]);await c(t,".self-shooting-contain button","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1) && !document.querySelector('.self-shooting-contain')`,n)}export async function setXhsPublishSettings(t,e){const o=validateXhsSettings(e);if(e.original!==void 0)await xhsSwitch(t,"原创声明",e.original);if(o.declaration)await C(t,e,o.declaration);if(e["allow-duet"]!==void 0)await xhsSwitch(t,"允许合拍",e["allow-duet"]);if(e["allow-copy"]!==void 0)await xhsSwitch(t,"允许正文复制",e["allow-copy"]);if(e.visibility){const n=d[e.visibility];if(!await p(t,".d-select-description",n)){const i=await t.evaluate(`([...document.querySelectorAll('.d-select-description')].filter(e=>${JSON.stringify(Object.values(d))}.includes(e.textContent.trim())).map(e=>e.textContent.trim()))`);if(i.length!==1)throw new m("无法确定当前可见范围;已停止提交");await y(t,i[0]);await h(t,".custom-option .name",n)}if(o.audience.length){for(const i of o.audience){await u(t,'.d-modal input[placeholder="搜索用户"]',i,!1);await r(t,`!![...document.querySelectorAll('.d-modal .left .user-list *')].find(e=>!e.children.length&&e.textContent.trim()===${JSON.stringify(i)})`,"可选用户 "+i);await c(t,".d-modal .left .user-list .user-name",i)}await c(t,".d-modal .confirm-btn","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1)`,"可见范围")}if(o.schedule){await xhsSwitch(t,"定时发布",!0);await u(t,".d-datepicker-input-filter input",o.schedule)}if(e.location){await y(t,"添加地点");await u(t,".d-select.focus input",e.location,!1);const n=`(({name,address})=>{const all=[...document.querySelectorAll('.d-popover .option-name')];const hits=all.filter(e=>e.getClientRects().length && e.textContent.trim()===name && (!address || e.parentElement.querySelector('.option-subname')?.textContent.trim()===address));return hits.length===1 ? all.indexOf(hits[0]) : -1;})(${JSON.stringify({name:e.location,address:e["location-address"]})})`;await r(t,`(${n})>=0`,"唯一地点(重名时指定 --location-address)");const i=await t.evaluate(n);if(i<0)throw new m("地点候选已变化,停止提交");await t.evaluate(`document.querySelectorAll('.d-popover .option-name')[${i}].click()`);await r(t,`!![...document.querySelectorAll('.d-select-description')].find(e=>e.textContent.trim()===${JSON.stringify(e.location)})`,"地点")}if(e["quote-note"]||e["quote-title"]){await c(t,".setting-card-text","引用笔记");if(e["quote-note"]){await c(t,".select-note-modal__tab","他人笔记");await u(t,'input[placeholder="请粘贴笔记链接 http://..."]',e["quote-note"],!1)}const n=e["quote-title"];await r(t,`([...document.querySelectorAll('.select-note-modal .note-card__title')].filter(e=>e.getClientRects().length ${n?"&& e.textContent.trim()==="+JSON.stringify(n):""}).length===1)`,"待引用笔记");const i=await w(t,".select-note-modal .note-card__title",n),S=await t.evaluate(`document.querySelectorAll('.select-note-modal .note-card__title')[${i.nth}].textContent.trim()`);await t.click(i.selector,{nth:i.nth});await c(t,".select-note-modal button","确认引用");await r(t,`!document.querySelector('.select-note-modal') && document.body.innerText.includes(${JSON.stringify("《")} + ${JSON.stringify(S)} + '》')`,"引用笔记")}if(e.activity){await h(t,".more","更多");const n=`((name)=>{const cards=[...document.querySelectorAll('.activity-card-drawer')].filter(e=>e.querySelector('.activity-name')?.textContent.trim()===name);return cards.length===1 ? {nth:[...document.querySelectorAll('.activity-card-drawer .activity-action')].indexOf(cards[0].querySelector('.activity-action')),selected:cards[0].querySelector('.activity-action')?.textContent.trim()==='取消关联'} : null;})(${JSON.stringify(e.activity)})`;await r(t,`!!(${n})`,"活动 "+e.activity);const i=await t.evaluate(n);if(!i.selected)await t.evaluate(`document.querySelectorAll('.activity-card-drawer .activity-action')[${i.nth}].click()`);await r(t,`(${n})?.selected === true`,"关联活动");await h(t,".d-drawer-close")}if(e.attachment){await f(t,'.file-relation-container input[type="file"]',[a.resolve(e.attachment)]);await r(t,`document.querySelector('.file-relation-container .setting-card-text')?.textContent.trim() === ${JSON.stringify(a.basename(e.attachment))} && !document.querySelector('.file-relation-container')?.textContent.includes('上传中')`,"附件上传",60000)}if(o.chapters||e.summary!==void 0)await x(t,o.chapters,e.summary);if(e.cover){const n=await t.evaluate("document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage");await c(t,".cover-plugin-preview > .cover > .default");await c(t,".cover-plugin-preview .cover-edit-entry");await c(t,".d-modal .d-tabs-header-label","上传封面");await f(t,'.d-modal input[type="file"]',[a.resolve(e.cover)]);await r(t,"!!document.querySelector('#upload-cover-containner .cropper-canvas img')?.getAttribute('src')","封面图片载入",30000);if(e["cover-ratio"]){const i=e["cover-ratio"]==="original"?"原始":e["cover-ratio"];await c(t,".d-modal .crop-ratio-item",i);await r(t,`document.querySelector('.d-modal .crop-ratio-item-active')?.textContent.trim()===${JSON.stringify(i)}`,"封面裁剪比例")}await c(t,".d-modal button","确定");await r(t,`!document.querySelector('#upload-cover-containner') && document.querySelector('.cover-plugin-preview')?.getAttribute('aria-busy')==='false' && document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage !== ${JSON.stringify(n)}`,"视频封面上传",60000)}}
|
|
1
|
+
import{readChapters as v,setXhsChapters as x}from"./publish-editors.js";import*as s from"node:fs";import*as a from"node:path";import{setInputFiles as f}from"../../_shared/file-inject.js";import{ArgumentError as c,CommandExecutionError as d}from"@jackwener/opencli/errors";import{clickControl as l,control as w,fillControl as u,verifyControl as r,publicationTime as q,resolveDeclaration as b}from"../../_shared/publish-controls.js";async function y(t,e){const o=await w(t,".d-select",e);await t.evaluate(`(() => {const el=document.querySelectorAll('.d-select')[${o.nth}].closest('.d-select-wrapper'); el.focus();return true;})()`);await t.wait({time:0.2})}async function h(t,e,o){const n=await w(t,e,o);await t.evaluate(`(() => {document.querySelectorAll(${JSON.stringify(e)})[${n.nth}].click();return true;})()`);await t.wait({time:0.2})}export const XHS_DECLARATIONS={ai:"笔记含AI合成内容",fiction:"虚构演绎,仅供娱乐",marketing:"内容包含营销广告",reprint:"来源转载","self-shot":"自主拍摄"};const m={public:"公开可见",private:"仅自己可见",friends:"仅互关好友可见",include:"只给谁看",exclude:"不给谁看"};export const XHS_PUBLISH_ARGS=[{name:"declaration",choices:Object.keys(XHS_DECLARATIONS),help:"内容声明:ai / fiction / marketing / reprint / self-shot"},{name:"source",help:"转载来源媒体名称(declaration=reprint 必填)"},{name:"shot-location",help:"自主拍摄地点(使用平台候选地点的完整名称)"},{name:"shot-date",help:"自主拍摄日期 YYYY-MM-DD"},{name:"original",type:"boolean",help:"声明原创;true 同意平台原创声明须知,false 取消"},{name:"visibility",choices:Object.keys(m),help:"可见范围;include/exclude 需同时指定 --audience"},{name:"audience",help:"定向可见用户昵称,逗号分隔(最多200人,须在平台可选列表中)"},{name:"schedule",help:"北京时间 YYYY-MM-DD HH:mm / 带时区 ISO8601 / Unix秒;1小时至14天后"},{name:"allow-duet",type:"boolean",help:"允许合拍(true/false,不传保留平台默认)"},{name:"allow-copy",type:"boolean",help:"允许正文复制(true/false,不传保留平台默认)"},{name:"location",help:"地点完整名称,按平台搜索结果精确选择"},{name:"location-address",help:"地点完整地址,使用 xiaohongshu location 返回的地址区分重名"},{name:"activity",help:"关联活动完整名称(平台会自动添加活动话题)"},{name:"quote-note",help:"引用笔记链接(小红书完整链接,包含访问所需参数)"},{name:"quote-title",help:"引用自己已发布笔记的完整标题,与 --quote-note 二选一"},{name:"attachment",help:"文件附件路径:pdf/doc/docx/ppt/pptx,最多100MB"}],XHS_VIDEO_ARGS=[...XHS_PUBLISH_ARGS.filter((t)=>!["allow-duet","allow-copy","attachment"].includes(t.name)),{name:"chapters",help:"章节 JSON 文件路径:[{time:整数秒,title:章节名,description:描述}],视频须至少15秒"},{name:"summary",help:"视频内容总结(最多100字)"},{name:"cover",help:"自定义视频封面图片路径(jpg/png/webp)"},{name:"cover-ratio",choices:["original","1:1","3:4","4:3"],help:"封面裁剪比例,需同时提供 --cover"}];export function validateXhsSettings(t){if(t["location-address"]&&!t.location)throw new c("--location-address 需要 --location");const e=v(t.chapters);if(t.summary!==void 0&&[...String(t.summary)].length>100)throw new c("--summary 最多100字");if(t["cover-ratio"]&&!t.cover)throw new c("--cover-ratio 需要 --cover");if(t.cover){const i=a.resolve(t.cover);if(!s.existsSync(i)||!s.statSync(i).isFile()||![".jpg",".jpeg",".png",".webp"].includes(a.extname(i).toLowerCase()))throw new c("封面需为存在的 jpg/png/webp 文件")}if(t["quote-note"]&&t["quote-title"])throw new c("--quote-note 与 --quote-title 二选一");if(t["quote-note"]){let i;try{i=new URL(t["quote-note"])}catch{throw new c("--quote-note 需要完整的小红书笔记链接")}if(i.protocol!=="https:"||!["xiaohongshu.com","www.xiaohongshu.com","xhslink.com"].includes(i.hostname))throw new c("--quote-note 需要 HTTPS 小红书笔记链接")}if(t.attachment){const i=a.resolve(t.attachment);if(!s.existsSync(i)||!s.statSync(i).isFile())throw new c("附件文件不存在: "+i);if(![".pdf",".doc",".docx",".ppt",".pptx"].includes(a.extname(i).toLowerCase())||s.statSync(i).size>104857600)throw new c("附件需为100MB以内的 pdf/doc/docx/ppt/pptx")}const o=b(t,XHS_DECLARATIONS);if(o==="reprint"&&!String(t.source||"").trim())throw new c("--declaration reprint 需要 --source 媒体名称");if(t.source&&o!=="reprint")throw new c("--source 仅用于 --declaration reprint");if(o==="reprint"&&t.original)throw new c("转载来源声明不能与 --original true 同时使用");if(o==="self-shot"&&(!t["shot-location"]||!/^\d{4}-\d{2}-\d{2}$/.test(t["shot-date"]||"")))throw new c("自主拍摄需 --shot-location 和 --shot-date YYYY-MM-DD");if((t["shot-date"]||t["shot-location"])&&o!=="self-shot")throw new c("拍摄地点和日期仅用于 --declaration self-shot");if(t.visibility!==void 0&&!Object.hasOwn(m,t.visibility))throw new c("不支持的 --visibility");const n=String(t.audience||"").split(",").map((i)=>i.trim()).filter(Boolean);if(["include","exclude"].includes(t.visibility)&&(!n.length||n.length>200||new Set(n).size!==n.length))throw new c("定向可见需要1至200个不重复的 --audience 用户");if(n.length&&!["include","exclude"].includes(t.visibility))throw new c("--audience 仅用于 include/exclude 可见范围");return{declaration:o,schedule:q(t.schedule,1),audience:n,chapters:e}}async function p(t,e,o){return t.evaluate(`([...document.querySelectorAll(${JSON.stringify(e)})].filter(e=>e.getClientRects().length && e.textContent.trim()===${JSON.stringify(o)}).length === 1)`)}export async function xhsSwitch(t,e,o){const i=await(()=>t.evaluate(`((label)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);if(rows.length!==1)return null; const input=rows[0].querySelector('input[type="checkbox"]');return input ? {checked:input.checked,nth:[...document.querySelectorAll('.custom-switch-card .d-switch')].indexOf(rows[0].querySelector('.d-switch'))}:null;})(${JSON.stringify(e)})`))();if(!i||i.nth<0)throw new d("未找到发布设置开关:"+e+";已停止提交");if(i?.checked===o)return;await t.click(".custom-switch-card .d-switch",{nth:i.nth});await t.wait({time:0.2});if(e==="原创声明"&&o&&await t.evaluate("!!document.querySelector('.originalContainer')")){await l(t,".originalContainer .d-checkbox");await l(t,".originalContainer button","声明原创")}await r(t,`((label,value)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);return rows.length===1 && rows[0].querySelector('input[type="checkbox"]')?.checked===value;})(${JSON.stringify(e)},${o})`,e)}async function C(t,e,o){const n=XHS_DECLARATIONS[o],i=await p(t,".d-select-description",n);if(i&&!["reprint","self-shot"].includes(o))return;await l(t,".d-select",i?n:"添加内容类型声明");if(o==="reprint"||o==="self-shot")await l(t,".declaration-drop-down .d-option-name","内容来源声明");await l(t,".d-popover .d-option-content",n);if(o==="reprint"){await u(t,'input[placeholder="请输入媒体名称"]',e.source);await l(t,".self-shooting-contain button","确认")}if(o==="self-shot"){await u(t,'input[placeholder="下拉选择地点"]',e["shot-location"],!1);await r(t,`!![...document.querySelectorAll('.el-autocomplete-suggestion .name')].find(e=>e.textContent.trim()===${JSON.stringify(e["shot-location"])})`,"拍摄地点候选");await l(t,".el-autocomplete-suggestion .name",e["shot-location"],!1);await u(t,".self-shooting-contain .d-datepicker-input-filter input",e["shot-date"]);await l(t,".self-shooting-contain button","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1) && !document.querySelector('.self-shooting-contain')`,n)}async function O(t){const e=await t.evaluate(`(() => {
|
|
2
|
+
const preview = document.querySelector('.cover-plugin-preview');
|
|
3
|
+
if (!preview) return {error: '未找到视频封面区(.cover-plugin-preview)'};
|
|
4
|
+
const entries = [...preview.querySelectorAll('.cover-edit-entry')].filter(e => e.textContent.trim() === '编辑封面');
|
|
5
|
+
if (entries.length !== 1) return {error: '封面区「编辑封面」入口应唯一,找到 ' + entries.length + ';封面区现有文字:' + preview.innerText.replace(/\\s+/g, ' ').trim().slice(0, 80)};
|
|
6
|
+
entries[0].click();
|
|
7
|
+
return {ok: true};
|
|
8
|
+
})()`);if(!e?.ok)throw new d(`发布设置 视频封面:${e?.error||"页面响应异常"};已停止提交`);await r(t,"[...document.querySelectorAll('.d-modal .d-tabs-header-label')].some(e => e.getClientRects().length && e.textContent.trim() === '上传封面')","打开设置封面弹窗",1e4)}export async function setXhsPublishSettings(t,e){const o=validateXhsSettings(e);if(e.original!==void 0)await xhsSwitch(t,"原创声明",e.original);if(o.declaration)await C(t,e,o.declaration);if(e["allow-duet"]!==void 0)await xhsSwitch(t,"允许合拍",e["allow-duet"]);if(e["allow-copy"]!==void 0)await xhsSwitch(t,"允许正文复制",e["allow-copy"]);if(e.visibility){const n=m[e.visibility];if(!await p(t,".d-select-description",n)){const i=await t.evaluate(`([...document.querySelectorAll('.d-select-description')].filter(e=>${JSON.stringify(Object.values(m))}.includes(e.textContent.trim())).map(e=>e.textContent.trim()))`);if(i.length!==1)throw new d("无法确定当前可见范围;已停止提交");await y(t,i[0]);await h(t,".custom-option .name",n)}if(o.audience.length){for(const i of o.audience){await u(t,'.d-modal input[placeholder="搜索用户"]',i,!1);await r(t,`!![...document.querySelectorAll('.d-modal .left .user-list *')].find(e=>!e.children.length&&e.textContent.trim()===${JSON.stringify(i)})`,"可选用户 "+i);await l(t,".d-modal .left .user-list .user-name",i)}await l(t,".d-modal .confirm-btn","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1)`,"可见范围")}if(o.schedule){await xhsSwitch(t,"定时发布",!0);await u(t,".d-datepicker-input-filter input",o.schedule)}if(e.location){await y(t,"添加地点");await u(t,".d-select.focus input",e.location,!1);const n=`(({name,address})=>{const all=[...document.querySelectorAll('.d-popover .option-name')];const hits=all.filter(e=>e.getClientRects().length && e.textContent.trim()===name && (!address || e.parentElement.querySelector('.option-subname')?.textContent.trim()===address));return hits.length===1 ? all.indexOf(hits[0]) : -1;})(${JSON.stringify({name:e.location,address:e["location-address"]})})`;await r(t,`(${n})>=0`,"唯一地点(重名时指定 --location-address)");const i=await t.evaluate(n);if(i<0)throw new d("地点候选已变化,停止提交");await t.evaluate(`document.querySelectorAll('.d-popover .option-name')[${i}].click()`);await r(t,`!![...document.querySelectorAll('.d-select-description')].find(e=>e.textContent.trim()===${JSON.stringify(e.location)})`,"地点")}if(e["quote-note"]||e["quote-title"]){await l(t,".setting-card-text","引用笔记");if(e["quote-note"]){await l(t,".select-note-modal__tab","他人笔记");await u(t,'input[placeholder="请粘贴笔记链接 http://..."]',e["quote-note"],!1)}const n=e["quote-title"];await r(t,`([...document.querySelectorAll('.select-note-modal .note-card__title')].filter(e=>e.getClientRects().length ${n?"&& e.textContent.trim()==="+JSON.stringify(n):""}).length===1)`,"待引用笔记");const i=await w(t,".select-note-modal .note-card__title",n),S=await t.evaluate(`document.querySelectorAll('.select-note-modal .note-card__title')[${i.nth}].textContent.trim()`);await t.click(i.selector,{nth:i.nth});await l(t,".select-note-modal button","确认引用");await r(t,`!document.querySelector('.select-note-modal') && document.body.innerText.includes(${JSON.stringify("《")} + ${JSON.stringify(S)} + '》')`,"引用笔记")}if(e.activity){await h(t,".more","更多");const n=`((name)=>{const cards=[...document.querySelectorAll('.activity-card-drawer')].filter(e=>e.querySelector('.activity-name')?.textContent.trim()===name);return cards.length===1 ? {nth:[...document.querySelectorAll('.activity-card-drawer .activity-action')].indexOf(cards[0].querySelector('.activity-action')),selected:cards[0].querySelector('.activity-action')?.textContent.trim()==='取消关联'} : null;})(${JSON.stringify(e.activity)})`;await r(t,`!!(${n})`,"活动 "+e.activity);const i=await t.evaluate(n);if(!i.selected)await t.evaluate(`document.querySelectorAll('.activity-card-drawer .activity-action')[${i.nth}].click()`);await r(t,`(${n})?.selected === true`,"关联活动");await h(t,".d-drawer-close")}if(e.attachment){await f(t,'.file-relation-container input[type="file"]',[a.resolve(e.attachment)]);await r(t,`document.querySelector('.file-relation-container .setting-card-text')?.textContent.trim() === ${JSON.stringify(a.basename(e.attachment))} && !document.querySelector('.file-relation-container')?.textContent.includes('上传中')`,"附件上传",60000)}if(o.chapters||e.summary!==void 0)await x(t,o.chapters,e.summary);if(e.cover){const n=await t.evaluate("document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage");await O(t);await l(t,".d-modal .d-tabs-header-label","上传封面");await f(t,'.d-modal input[type="file"]',[a.resolve(e.cover)]);await r(t,"!!document.querySelector('#upload-cover-containner .cropper-canvas img')?.getAttribute('src')","封面图片载入",30000);if(e["cover-ratio"]){const i=e["cover-ratio"]==="original"?"原始":e["cover-ratio"];await l(t,".d-modal .crop-ratio-item",i);await r(t,`document.querySelector('.d-modal .crop-ratio-item-active')?.textContent.trim()===${JSON.stringify(i)}`,"封面裁剪比例")}await l(t,".d-modal button","确定");await r(t,`!document.querySelector('#upload-cover-containner') && document.querySelector('.cover-plugin-preview')?.getAttribute('aria-busy')==='false' && document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage !== ${JSON.stringify(n)}`,"视频封面上传",60000)}}
|
|
@@ -37,7 +37,7 @@ import{TOPIC_ID_ARG as C,parseTopics as I,attachTopics as q}from"./_shared/topic
|
|
|
37
37
|
`)}B({site:"xiaohongshu",name:"publish-video",access:"write",description:"小红书发布视频笔记(creator center UI 自动化)",domain:"creator.xiaohongshu.com",strategy:U.COOKIE,browser:!0,navigateBefore:!1,args:[{name:"content",required:!1,positional:!0,help:"笔记正文(字面文本,不展开 @文件 引用;长正文用 --file)"},{name:"file",required:!1,help:"从本机文件读取正文(UTF-8),与位置参数 <content> 二选一"},{name:"title",required:!0,help:"笔记标题(≤20字)"},{name:"video",required:!0,help:"视频文件路径 (mp4/mov/mkv/...)"},{name:"topics",required:!1,help:"话题名称,逗号分隔,最多10个;先用 topics 查询。无法准确选中时停止提交"},C,{name:"draft",type:"bool",default:!1,help:"暂存为草稿,不直接发布"},{name:"ai-generated",type:"boolean",help:"声明内容由 AI 生成(发布和草稿均支持;设置失败时停止提交)"},...D],columns:["status","detail"],func:async(t,e)=>{R(e);if(!t)throw Error("Browser page required");const i=String(e.title??"").trim(),n=e.file?String(e.file).trim():"";let o=String(e.content??"").trim();if(n){if(o)throw new s("正文位置参数和 --file 只能二选一");const r=p.resolve(n);if(!_.existsSync(r))throw new s(`--file 指向的文件不存在: ${r}`);o=_.readFileSync(r,"utf-8").trim();if(!o)throw new s(`--file 指向的文件内容为空: ${r}`)}const c=I(e),h=c.map((r)=>r.name),l=Boolean(e.draft);if(!i)throw new s("--title 必填");if(i.length>y)throw new s(`标题 ${i.length} 字,需 ≤ ${y} 字`);if(!o)throw new s("缺少正文:给位置参数 <content>,或用 --file <本机文件路径>");k(o,{fileFlag:"--file"});if(o.length>x)throw new s(`正文 ${o.length} 字,需 ≤ ${x} 字`);if(!e.video)throw new s("--video 必填");if(h.length>S)throw new s(`话题过多: ${h.length}(最多 ${S} 个)`);const v=G(String(e.video));await t.goto(J);await t.evaluate(`(() => {
|
|
38
38
|
document.documentElement.setAttribute('data-ppcli-composer-reload', 'pending');
|
|
39
39
|
setTimeout(() => location.reload(), 100);
|
|
40
|
-
})()`);await L(t
|
|
40
|
+
})()`);await L(t,`!!document.documentElement && !document.documentElement.hasAttribute('data-ppcli-composer-reload') && !!document.querySelector('input[type="file"]')`,"新的视频发布表单",30000);let d="";for(let r=0;r<30;r++){await t.wait({time:0.5});d=await t.evaluate("() => location.href");if(d.includes("creator.xiaohongshu.com"))break}if(!d.includes("creator.xiaohongshu.com")){await t.screenshot({path:"/tmp/xhs_video_redirect_debug.png"});throw new a(`被重定向离开创作者中心(当前 ${d})——登录态可能已过期。`+"用 ppcli xiaohongshu creator-profile 重新登录。截图: /tmp/xhs_video_redirect_debug.png")}const g=await K(t,v);if(!g.ok){await t.screenshot({path:"/tmp/xhs_video_upload_debug.png"});throw new a(`视频上传失败: ${g.error??"unknown"}。截图: /tmp/xhs_video_upload_debug.png`)}if(!await Q(t)){await t.screenshot({path:"/tmp/xhs_video_form_debug.png"});throw new a("上传后编辑表单未就绪(标题/正文未出现)。截图: /tmp/xhs_video_form_debug.png")}process.stderr.write(` 等待视频转码(可发布状态)...
|
|
41
41
|
`);if(!await z(t)){await t.screenshot({path:"/tmp/xhs_video_transcode_debug.png"});throw new a("视频转码超时(10min),发布按钮未解禁。截图: /tmp/xhs_video_transcode_debug.png")}await W(t,i);await t.wait({time:0.4});await Z(t,o);await t.wait({time:0.5});let m=[];if(h.length){m=await q(t,[b],c);const r=h.filter((P)=>!m.includes(P));if(r.length){await t.screenshot({path:"/tmp/xhs_video_topic_debug.png"});throw new a(`话题未能生成实体: ${r.join(", ")}(联想下拉未出现或无匹配项)。截图: /tmp/xhs_video_topic_debug.png`)}}await F(t,e);const M=await t.evaluate("(() => { const b = document.querySelector('xhs-publish-btn'); return !!b && b.getAttribute('submit-disabled') === 'false'; })()");if(!l&&!M){await t.screenshot({path:"/tmp/xhs_video_prepublish_debug.png"});throw new a("发布前复查:发布按钮不可用(submit-disabled≠false)。截图: /tmp/xhs_video_prepublish_debug.png")}const f=await tt(t,l);if(!f?.ok){await t.screenshot({path:"/tmp/xhs_video_submit_debug.png"});throw new a(`找不到「${l?"暂存离开":"发布"}」触发方式(hosts=${f?.hosts??0}${f?.lastMethodError?`, lastMethodError=${f.lastMethodError}`:""})。截图: /tmp/xhs_video_submit_debug.png`)}await t.wait({time:4});let u=await t.evaluate("() => location.href");const N=l?["草稿已保存","暂存成功","保存成功","保存于"]:["发布成功","上传成功"],w=await t.evaluate(`
|
|
42
42
|
((markers) => {
|
|
43
43
|
for (const el of document.querySelectorAll('*')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "publishport-opencli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.58",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": false
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"dev": "tsx src/main.ts",
|
|
47
47
|
"dev:bun": "bun src/main.ts",
|
|
48
|
+
"prerelease": "npm run build && git diff --exit-code --stat -- cli-manifest.json",
|
|
48
49
|
"release": "npm version patch -m \"chore(release): %s\" && git push origin HEAD && git push origin \"$(git describe --tags --abbrev=0)\"",
|
|
49
50
|
"build": "npm run clean-dist && npm run copy-yaml && npm run build-manifest",
|
|
50
51
|
"minify:release": "bun scripts/minify-release.mjs",
|