Skip to content

Commit

Permalink
1.5.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Mar 30, 2024
1 parent 6e6f4fb commit d639f1a
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 39 deletions.
13 changes: 12 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<!-- TODO: TWITCH STREAM TRANSLATION -->
<!-- TODO: -->
<!-- TWITCH STREAM TRANSLATION -->
<!-- перевод Reddit -->
<!-- перевод Patreon (add *://*.patreon.com/* in headers.json)-->

# 1.5.1.4
Все изменения были внесены @SashaXser в #560 и #573
- Добавлено автоматическое определение языка для перевода прямых ссылок
- Добавлено обновление субтитров после перевода видео
- Добавлено сохранение перевода при изменение качества видео
- Возвращен addExtraEventListener emptied взамен на lipsync emptied
- Убрана активация скрипта с локальных файлов .mp4 (они не переводятся)

# 1.5.1.3
- Добавлена поддержка прямых веб-ссылок на видео (.mp4)
Expand Down
5 changes: 3 additions & 2 deletions dist/vot-cloudflare-min.user.js

Large diffs are not rendered by default.

50 changes: 35 additions & 15 deletions dist/vot-cloudflare.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@
// @match *://*.egghead.io/*
// @match *://*.youku.com/*
// @match *://*/*.mp4*
// @exclude file://*/*.mp4*
// @connect api.browser.yandex.ru
// @namespace vot-cloudflare
// @version 1.5.1.3
// @version 1.5.1.4
// @icon https://translate.yandex.ru/icons/favicon.ico
// @author sodapng, mynovelhost, Toil, SashaXser, MrSoczekXD
// @homepageURL https://github.com/ilyhalight/voice-over-translation/issues
Expand Down Expand Up @@ -2322,6 +2323,8 @@ const getVideoId = (service, video) => {
return url.pathname;
case "youku":
return url.pathname.match(/v_show\/id_[\w=]+/)?.[0];
// case "patreon":
// return url.pathname.match(/posts\/([^/]+)/)?.[0];
case "directlink":
return url.pathname + url.search;
default:
Expand Down Expand Up @@ -2410,7 +2413,7 @@ const VideoTranslationHelpObject = new protobuf.Type(

const VideoTranslationRequest = new protobuf.Type("VideoTranslationRequest")
.add(new protobuf.Field("url", 3, "string"))
.add(new protobuf.Field("deviceId", 4, "string")) // removed?
.add(new protobuf.Field("deviceId", 4, "string")) // used in mobile version
.add(new protobuf.Field("firstRequest", 5, "bool")) // true for the first request, false for subsequent ones
.add(new protobuf.Field("duration", 6, "double"))
.add(new protobuf.Field("unknown2", 7, "int32")) // 1 1
Expand Down Expand Up @@ -4084,6 +4087,14 @@ const sites = () => {
match: (url) => /([^.]+).mp4/.test(url.pathname),
selector: null,
},
// пока рано
// {
// host: "patreon",
// url: "https://www.patreon.com/",
// match: /^www.patreon.com$/,
// selector:
// 'div[data-tag="post-card"] div[elevation="subtle"] > div > div > div > div',
// },
// Нужно куда-то заливать данные о плейлисте
// {
// host: "epicgames",
Expand Down Expand Up @@ -5451,6 +5462,13 @@ class VideoHandler {
this.container.draggable = false;
}

addExtraEventListener(this.video, "emptied", () => {
if (getVideoId(this.site.host, this.video) === this.videoData.videoId)
return;
debug/* default */.A.log("lipsync mode is emptied");
this.stopTranslation();
});

addExtraEventListener(this.video, "progress", async () => {
if (
!this.videoData.videoId ||
Expand Down Expand Up @@ -5737,6 +5755,7 @@ class VideoHandler {
"trovo",
"yandexdisk",
"coursehunter",
"directlink",
].includes(this.site.host)
) {
videoData.detectedLanguage = "auto";
Expand Down Expand Up @@ -5816,10 +5835,6 @@ class VideoHandler {
debug/* default */.A.log("lipsync mode is playing");
this.audio.play();
}
if (mode == "emptied") {
debug/* default */.A.log("lipsync mode is emptied");
this.stopTranslation();
}
}

// Define a function to handle common events
Expand Down Expand Up @@ -6159,6 +6174,14 @@ class VideoHandler {
}

this.updateTranslation(urlOrError);
if (!this.subtitlesList.some((item) => item.source === "yandex")) {
this.subtitlesList = await subtitles_getSubtitles(
this.site,
this.videoData.videoId,
this.videoData.detectedLanguage,
);
await this.updateSubtitlesLangSelect();
}

this.videoTranslations.push({
videoId: VIDEO_ID,
Expand All @@ -6178,19 +6201,17 @@ class VideoHandler {
}

async handleSrcChanged() {
if (getVideoId(this.site.host, this.video) === this.videoData.videoId)
return;
debug/* default */.A.log("[VideoHandler] src changed", this);

this.stopTranslation();

this.firstPlay = true;

this.videoData = await this.getVideoData();
if (this.videoData.detectedLanguage) {
this.setSelectMenuValues(
this.videoData.detectedLanguage,
this.videoData.responseLanguage,
);
}
this.setSelectMenuValues(
this.videoData.detectedLanguage,
this.videoData.responseLanguage,
);

const hide =
(!this.video.src && !this.video.currentSrc && !this.video.srcObject) ||
Expand All @@ -6216,7 +6237,6 @@ class VideoHandler {
debug/* default */.A.log("[VideoHandler] release");

this.initialized = false;
this.stopTranslation();
this.releaseExtraEvents();
this.subtitlesWidget.release();
this.votButton.container.remove();
Expand Down
5 changes: 3 additions & 2 deletions dist/vot-min.user.js

Large diffs are not rendered by default.

50 changes: 35 additions & 15 deletions dist/vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@
// @match *://*.egghead.io/*
// @match *://*.youku.com/*
// @match *://*/*.mp4*
// @exclude file://*/*.mp4*
// @connect api.browser.yandex.ru
// @namespace vot
// @version 1.5.1.3
// @version 1.5.1.4
// @icon https://translate.yandex.ru/icons/favicon.ico
// @author sodapng, mynovelhost, Toil, SashaXser, MrSoczekXD
// @homepageURL https://github.com/ilyhalight/voice-over-translation/issues
Expand Down Expand Up @@ -2306,6 +2307,8 @@ const getVideoId = (service, video) => {
return url.pathname;
case "youku":
return url.pathname.match(/v_show\/id_[\w=]+/)?.[0];
// case "patreon":
// return url.pathname.match(/posts\/([^/]+)/)?.[0];
case "directlink":
return url.pathname + url.search;
default:
Expand Down Expand Up @@ -2394,7 +2397,7 @@ const VideoTranslationHelpObject = new protobuf.Type(

const VideoTranslationRequest = new protobuf.Type("VideoTranslationRequest")
.add(new protobuf.Field("url", 3, "string"))
.add(new protobuf.Field("deviceId", 4, "string")) // removed?
.add(new protobuf.Field("deviceId", 4, "string")) // used in mobile version
.add(new protobuf.Field("firstRequest", 5, "bool")) // true for the first request, false for subsequent ones
.add(new protobuf.Field("duration", 6, "double"))
.add(new protobuf.Field("unknown2", 7, "int32")) // 1 1
Expand Down Expand Up @@ -4068,6 +4071,14 @@ const sites = () => {
match: (url) => /([^.]+).mp4/.test(url.pathname),
selector: null,
},
// пока рано
// {
// host: "patreon",
// url: "https://www.patreon.com/",
// match: /^www.patreon.com$/,
// selector:
// 'div[data-tag="post-card"] div[elevation="subtle"] > div > div > div > div',
// },
// Нужно куда-то заливать данные о плейлисте
// {
// host: "epicgames",
Expand Down Expand Up @@ -5430,6 +5441,13 @@ class VideoHandler {
this.container.draggable = false;
}

addExtraEventListener(this.video, "emptied", () => {
if (getVideoId(this.site.host, this.video) === this.videoData.videoId)
return;
debug/* default */.A.log("lipsync mode is emptied");
this.stopTranslation();
});

addExtraEventListener(this.video, "progress", async () => {
if (
!this.videoData.videoId ||
Expand Down Expand Up @@ -5716,6 +5734,7 @@ class VideoHandler {
"trovo",
"yandexdisk",
"coursehunter",
"directlink",
].includes(this.site.host)
) {
videoData.detectedLanguage = "auto";
Expand Down Expand Up @@ -5795,10 +5814,6 @@ class VideoHandler {
debug/* default */.A.log("lipsync mode is playing");
this.audio.play();
}
if (mode == "emptied") {
debug/* default */.A.log("lipsync mode is emptied");
this.stopTranslation();
}
}

// Define a function to handle common events
Expand Down Expand Up @@ -6128,6 +6143,14 @@ class VideoHandler {
}

this.updateTranslation(urlOrError);
if (!this.subtitlesList.some((item) => item.source === "yandex")) {
this.subtitlesList = await subtitles_getSubtitles(
this.site,
this.videoData.videoId,
this.videoData.detectedLanguage,
);
await this.updateSubtitlesLangSelect();
}

this.videoTranslations.push({
videoId: VIDEO_ID,
Expand All @@ -6147,19 +6170,17 @@ class VideoHandler {
}

async handleSrcChanged() {
if (getVideoId(this.site.host, this.video) === this.videoData.videoId)
return;
debug/* default */.A.log("[VideoHandler] src changed", this);

this.stopTranslation();

this.firstPlay = true;

this.videoData = await this.getVideoData();
if (this.videoData.detectedLanguage) {
this.setSelectMenuValues(
this.videoData.detectedLanguage,
this.videoData.responseLanguage,
);
}
this.setSelectMenuValues(
this.videoData.detectedLanguage,
this.videoData.responseLanguage,
);

const hide =
(!this.video.src && !this.video.currentSrc && !this.video.srcObject) ||
Expand All @@ -6185,7 +6206,6 @@ class VideoHandler {
debug/* default */.A.log("[VideoHandler] release");

this.initialized = false;
this.stopTranslation();
this.releaseExtraEvents();
this.subtitlesWidget.release();
this.votButton.container.remove();
Expand Down
6 changes: 2 additions & 4 deletions src/headers.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "[VOT] - Voice Over Translation",
"description": "A small extension that adds a Yandex Browser video translation to other browsers",
"version": "1.5.1.3",
"version": "1.5.1.4",
"author": "sodapng, mynovelhost, Toil, SashaXser, MrSoczekXD",
"namespace": "vot",
"icon": "https://translate.yandex.ru/icons/favicon.ico",
Expand Down Expand Up @@ -107,9 +107,7 @@
"*://*.youku.com/*",
"*://*/*.mp4*"
],
"exclude": [
"file://*/*.mp4*"
],
"exclude": ["file://*/*.mp4*"],
"require": [
"https://cdn.jsdelivr.net/npm/protobufjs/dist/light/protobuf.min.js",
"https://cdn.jsdelivr.net/npm/hls.js/dist/hls.light.min.js"
Expand Down

0 comments on commit d639f1a

Please sign in to comment.