Skip to content

Commit

Permalink
Merge pull request #820 from ilyhalight/add-id3-to-audio
Browse files Browse the repository at this point in the history
Add id3 to audio
  • Loading branch information
ilyhalight authored Sep 20, 2024
2 parents 68ee5c7 + 7a8fc99 commit 5935820
Show file tree
Hide file tree
Showing 7 changed files with 9,164 additions and 6,213 deletions.
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 { getVideoData, getVideoID, getService } from "vot.js/utils/videoData";
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 @@ -1101,7 +1102,11 @@ class VideoHandler {
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 @@ class VideoHandler {
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 @@ class VideoHandler {
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 @@ class VideoHandler {
// 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 Down
Loading

0 comments on commit 5935820

Please sign in to comment.