Skip to content

Commit

Permalink
Улучшения логики получения звука из видео (фикс автогромкости)
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaXser authored Jan 27, 2024
1 parent 6703d13 commit f6bc425
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dist/vot-cloudflare-min.user.js

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions dist/vot-cloudflare.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5174,6 +5174,13 @@ class VideoHandler {
this.stopTranslation();
});

addExtraEventListener(this.video, "volumechange", () => {
debug/* default */.Z.log("lipsync mode is volumechange");
if (this.video.volume !== this.data.autoVolume) {
this.volumeOnStart = this.getVideoVolume();
}
});

addExtraEventListener(this.video, "progress", async () => {
if (!(this.firstPlay && this.data.autoTranslate === 1)) {
return;
Expand Down Expand Up @@ -5550,7 +5557,7 @@ class VideoHandler {
this.votDownloadButton.hidden = true;
this.downloadTranslationUrl = null;
this.transformBtn("none", localizationProvider/* localizationProvider */.V.get("translateVideo"));
if (this.volumeOnStart) {
if (this.video.volume === this.data.autoVolume) {
debug/* default */.Z.log(`Volume on start: ${this.volumeOnStart}`);
if (this.site.host === "youtube") {
youtubeUtils.setVideoVolume(this.volumeOnStart);
Expand All @@ -5565,8 +5572,7 @@ class VideoHandler {

async translateExecutor(VIDEO_ID) {
// доработать логику
const audioSouce = this.audio.src || this.hls;
if (this.firstPlay && !audioSouce) {
if (this.firstPlay) {
this.videoData = await this.getVideoData();
this.setSelectMenuValues(
this.videoData.detectedLanguage,
Expand Down Expand Up @@ -5729,7 +5735,6 @@ class VideoHandler {

youtubeUtils.videoSeek(this.video, 10); // 10 is the most successful number for streaming. With it, the audio is not so far behind the original

this.volumeOnStart = this.getVideoVolume();
if (typeof this.data.defaultVolume === "number") {
this.audio.volume = this.data.defaultVolume / 100;
}
Expand Down Expand Up @@ -5850,7 +5855,6 @@ class VideoHandler {
this.audio.src = proxiedAudioUrl;
}

this.volumeOnStart = this.getVideoVolume();
if (typeof this.data.defaultVolume === "number") {
this.audio.volume = this.data.defaultVolume / 100;
}
Expand Down Expand Up @@ -5958,6 +5962,8 @@ class VideoHandler {

this.firstPlay = true;

this.volumeOnStart = this.getVideoVolume();

const hide =
!this.video.src && !this.video.currentSrc && !this.video.srcObject;
this.votButton.container.hidden = hide;
Expand Down
2 changes: 1 addition & 1 deletion dist/vot-min.user.js

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions dist/vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5163,6 +5163,13 @@ class VideoHandler {
this.stopTranslation();
});

addExtraEventListener(this.video, "volumechange", () => {
debug/* default */.Z.log("lipsync mode is volumechange");
if (this.video.volume !== this.data.autoVolume) {
this.volumeOnStart = this.getVideoVolume();
}
});

addExtraEventListener(this.video, "progress", async () => {
if (!(this.firstPlay && this.data.autoTranslate === 1)) {
return;
Expand Down Expand Up @@ -5539,7 +5546,7 @@ class VideoHandler {
this.votDownloadButton.hidden = true;
this.downloadTranslationUrl = null;
this.transformBtn("none", localizationProvider/* localizationProvider */.V.get("translateVideo"));
if (this.volumeOnStart) {
if (this.video.volume === this.data.autoVolume) {
debug/* default */.Z.log(`Volume on start: ${this.volumeOnStart}`);
if (this.site.host === "youtube") {
youtubeUtils.setVideoVolume(this.volumeOnStart);
Expand All @@ -5554,8 +5561,7 @@ class VideoHandler {

async translateExecutor(VIDEO_ID) {
// доработать логику
const audioSouce = this.audio.src || this.hls;
if (this.firstPlay && !audioSouce) {
if (this.firstPlay) {
this.videoData = await this.getVideoData();
this.setSelectMenuValues(
this.videoData.detectedLanguage,
Expand Down Expand Up @@ -5718,7 +5724,6 @@ class VideoHandler {

youtubeUtils.videoSeek(this.video, 10); // 10 is the most successful number for streaming. With it, the audio is not so far behind the original

this.volumeOnStart = this.getVideoVolume();
if (typeof this.data.defaultVolume === "number") {
this.audio.volume = this.data.defaultVolume / 100;
}
Expand Down Expand Up @@ -5829,7 +5834,6 @@ class VideoHandler {
false
) {}

this.volumeOnStart = this.getVideoVolume();
if (typeof this.data.defaultVolume === "number") {
this.audio.volume = this.data.defaultVolume / 100;
}
Expand Down Expand Up @@ -5937,6 +5941,8 @@ class VideoHandler {

this.firstPlay = true;

this.volumeOnStart = this.getVideoVolume();

const hide =
!this.video.src && !this.video.currentSrc && !this.video.srcObject;
this.votButton.container.hidden = hide;
Expand Down
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,13 @@ class VideoHandler {
this.stopTranslation();
});

addExtraEventListener(this.video, "volumechange", () => {
debug.log("lipsync mode is volumechange");
if (this.video.volume !== this.data.autoVolume) {
this.volumeOnStart = this.getVideoVolume();
}
});

addExtraEventListener(this.video, "progress", async () => {
if (!(this.firstPlay && this.data.autoTranslate === 1)) {
return;
Expand Down Expand Up @@ -1653,7 +1660,7 @@ class VideoHandler {
this.votDownloadButton.hidden = true;
this.downloadTranslationUrl = null;
this.transformBtn("none", localizationProvider.get("translateVideo"));
if (this.volumeOnStart) {
if (this.video.volume === this.data.autoVolume) {
debug.log(`Volume on start: ${this.volumeOnStart}`);
if (this.site.host === "youtube") {
youtubeUtils.setVideoVolume(this.volumeOnStart);
Expand All @@ -1668,9 +1675,7 @@ class VideoHandler {

async translateExecutor(VIDEO_ID) {
// доработать логику
const audioSouce = this.audio.src || this.hls;
console.log("audioSouce", audioSouce);
if (this.firstPlay && !audioSouce) {
if (this.firstPlay) {
this.videoData = await this.getVideoData();
this.setSelectMenuValues(
this.videoData.detectedLanguage,
Expand Down Expand Up @@ -1833,7 +1838,6 @@ class VideoHandler {

youtubeUtils.videoSeek(this.video, 10); // 10 is the most successful number for streaming. With it, the audio is not so far behind the original

this.volumeOnStart = this.getVideoVolume();
if (typeof this.data.defaultVolume === "number") {
this.audio.volume = this.data.defaultVolume / 100;
}
Expand Down Expand Up @@ -1954,7 +1958,6 @@ class VideoHandler {
this.audio.src = proxiedAudioUrl;
}

this.volumeOnStart = this.getVideoVolume();
if (typeof this.data.defaultVolume === "number") {
this.audio.volume = this.data.defaultVolume / 100;
}
Expand Down Expand Up @@ -2062,6 +2065,8 @@ class VideoHandler {

this.firstPlay = true;

this.volumeOnStart = this.getVideoVolume();

const hide =
!this.video.src && !this.video.currentSrc && !this.video.srcObject;
this.votButton.container.hidden = hide;
Expand Down

0 comments on commit f6bc425

Please sign in to comment.