Skip to content

Commit

Permalink
builded new version
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Oct 24, 2024
1 parent 70c34a3 commit ef30918
Show file tree
Hide file tree
Showing 315 changed files with 903 additions and 423 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.3.5

- Fixed long waiting for translation for new translation requests for YouTube (status = 6)
- Added a blank function for video-translation/audio (now return only empty audio info for continue video translation)
- Updated Protobuf

# 1.3.4

- Added Incestflix mirrors with https support
Expand Down
15 changes: 10 additions & 5 deletions dist/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { VOTOpts, FetchFunction, GetVideoDataFunction, ClientSession, VOTSessions, URLSchema, ClientResponse } from "./types/client.js";
import type { VideoTranslationOpts, VideoTranslationResponse, RequestLang, ResponseLang, VideoSubtitlesOpts, StreamPingOptions, StreamTranslationOpts, StreamTranslationResponse, SessionModule } from "./types/yandex.js";
import type { VideoTranslationOpts, VideoTranslationResponse, RequestLang, ResponseLang, VideoSubtitlesOpts, StreamPingOptions, StreamTranslationOpts, StreamTranslationResponse, SessionModule, VideoTranslationFailAudioResponse } from "./types/yandex.js";
import { VideoTranslationVOTOpts } from "./types/vot.js";
export default class VOTClient {
host: string;
Expand All @@ -16,6 +16,8 @@ export default class VOTClient {
componentVersion: string;
paths: {
videoTranslation: string;
videoTranslationFailAudio: string;
videoTranslationAudio: string;
videoSubtitles: string;
streamPing: string;
streamTranslation: string;
Expand All @@ -25,18 +27,21 @@ export default class VOTClient {
headers: Record<string, string>;
headersVOT: Record<string, string>;
constructor({ host, hostVOT, fetchFn, fetchOpts, getVideoDataFn, requestLang, responseLang, headers, }?: VOTOpts);
getOpts(body: unknown, headers?: Record<string, string>): {
getOpts(body: unknown, headers?: Record<string, string>, method?: string): {
method: string;
headers: {
[x: string]: string;
};
body: unknown;
};
request(path: string, body: Uint8Array, headers?: Record<string, string>): Promise<ClientResponse>;
request<T = ArrayBuffer>(path: string, body: Uint8Array, headers?: Record<string, string>, method?: string): Promise<ClientResponse<T>>;
requestJSON<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>, method?: string): Promise<ClientResponse<T>>;
requestVOT<T = unknown>(path: string, body: NonNullable<any>, headers?: Record<string, string>): Promise<ClientResponse<T>>;
getSession(module: SessionModule): Promise<ClientSession>;
protected translateVideoYAImpl({ videoData, requestLang, responseLang, translationHelp, headers, }: VideoTranslationOpts): Promise<VideoTranslationResponse>;
protected translateVideoYAImpl({ videoData, requestLang, responseLang, translationHelp, headers, shouldSendFailedAudio, }: VideoTranslationOpts): Promise<VideoTranslationResponse>;
protected translateVideoVOTImpl({ url, videoId, service, requestLang, responseLang, headers, }: VideoTranslationVOTOpts): Promise<VideoTranslationResponse>;
protected requestVtransFailAudio(url: string): Promise<ClientResponse<VideoTranslationFailAudioResponse>>;
requestVtransAudio(url: string, translationId: string, headers?: Record<string, string>): Promise<import("./protos/yandex.js").VideoTranslationResponse>;
translateVideo({ videoData, requestLang, responseLang, translationHelp, headers, }: VideoTranslationOpts): Promise<VideoTranslationResponse>;
getSubtitles({ videoData, requestLang, headers, }: VideoSubtitlesOpts): Promise<import("./protos/yandex.js").SubtitlesResponse>;
pingStream({ pingId, headers }: StreamPingOptions): Promise<boolean>;
Expand All @@ -48,6 +53,6 @@ export default class VOTClient {
}>;
}
export declare class VOTWorkerClient extends VOTClient {
request(path: string, body: Uint8Array, headers?: Record<string, string>): Promise<ClientResponse>;
request<T = ArrayBuffer>(path: string, body: Uint8Array, headers?: Record<string, string>): Promise<ClientResponse<T>>;
}
//# sourceMappingURL=client.d.ts.map
2 changes: 1 addition & 1 deletion dist/client.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 65 additions & 7 deletions dist/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class VOTClient {
componentVersion = config.componentVersion;
paths = {
videoTranslation: "/video-translation/translate",
videoTranslationFailAudio: "/video-translation/fail-audio-js",
videoTranslationAudio: "/video-translation/audio",
videoSubtitles: "/video-subtitles/get-subtitles",
streamPing: "/stream-translation/ping-stream",
streamTranslation: "/stream-translation/translate-stream",
Expand Down Expand Up @@ -71,9 +73,9 @@ export default class VOTClient {
this.responseLang = responseLang;
this.headers = { ...this.headers, ...headers };
}
getOpts(body, headers = {}) {
getOpts(body, headers = {}, method = "POST") {
return {
method: "POST",
method,
headers: {
...this.headers,
...headers,
Expand All @@ -82,11 +84,31 @@ export default class VOTClient {
...this.fetchOpts,
};
}
async request(path, body, headers = {}) {
const options = this.getOpts(new Blob([body]), headers);
async request(path, body, headers = {}, method = "POST") {
const options = this.getOpts(new Blob([body]), headers, method);
try {
const res = await this.fetch(`${this.schema}://${this.host}${path}`, options);
const data = await res.arrayBuffer();
const data = (await res.arrayBuffer());
return {
success: res.status === 200,
data,
};
}
catch (err) {
return {
success: false,
data: err?.message,
};
}
}
async requestJSON(path, body = null, headers = {}, method = "POST") {
const options = this.getOpts(body, {
"Content-Type": "application/json",
...headers,
}, method);
try {
const res = await this.fetch(`${this.schema}://${this.host}${path}`, options);
const data = (await res.json());
return {
success: res.status === 200,
data,
Expand Down Expand Up @@ -134,7 +156,7 @@ export default class VOTClient {
};
return this.sessions[module];
}
async translateVideoYAImpl({ videoData, requestLang = this.requestLang, responseLang = this.responseLang, translationHelp = null, headers = {}, }) {
async translateVideoYAImpl({ videoData, requestLang = this.requestLang, responseLang = this.responseLang, translationHelp = null, headers = {}, shouldSendFailedAudio = true, }) {
const { url, duration = config.defaultDuration } = videoData;
const { secretKey, uuid } = await this.getSession("video-translation");
const body = yandexProtobuf.encodeTranslationRequest(url, duration, requestLang, responseLang, translationHelp);
Expand Down Expand Up @@ -169,6 +191,18 @@ export default class VOTClient {
};
case VideoTranslationStatus.LONG_WAITING:
case VideoTranslationStatus.LONG_WAITING_2:
if (url.startsWith("https://youtu.be/") && shouldSendFailedAudio) {
await this.requestVtransFailAudio(url);
await this.requestVtransAudio(url, translationData.translationId);
return await this.translateVideoYAImpl({
videoData,
requestLang,
responseLang,
translationHelp,
headers,
shouldSendFailedAudio: false,
});
}
return {
translated: false,
remainingTime: translationData.remainingTime ?? -1,
Expand Down Expand Up @@ -212,6 +246,30 @@ export default class VOTClient {
};
}
}
async requestVtransFailAudio(url) {
const res = await this.requestJSON(this.paths.videoTranslationFailAudio, JSON.stringify({
video_url: url,
}), undefined, "PUT");
if (!res.data || typeof res.data === "string" || res.data.status !== 1) {
throw new VOTJSError("Failed to request to fake video translation fail audio js", res);
}
return res;
}
async requestVtransAudio(url, translationId, headers = {}) {
const { secretKey, uuid } = await this.getSession("video-translation");
const body = yandexProtobuf.encodeTranslationAudioRequest(url, translationId);
const sign = await getSignature(body);
const res = await this.request(this.paths.videoTranslationAudio, body, {
"Vtrans-Signature": sign,
"Sec-Vtrans-Sk": secretKey,
"Sec-Vtrans-Token": `${sign}:${uuid}:${this.paths.videoTranslationAudio}:${this.componentVersion}`,
...headers,
}, "PUT");
if (!res.success) {
throw new VOTJSError("Failed to request video translation audio", res);
}
return yandexProtobuf.decodeTranslationAudioResponse(res.data);
}
async translateVideo({ videoData, requestLang = this.requestLang, responseLang = this.responseLang, translationHelp = null, headers = {}, }) {
const { url, videoId, host } = videoData;
return this.isCustomLink(url)
Expand Down Expand Up @@ -336,7 +394,7 @@ export class VOTWorkerClient extends VOTClient {
});
try {
const res = await this.fetch(`${this.schema}://${this.host}${path}`, options);
const data = await res.arrayBuffer();
const data = (await res.arrayBuffer());
return {
success: res.status === 200,
data,
Expand Down
4 changes: 2 additions & 2 deletions dist/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export default {
host: "api.browser.yandex.ru",
hostVOT: "vot-api.toil.cc/v1",
mediaProxy: "media-proxy.toil.cc",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 YaBrowser/24.7.0.0 Safari/537.36",
componentVersion: "24.7.6.972",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 YaBrowser/24.10.0.0 Safari/537.36",
componentVersion: "24.10.1.598",
hmac: "bt8xH3VOlb4mqf0nqAibnDOoiPlXsisf",
defaultDuration: 343,
};
4 changes: 3 additions & 1 deletion dist/protobuf.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { StreamTranslationResponse, SubtitlesResponse, VideoTranslationResponse, YandexSessionResponse } from "./protos/yandex.js";
import type { SessionModule, TranslationHelp } from "./types/yandex.js";
import { type SessionModule, type TranslationHelp } from "./types/yandex.js";
export declare const yandexProtobuf: {
encodeTranslationRequest(url: string, duration: number, requestLang: string, responseLang: string, translationHelp: TranslationHelp[] | null): Uint8Array;
decodeTranslationResponse(response: ArrayBuffer): VideoTranslationResponse;
encodeTranslationAudioRequest(url: string, translationId: string): Uint8Array;
decodeTranslationAudioResponse(response: ArrayBuffer): VideoTranslationResponse;
encodeSubtitlesRequest(url: string, requestLang: string): Uint8Array;
decodeSubtitlesResponse(response: ArrayBuffer): SubtitlesResponse;
encodeStreamPingRequest(pingId: number): Uint8Array;
Expand Down
2 changes: 1 addition & 1 deletion dist/protobuf.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion dist/protobuf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StreamPingRequest, StreamTranslationRequest, StreamTranslationResponse, SubtitlesRequest, SubtitlesResponse, VideoTranslationRequest, VideoTranslationResponse, YandexSessionRequest, YandexSessionResponse, } from "./protos/yandex.js";
import { StreamPingRequest, StreamTranslationRequest, StreamTranslationResponse, SubtitlesRequest, SubtitlesResponse, VideoTranslationAudioRequest, VideoTranslationRequest, VideoTranslationResponse, YandexSessionRequest, YandexSessionResponse, } from "./protos/yandex.js";
import { AudioInfoMessage, } from "./types/yandex.js";
export const yandexProtobuf = {
encodeTranslationRequest(url, duration, requestLang, responseLang, translationHelp) {
return VideoTranslationRequest.encode({
Expand All @@ -14,11 +15,25 @@ export const yandexProtobuf = {
unknown2: 0,
unknown3: 1,
bypassCache: false,
unknown4: 1,
}).finish();
},
decodeTranslationResponse(response) {
return VideoTranslationResponse.decode(new Uint8Array(response));
},
encodeTranslationAudioRequest(url, translationId) {
return VideoTranslationAudioRequest.encode({
url,
translationId,
audioInfo: {
audioFile: new Uint8Array(0),
message: AudioInfoMessage.WEB_API_GET_ALL_GENERATING_URLS_DATA_FROM_IFRAME,
},
}).finish();
},
decodeTranslationAudioResponse(response) {
return VideoTranslationResponse.decode(new Uint8Array(response));
},
encodeSubtitlesRequest(url, requestLang) {
return SubtitlesRequest.encode({
url,
Expand Down
Loading

0 comments on commit ef30918

Please sign in to comment.