diff --git a/changelog.md b/changelog.md index 9a959de5..c70b6f01 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# 1.3.1 + +- Improved the work of constructing links to private videos for vimeo embed + # 1.3.0 > [!CAUTION] diff --git a/dist/client.d.ts.map b/dist/client.d.ts.map index 874df50f..da2d76d7 100644 --- a/dist/client.d.ts.map +++ b/dist/client.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,SAAS,EACT,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EAEzB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAuB,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAe3E,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IAMrB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,cAAc,EAAE,oBAAoB,CAAC;IAGrC,QAAQ,EAAE,WAAW,CAAM;IAG3B,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAE3B,SAAS,EAAE,MAAM,CAAoB;IACrC,gBAAgB,EAAE,MAAM,CAA2B;IAEnD,KAAK;;;;;;MAMH;IAMF,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAUlC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAY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EAAE,MAAM,EAAE,OAAY,EAAE,EAAE,iBAAiB;IAuBtD,eAAe,CAAC,EACpB,SAAS,EACT,WAA8B,EAC9B,YAAgC,EAChC,OAAY,GACb,EAAE,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA0DvD,aAAa,CAAC,MAAM,EAAE,aAAa;;;;;CAqB1C;AAED,qBAAa,eAAgB,SAAQ,SAAS;IACtC,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,OAAO,CAAC,cAAc,CAAC;CA+B3B"} \ No newline at end of file +{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,SAAS,EACT,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EAEzB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAuB,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAkB3E,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IAMrB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,cAAc,EAAE,oBAAoB,CAAC;IAGrC,QAAQ,EAAE,WAAW,CAAM;IAG3B,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAE3B,SAAS,EAAE,MAAM,CAAoB;IACrC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EACtB,OAAY,GACb,EAAE,oBAAoB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAwBrD,YAAY,CAAC,EACjB,SAAS,EACT,WAA8B,EAC9B,OAAY,GACb,EAAE,kBAAkB;IA4Bf,UAAU,CAAC,EAAE,MAAM,EAAE,OAAY,EAAE,EAAE,iBAAiB;IAuBtD,eAAe,CAAC,EACpB,SAAS,EACT,WAA8B,EAC9B,YAAgC,EAChC,OAAY,GACb,EAAE,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA0DvD,aAAa,CAAC,MAAM,EAAE,aAAa;;;;;CAqB1C;AAED,qBAAa,eAAgB,SAAQ,SAAS;IACtC,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,OAAO,CAAC,cAAc,CAAC;CA+B3B"} \ No newline at end of file diff --git a/dist/helpers/vimeo.d.ts.map b/dist/helpers/vimeo.d.ts.map index 476f023b..0abf373d 100644 --- a/dist/helpers/vimeo.d.ts.map +++ b/dist/helpers/vimeo.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"vimeo.d.ts","sourceRoot":"","sources":["../../src/helpers/vimeo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAqB,MAAM,iBAAiB,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAoB,MAAM,QAAQ,CAAC;AAItD,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,UAAU;IACjD,OAAO,SAAM;IACb,mBAAmB,SAAuB;IAC1C,WAAW,SAEkB;IAE7B,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,IAAI,IAAI,KAAK,CAAC,KAAK;IAIlD,eAAe;IAIT,aAAa;IAiBb,YAAY,CAAC,OAAO,EAAE,MAAM;IA6B5B,qBAAqB,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY;IA6C/C,mBAAmB,CAAC,OAAO,EAAE,MAAM;;;;;;;IAiDnC,WAAW,CAAC,OAAO,EAAE,MAAM;IA8B3B,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAuFpE,UAAU,CAAC,GAAG,EAAE,GAAG;CAU1B"} \ No newline at end of file +{"version":3,"file":"vimeo.d.ts","sourceRoot":"","sources":["../../src/helpers/vimeo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAqB,MAAM,iBAAiB,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAoB,MAAM,QAAQ,CAAC;AAItD,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,UAAU;IACjD,OAAO,SAAM;IACb,mBAAmB,SAAuB;IAC1C,WAAW,SAEkB;IAE7B,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,IAAI,IAAI,KAAK,CAAC,KAAK;IAIlD,eAAe;IAIT,aAAa;IAiBb,YAAY,CAAC,OAAO,EAAE,MAAM;IA6B5B,qBAAqB,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY;IAmD/C,mBAAmB,CAAC,OAAO,EAAE,MAAM;;;;;;;IAiDnC,WAAW,CAAC,OAAO,EAAE,MAAM;IA8B3B,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAuFpE,UAAU,CAAC,GAAG,EAAE,GAAG;CAU1B"} \ No newline at end of file diff --git a/dist/helpers/vimeo.js b/dist/helpers/vimeo.js index e8b0a2ae..941b0ca8 100644 --- a/dist/helpers/vimeo.js +++ b/dist/helpers/vimeo.js @@ -60,9 +60,15 @@ export default class VimeoHelper extends BaseHelper { const baseUrl = new URL(cdnUrl); const pathLength = Array.from(data.base_url.matchAll(/\.\.\//g)).length + 1; const pathFragments = baseUrl.pathname.split("/"); - baseUrl.pathname = pathFragments - .slice(0, pathFragments.length - pathLength) - .join("/"); + let extraPath = data.base_url.replaceAll("../", ""); + extraPath = + extraPath && !extraPath.startsWith("/") ? `/${extraPath}` : extraPath; + baseUrl.pathname = + pathFragments.slice(0, pathFragments.length - pathLength).join("/") + + extraPath; + if (!baseUrl.pathname.endsWith("/")) { + baseUrl.pathname += "/"; + } const videoData = data.audio.find((v) => v.mime_type === "audio/mp4" && v.format === "dash"); if (!videoData) { throw new VideoHelperError("Failed to find video data"); @@ -72,9 +78,9 @@ export default class VimeoHelper extends BaseHelper { throw new VideoHelperError("Failed to find first segment url"); } const [videoName, videoParams] = segmentUrl.split("?", 2); - baseUrl.pathname += `/${videoData.base_url}${videoName}`; const params = new URLSearchParams(videoParams); params.delete("range"); + baseUrl.pathname += `${videoData.base_url}${videoName}`; baseUrl.href = baseUrl.href.split("?")[0] + "?" + params.toString(); return baseUrl.href; } diff --git a/docs/classes/VOTClient.html b/docs/classes/VOTClient.html index 11a06d1c..59d8bb33 100644 --- a/docs/classes/VOTClient.html +++ b/docs/classes/VOTClient.html @@ -1,4 +1,4 @@ -
If you don't want to use the classic fetch
import { ofetch } from "ofetch";
import VOTClient from "../dist/client";
import { getVideoData } from "../dist/utils/videoData";
// https://github.com/unjs/ofetch
const client = new VOTClient({
fetchFn: ofetch.native,
});
const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI");
const response = await client.translateVideo({
videoData,
});
-Headers for interacting with Yandex API
-Headers for interacting with VOT Backend API
-Headers for interacting with Yandex API
+Headers for interacting with VOT Backend API
+
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
});
console.log(response);
// subs
const subs = await client.getSubtitles({
videoData,
requestLang: "ru",
});
-Media with this format use VOT Backend API +
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
+
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
-The standard method for requesting the Yandex API, if necessary, you can override how it is done in the example
+The standard method for requesting the Yandex API, if necessary, you can override how it is done in the example
import { getVideoData } from "../dist/utils/videoData";
// https://github.com/axios/axios
const client = new (class AxiosVOTClient extends VOTClient {
async request(
path: string,
body: Uint8Array,
headers: Record<string, string> = {},
): Promise<ClientResponse> {
try {
const res = await axios({
url: `https://${this.host}${path}`,
method: "POST",
headers: {
...this.headers,
...headers,
},
data: body,
responseType: "arraybuffer",
...this.fetchOpts,
});
return {
success: res.status === 200,
data: res.data as ClientResponse,
};
} catch (err: unknown) {
return {
success: false,
data: (err as Error)?.message,
};
}
}
})();
const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI");
const response = await client.translateVideo({
videoData,
});
-The standard method for requesting the VOT Backend API
-
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
+
The standard method for requesting the VOT Backend API
+
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
-
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
const videoData = await getVideoData(url);
// only link
let response = await client.translateVideo({
videoData,
});
console.log(response);
const videoDataTransHelp = await getVideoData("https://s3.toil.cc/vot/video");
// link + translationHelp (just for example, this is an unsupported domain)
response = await client.translateVideo({
videoData: videoDataTransHelp,
translationHelp: [
{
target: "subtitles_file_url",
targetUrl: "https://s3.toil.cc/vot/subs.vtt",
},
{
target: "video_file_url",
targetUrl: "https://s3.toil.cc/vot/video.mp4",
},
requestLang: "ru",
});
console.log(subs);
// translate weverse
const videoDataWeverse = await getVideoData(
"https://weverse.io/redvelvet/media/4-139332911",
);
response = await client.translateVideo({
+
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
const videoData = await getVideoData(url);
// only link
let response = await client.translateVideo({
videoData,
});
console.log(response);
const videoDataTransHelp = await getVideoData("https://s3.toil.cc/vot/video");
// link + translationHelp (just for example, this is an unsupported domain)
response = await client.translateVideo({
videoData: videoDataTransHelp,
translationHelp: [
{
target: "subtitles_file_url",
targetUrl: "https://s3.toil.cc/vot/subs.vtt",
},
{
target: "video_file_url",
targetUrl: "https://s3.toil.cc/vot/video.mp4",
},
requestLang: "ru",
});
console.log(subs);
// translate weverse
const videoDataWeverse = await getVideoData(
"https://weverse.io/redvelvet/media/4-139332911",
);
response = await client.translateVideo({
-Protected
translateProtected
translateProtected
translateProtected
translateIf you don't want to use the classic fetch
import { ofetch } from "ofetch";
import VOTClient from "../dist/client";
import { getVideoData } from "../dist/utils/videoData";
// https://github.com/unjs/ofetch
const client = new VOTClient({
fetchFn: ofetch.native,
});
const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI");
const response = await client.translateVideo({
videoData,
});
-Headers for interacting with Yandex API
-Headers for interacting with VOT Backend API
-Headers for interacting with Yandex API
+Headers for interacting with VOT Backend API
+
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
});
console.log(response);
// subs
const subs = await client.getSubtitles({
videoData,
requestLang: "ru",
});
-Media with this format use VOT Backend API +
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
+
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
-The standard method for requesting the Yandex API, if necessary, you can override how it is done in the example
+The standard method for requesting the Yandex API, if necessary, you can override how it is done in the example
import { getVideoData } from "../dist/utils/videoData";
// https://github.com/axios/axios
const client = new (class AxiosVOTClient extends VOTClient {
async request(
path: string,
body: Uint8Array,
headers: Record<string, string> = {},
): Promise<ClientResponse> {
try {
const res = await axios({
url: `https://${this.host}${path}`,
method: "POST",
headers: {
...this.headers,
...headers,
},
data: body,
responseType: "arraybuffer",
...this.fetchOpts,
});
return {
success: res.status === 200,
data: res.data as ClientResponse,
};
} catch (err: unknown) {
return {
success: false,
data: (err as Error)?.message,
};
}
}
})();
const videoData = await getVideoData("https://youtu.be/LK6nLR1bzpI");
const response = await client.translateVideo({
videoData,
});
-The standard method for requesting the VOT Backend API
-
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
+
The standard method for requesting the VOT Backend API
+
import { getVideoData } from "../dist/utils/videoData";
const client = new VOTClient();
const videoData = await getVideoData("https://youtu.be/nA9UZF-SZoQ");
let response: StreamTranslationResponse;
let inter: Timer;
function isAbortedWaitingStream(
response: StreamTranslationResponse,
): response is WaitingStreamTranslationResponse {
return !!(response as WaitingStreamTranslationResponse).message;
}
const fn = async () => {
response = await client.translateStream({
videoData,
requestLang: "en",
responseLang: "ru",
});
console.log(response);
clearTimeout(inter);
if (!response.translated && response.interval === 10) {
inter = setTimeout(fn, 10000);
return;
}
if (isAbortedWaitingStream(response)) {
console.log(`Stream translation aborted! Message: ${response.message}`);
return;
}
await client.pingStream({
pingId: response.pingId,
});
console.log(`Success! URL: ${response.result.url}`);
-
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
const videoData = await getVideoData(url);
// only link
let response = await client.translateVideo({
videoData,
});
console.log(response);
const videoDataTransHelp = await getVideoData("https://s3.toil.cc/vot/video");
// link + translationHelp (just for example, this is an unsupported domain)
response = await client.translateVideo({
videoData: videoDataTransHelp,
translationHelp: [
{
target: "subtitles_file_url",
targetUrl: "https://s3.toil.cc/vot/subs.vtt",
},
{
target: "video_file_url",
targetUrl: "https://s3.toil.cc/vot/video.mp4",
},
requestLang: "ru",
});
console.log(subs);
// translate weverse
const videoDataWeverse = await getVideoData(
"https://weverse.io/redvelvet/media/4-139332911",
);
response = await client.translateVideo({
+
const client = new VOTClient();
const url = "https://youtu.be/LK6nLR1bzpI";
const videoData = await getVideoData(url);
// only link
let response = await client.translateVideo({
videoData,
});
console.log(response);
const videoDataTransHelp = await getVideoData("https://s3.toil.cc/vot/video");
// link + translationHelp (just for example, this is an unsupported domain)
response = await client.translateVideo({
videoData: videoDataTransHelp,
translationHelp: [
{
target: "subtitles_file_url",
targetUrl: "https://s3.toil.cc/vot/subs.vtt",
},
{
target: "video_file_url",
targetUrl: "https://s3.toil.cc/vot/video.mp4",
},
requestLang: "ru",
});
console.log(subs);
// translate weverse
const videoDataWeverse = await getVideoData(
"https://weverse.io/redvelvet/media/4-139332911",
);
response = await client.translateVideo({
-Protected
translateProtected
translateProtected
translateProtected
translateA convenient wrapper over the rest of the helpers
-
If you don't want to use the classic fetch
+