Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add id3 to audio #820

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
32 changes: 16 additions & 16 deletions dist/vot-min.user.js

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions dist/vot.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default [
"sonarjs/max-switch-cases": 0,
"sonarjs/prefer-for-of": 0,
"sonarjs/new-cap": 0,
"sonarjs/todo-tag": 0,
"sonarjs/todo-tag": "warn",
"sonarjs/no-commented-code": 0,
"sonarjs/no-nested-assignment": 0,
"sonarjs/cognitive-complexity": "warn",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"voice-over-translation"
],
"devDependencies": {
"browser-id3-writer": "^6.1.0",
"browserslist": "^4.23.3",
"bun-types": "^1.1.28",
"enquirer": "^2.4.1",
Expand Down
26 changes: 10 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { availableLangs, availableTTS, subtitlesFormats } from "vot.js/consts";
import { convertSubs } from "vot.js/utils/subs";
import { svg, html } from "lit-html";
import { ID3Writer } from "browser-id3-writer";

import {
defaultAutoVolume,
Expand Down Expand Up @@ -362,7 +363,7 @@
}

// convert old vot-worker domain to actual
// TODO: remove converter in one of the next versions after release 1.7.0

Check warning on line 366 in src/index.js

View workflow job for this annotation

GitHub Actions / node (18.18.x)

Complete the task associated to this "TODO" comment

Check warning on line 366 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Complete the task associated to this "TODO" comment
if (this.data.proxyWorkerHost === "vot.toil.cc") {
this.data.proxyWorkerHost = proxyWorkerHost;
await votStorage.set("proxyWorkerHost", proxyWorkerHost);
Expand Down Expand Up @@ -472,7 +473,7 @@
}
}

initUI() {

Check warning on line 476 in src/index.js

View workflow job for this annotation

GitHub Actions / node (18.18.x)

Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed

Check warning on line 476 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed
// VOT Button
{
this.votButton = ui.createVOTButton(
Expand Down Expand Up @@ -1101,7 +1102,11 @@
const filename = clearFileName(
this.videoData.title ?? this.videoData.videoId,
);
downloadBlob(blob, `${filename}.mp3`);
const arrayBuffer = await blob.arrayBuffer();
const writer = new ID3Writer(arrayBuffer);
writer.setFrame("TIT2", filename);
writer.addTag();
downloadBlob(writer.getBlob(), `${filename}.mp3`);
});

this.votDownloadSubtitlesButton.addEventListener("click", async () => {
Expand Down Expand Up @@ -2173,6 +2178,9 @@
localizationProvider.get("grantPermissionToAutoPlay"),
);
throw new VOTLocalizedError("grantPermissionToAutoPlay");
} else if (e.name === "NotSupportedError") {
this.data.audioProxy = 1;
await votStorage.set("audioProxy", 1);
}
});
}
Expand Down Expand Up @@ -2354,20 +2362,6 @@
return audioUrl;
}

async setAudioSourceAndPlay(audioUrl) {
debug.log("setAudioSourceAndPlay");
this.audio.src = audioUrl;
try {
await this.audio.play();
} catch (e) {
console.error("[VOT]", e);
if (e.name === "NotSupportedError") {
this.data.audioProxy = 1;
await votStorage.set("audioProxy", 1);
}
}
}

/**
* Download audio file and connect it to audio context
*
Expand Down Expand Up @@ -2422,7 +2416,7 @@
// eslint-disable-next-line sonarjs/no-unused-expressions
this.needBypassCSP()
? await this.configurePlaySound(audioUrl)
: await this.setAudioSourceAndPlay(audioUrl);
: (this.audio.src = audioUrl);

if (!this.volumeOnStart) {
this.volumeOnStart = this.getVideoVolume();
Expand All @@ -2449,7 +2443,7 @@
}

// Define a function to translate a video and handle the callback
async translateFunc(

Check warning on line 2446 in src/index.js

View workflow job for this annotation

GitHub Actions / node (18.18.x)

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed

Check warning on line 2446 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed
VIDEO_ID,
isStream,
requestLang,
Expand Down
Loading
Loading