Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaXser authored Jan 19, 2024
1 parent 43afa77 commit d0c63ed
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class VideoHandler {
this.srcObserver.observe(this.video, {
attributeFilter: ["src", "currentSrc"],
});
this.video.addEventListener("canplaythrough", this.handleSrcChanged);
this.video.addEventListener("loadeddata", this.handleSrcChangedBound);
this.stopTranslationBound = this.stopTranslation.bind(this);
this.handleVideoEventBound = this.handleVideoEvent.bind(this);
this.changeOpacityOnEventBound = this.changeOpacityOnEvent.bind(this);
Expand Down Expand Up @@ -1270,13 +1270,15 @@ class VideoHandler {
if (!(this.firstPlay && this.data.autoTranslate === 1)) {
return;
}

const VIDEO_ID = getVideoId(this.site.host, this.video);

if (!VIDEO_ID) {
throw new VOTLocalizedError("VOTNoVideoIDFound");
}

try {
this.videoData = await this.getVideoData();
await this.translateExecutor(VIDEO_ID);
this.firstPlay = false;
} catch (err) {
Expand Down Expand Up @@ -1480,7 +1482,7 @@ class VideoHandler {

videoData.translationHelp = null; // ! should be null for ALL websites except coursera and udemy !
videoData.isStream = false; // by default, we request the translation of the video
videoData.duration = this.video.duration; // ! if 0 - we get 400 error
videoData.duration = this.video?.duration || 343; // ! if 0 - we get 400 error
videoData.videoId = getVideoId(this.site.host, this.video);
videoData.detectedLanguage = this.translateFromLang;
videoData.responseLanguage = this.translateToLang;
Expand Down Expand Up @@ -1682,6 +1684,9 @@ class VideoHandler {
console.log("[VOT] Video Data: ", this.videoData);
const videoURL = `${this.site.url}${VIDEO_ID}`;

// fix enabling the old requested voiceover when changing the language to the native language (#)
this.videoValidator();

if (isStream) {
debug.log("Executed stream translation");
// if (BUILD_MODE === "cloudflare") {
Expand Down Expand Up @@ -2056,10 +2061,11 @@ class VideoHandler {
}

async handleSrcChanged() {
if (!this.video.duration) return;

debug.log("[VideoHandler] src changed", this);

if (!(await this.waitInitialization())) return;
if (!this.video.duration) return;

this.stopTranslation();

Expand Down

0 comments on commit d0c63ed

Please sign in to comment.