maoda-commander-tt 0.0.22 → 0.0.23
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.
- package/dist/main.js +155 -6
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1799,6 +1799,154 @@ var PippitAssetGetCommand = class extends BaseCommand {
|
|
|
1799
1799
|
}
|
|
1800
1800
|
};
|
|
1801
1801
|
|
|
1802
|
+
// src/commands/pippit/modules/douyin-video/errors.ts
|
|
1803
|
+
var BASE6 = 15e3;
|
|
1804
|
+
var DouyinVideoError = ((DouyinVideoError2) => {
|
|
1805
|
+
DouyinVideoError2[DouyinVideoError2["MissingUserInput"] = BASE6 + 1] = "MissingUserInput";
|
|
1806
|
+
DouyinVideoError2[DouyinVideoError2["MissingWebToken"] = BASE6 + 2] = "MissingWebToken";
|
|
1807
|
+
DouyinVideoError2[DouyinVideoError2["NetworkRequestFailed"] = BASE6 + 3] = "NetworkRequestFailed";
|
|
1808
|
+
DouyinVideoError2[DouyinVideoError2["ResponseParseFailed"] = BASE6 + 4] = "ResponseParseFailed";
|
|
1809
|
+
DouyinVideoError2[DouyinVideoError2["RequestFailed"] = BASE6 + 5] = "RequestFailed";
|
|
1810
|
+
return DouyinVideoError2;
|
|
1811
|
+
})(DouyinVideoError || {});
|
|
1812
|
+
var missingUserInputError = lvErrorConst(
|
|
1813
|
+
DouyinVideoError.MissingUserInput,
|
|
1814
|
+
"\u7F3A\u5C11\u6296\u97F3\u94FE\u63A5\u53C2\u6570\u3002"
|
|
1815
|
+
);
|
|
1816
|
+
var missingWebTokenError2 = lvErrorConst(
|
|
1817
|
+
DouyinVideoError.MissingWebToken,
|
|
1818
|
+
"\u7F3A\u5C11\u53EF\u7528\u7684 sessionid_pippitcn_web token\uFF0C\u8BF7\u5148\u4F7F\u7528 `tt pippit web-token --region=cn <token>` \u914D\u7F6E token\u3002"
|
|
1819
|
+
);
|
|
1820
|
+
var networkRequestFailedError6 = lvErrorConst(
|
|
1821
|
+
DouyinVideoError.NetworkRequestFailed,
|
|
1822
|
+
"\u8BF7\u6C42\u6296\u97F3\u89C6\u9891\u89E3\u6790\u63A5\u53E3\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u548C\u767B\u5F55\u6001\u3002"
|
|
1823
|
+
);
|
|
1824
|
+
var responseParseFailedError5 = lvErrorConst(
|
|
1825
|
+
DouyinVideoError.ResponseParseFailed,
|
|
1826
|
+
"\u89E3\u6790\u6296\u97F3\u89C6\u9891\u89E3\u6790\u63A5\u53E3\u54CD\u5E94\u5931\u8D25\u3002"
|
|
1827
|
+
);
|
|
1828
|
+
var requestFailedError2 = lvErrorConst(
|
|
1829
|
+
DouyinVideoError.RequestFailed,
|
|
1830
|
+
"\u83B7\u53D6\u6296\u97F3\u89C6\u9891\u5730\u5740\u5931\u8D25\u3002"
|
|
1831
|
+
);
|
|
1832
|
+
|
|
1833
|
+
// src/commands/pippit/modules/douyin-video/cn-douyin-video.ts
|
|
1834
|
+
var PARSE_URL = "https://xyq.jianying.com/api/biz/v1/parse/check_input_valid";
|
|
1835
|
+
function normalizeToken4(token) {
|
|
1836
|
+
const trimmed = token.trim();
|
|
1837
|
+
const prefix = "sessionid_pippitcn_web=";
|
|
1838
|
+
if (trimmed.startsWith(prefix)) {
|
|
1839
|
+
return trimmed.slice(prefix.length).trim();
|
|
1840
|
+
}
|
|
1841
|
+
return trimmed;
|
|
1842
|
+
}
|
|
1843
|
+
function createCookieHeader3(token) {
|
|
1844
|
+
return `sessionid_pippitcn_web=${normalizeToken4(token)}`;
|
|
1845
|
+
}
|
|
1846
|
+
function readRecord(value) {
|
|
1847
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1848
|
+
return void 0;
|
|
1849
|
+
}
|
|
1850
|
+
return value;
|
|
1851
|
+
}
|
|
1852
|
+
function parseVideoUrl(data) {
|
|
1853
|
+
const dataRecord = readRecord(data);
|
|
1854
|
+
const videoInfoRecord = readRecord(dataRecord?.video_info);
|
|
1855
|
+
const videoUrl = videoInfoRecord?.video_url;
|
|
1856
|
+
if (typeof videoUrl !== "string") {
|
|
1857
|
+
return void 0;
|
|
1858
|
+
}
|
|
1859
|
+
const trimmed = videoUrl.trim();
|
|
1860
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
1861
|
+
}
|
|
1862
|
+
function parseErrorCode2(ret) {
|
|
1863
|
+
const parsed = typeof ret === "number" ? ret : typeof ret === "string" ? Number.parseInt(ret, 10) : Number.NaN;
|
|
1864
|
+
return Number.isFinite(parsed) ? parsed : DouyinVideoError.RequestFailed;
|
|
1865
|
+
}
|
|
1866
|
+
async function fetchDouyinVideoCn(options) {
|
|
1867
|
+
const webContextResult = await readWebContext("cn" /* CN */);
|
|
1868
|
+
if (!webContextResult.ok) {
|
|
1869
|
+
return webContextResult;
|
|
1870
|
+
}
|
|
1871
|
+
const tokenResult = await readWebToken("cn" /* CN */);
|
|
1872
|
+
if (!tokenResult.ok) {
|
|
1873
|
+
return tokenResult;
|
|
1874
|
+
}
|
|
1875
|
+
const token = tokenResult.value?.trim();
|
|
1876
|
+
if (!token) {
|
|
1877
|
+
return missingWebTokenError2();
|
|
1878
|
+
}
|
|
1879
|
+
const responseResult = await requestJson(
|
|
1880
|
+
PARSE_URL,
|
|
1881
|
+
{
|
|
1882
|
+
method: "POST",
|
|
1883
|
+
headers: {
|
|
1884
|
+
accept: "application/json, text/plain, */*",
|
|
1885
|
+
"content-type": "application/json",
|
|
1886
|
+
cookie: createCookieHeader3(token),
|
|
1887
|
+
Referer: "https://xyq.jianying.com/"
|
|
1888
|
+
},
|
|
1889
|
+
body: JSON.stringify({
|
|
1890
|
+
uid: webContextResult.value.uid,
|
|
1891
|
+
user_input: options.userInput
|
|
1892
|
+
})
|
|
1893
|
+
},
|
|
1894
|
+
{
|
|
1895
|
+
networkRequestFailed: (message) => networkRequestFailedError6(message),
|
|
1896
|
+
responseParseFailed: (message) => responseParseFailedError5(message)
|
|
1897
|
+
}
|
|
1898
|
+
);
|
|
1899
|
+
if (!responseResult.ok) {
|
|
1900
|
+
return responseResult;
|
|
1901
|
+
}
|
|
1902
|
+
const response = responseResult.value;
|
|
1903
|
+
const videoUrl = parseVideoUrl(response.data);
|
|
1904
|
+
if (videoUrl) {
|
|
1905
|
+
return makeOkWith({ video_url: videoUrl });
|
|
1906
|
+
}
|
|
1907
|
+
if (response.ret !== void 0 && String(response.ret) !== "0") {
|
|
1908
|
+
return makeError(
|
|
1909
|
+
parseErrorCode2(response.ret),
|
|
1910
|
+
response.errmsg?.trim() || "\u6296\u97F3\u89C6\u9891\u89E3\u6790\u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF\u3002"
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1913
|
+
return requestFailedError2("\u63A5\u53E3\u672A\u8FD4\u56DE data.video_info.video_url\u3002");
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
// src/commands/pippit/modules/douyin-video/douyin-video.ts
|
|
1917
|
+
async function fetchDouyinVideo(options) {
|
|
1918
|
+
return fetchDouyinVideoCn(options);
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
// src/commands/pippit/pippit-douyin-video-command.ts
|
|
1922
|
+
var PippitDouyinVideoCommand = class extends BaseCommand {
|
|
1923
|
+
_meta() {
|
|
1924
|
+
return {
|
|
1925
|
+
name: "douyin-video",
|
|
1926
|
+
description: "\u901A\u8FC7\u6296\u97F3\u94FE\u63A5\u83B7\u53D6\u89C6\u9891\u5730\u5740"
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
_configureArguments(cmd) {
|
|
1930
|
+
cmd.argument("<user_input...>", "\u8981\u89E3\u6790\u7684\u6296\u97F3\u94FE\u63A5\u6216\u5B8C\u6574\u5206\u4EAB\u6587\u6848");
|
|
1931
|
+
}
|
|
1932
|
+
async _execute(ctx) {
|
|
1933
|
+
const userInputParts = ctx.args[0] ?? [];
|
|
1934
|
+
const userInput = userInputParts.join(" ").trim();
|
|
1935
|
+
if (!userInput) {
|
|
1936
|
+
const error = missingUserInputError();
|
|
1937
|
+
this._outputJsonError(error.code, error.msg);
|
|
1938
|
+
return this._makeOk();
|
|
1939
|
+
}
|
|
1940
|
+
const result = await fetchDouyinVideo({ userInput });
|
|
1941
|
+
if (!result.ok) {
|
|
1942
|
+
this._outputJsonError(result.code, result.msg);
|
|
1943
|
+
return this._makeOk();
|
|
1944
|
+
}
|
|
1945
|
+
this._outputJsonOk(result.value);
|
|
1946
|
+
return this._makeOk();
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
|
|
1802
1950
|
// src/commands/pippit/pippit-command.ts
|
|
1803
1951
|
var PippitCommand = class extends BaseSubcommandHost {
|
|
1804
1952
|
_meta() {
|
|
@@ -1816,6 +1964,7 @@ var PippitCommand = class extends BaseSubcommandHost {
|
|
|
1816
1964
|
this._addSubcommand(new PippitAssetUploadCommand());
|
|
1817
1965
|
this._addSubcommand(new PippitWebTokenCommand());
|
|
1818
1966
|
this._addSubcommand(new PippitAssetGetCommand());
|
|
1967
|
+
this._addSubcommand(new PippitDouyinVideoCommand());
|
|
1819
1968
|
}
|
|
1820
1969
|
};
|
|
1821
1970
|
|
|
@@ -2692,7 +2841,7 @@ var generateUuid = (() => {
|
|
|
2692
2841
|
|
|
2693
2842
|
// src/commands/pippit/modules/submit-direct/submit-direct-cn.ts
|
|
2694
2843
|
var SUBMIT_DIRECT_URL = "https://xyq.jianying.com/api/biz/v1/agent/submit_run";
|
|
2695
|
-
function
|
|
2844
|
+
function normalizeToken5(token) {
|
|
2696
2845
|
const trimmed = token.trim();
|
|
2697
2846
|
const prefix = "sessionid_pippitcn_web=";
|
|
2698
2847
|
if (trimmed.startsWith(prefix)) {
|
|
@@ -2700,10 +2849,10 @@ function normalizeToken4(token) {
|
|
|
2700
2849
|
}
|
|
2701
2850
|
return trimmed;
|
|
2702
2851
|
}
|
|
2703
|
-
function
|
|
2704
|
-
return `sessionid_pippitcn_web=${
|
|
2852
|
+
function createCookieHeader4(token) {
|
|
2853
|
+
return `sessionid_pippitcn_web=${normalizeToken5(token)}`;
|
|
2705
2854
|
}
|
|
2706
|
-
function
|
|
2855
|
+
function parseErrorCode3(ret) {
|
|
2707
2856
|
const parsed = typeof ret === "number" ? ret : typeof ret === "string" ? Number.parseInt(ret, 10) : Number.NaN;
|
|
2708
2857
|
return Number.isFinite(parsed) ? parsed : 1;
|
|
2709
2858
|
}
|
|
@@ -2789,7 +2938,7 @@ async function submitDirectCn(options) {
|
|
|
2789
2938
|
headers: {
|
|
2790
2939
|
accept: "application/json, text/plain, */*",
|
|
2791
2940
|
"content-type": "application/json",
|
|
2792
|
-
cookie:
|
|
2941
|
+
cookie: createCookieHeader4(token),
|
|
2793
2942
|
Referer: "https://xyq.jianying.com/"
|
|
2794
2943
|
},
|
|
2795
2944
|
body: JSON.stringify({
|
|
@@ -2812,7 +2961,7 @@ async function submitDirectCn(options) {
|
|
|
2812
2961
|
console.log("=====response", response);
|
|
2813
2962
|
if (String(response.ret) !== "0") {
|
|
2814
2963
|
return makeError(
|
|
2815
|
-
|
|
2964
|
+
parseErrorCode3(response.ret),
|
|
2816
2965
|
response.errmsg?.trim() || "\u76F4\u63A5\u63D0\u4EA4\u5931\u8D25\u3002"
|
|
2817
2966
|
);
|
|
2818
2967
|
}
|