diff --git a/NUXT/pages/watch.vue b/NUXT/pages/watch.vue
index 30ff0654..0dffe995 100644
--- a/NUXT/pages/watch.vue
+++ b/NUXT/pages/watch.vue
@@ -371,6 +371,7 @@ export default {
this.$youtube.getVid(this.$route.query.v).then((result) => {
// TODO: sourt "tiny" (no qualityLabel) as audio and rest as video
this.sources = result.availableResolutionsAdaptive;
+ this.captions = result.captions;
console.log("Video info data", result);
this.video = result;
@@ -520,6 +521,7 @@ export default {
showComments: false,
// share: false,
sources: [],
+ captions: [],
recommends: null,
loaded: false,
interval: null,
diff --git a/NUXT/plugins/innertube.js b/NUXT/plugins/innertube.js
index 475329c2..0cae1ba7 100644
--- a/NUXT/plugins/innertube.js
+++ b/NUXT/plugins/innertube.js
@@ -750,6 +750,13 @@ class Innertube {
(content) => content.slimOwnerRenderer
)?.slimOwnerRenderer;
+ const captions = responseInfo.captions?.playerCaptionsTracklistRenderer?.captionTracks;
+ captions.unshift({
+ baseUrl: null,
+ name: {
+ runs: [{text: "Disable captions"}]
+ }
+ })
try {
console.log(vidMetadata.contents);
this.playerParams =
@@ -819,6 +826,7 @@ class Innertube {
ownerData.navigationEndpoint
),
channelImg: ownerData?.thumbnail?.thumbnails[0].url,
+ captions: captions,
availableResolutions: resolutions?.formats,
availableResolutionsAdaptive: resolutions?.adaptiveFormats,
metadata: {
diff --git a/NUXT/plugins/utils.js b/NUXT/plugins/utils.js
index 8408883f..64f839f4 100644
--- a/NUXT/plugins/utils.js
+++ b/NUXT/plugins/utils.js
@@ -51,12 +51,70 @@ function setHttp(link) {
// Replace inputted html with tweemoji
function parseEmoji(body) {
- if (twemoji)
- return twemoji.parse(body, {
- folder: "svg",
- ext: ".svg",
- base: 'https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/'
- });
+ try {
+
+ if (twemoji)
+ return twemoji.parse(body, {
+ folder: "svg",
+ ext: ".svg",
+ base: 'https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/'
+ });
+ }catch (e) {
+
+ }
+}
+
+// Function to convert seconds to VTT timestamp format
+function secondsToVTTTime(seconds) {
+ const hours = Math.floor(seconds / 3600);
+ const minutes = Math.floor((seconds % 3600) / 60);
+ const secs = Math.floor(seconds % 60);
+ const milliseconds = Math.round((seconds % 1) * 1000);
+
+ return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}.${String(milliseconds).padStart(3, '0')}`;
+}
+function decodeHtmlEntities(str) {
+ const parser = new DOMParser();
+ const doc = parser.parseFromString(`${str}`, 'text/html');
+ return doc.body.textContent || '';
+}
+
+// Function to parse transcript and convert to VTT
+function convertTranscriptToVTT(transcript) {
+ // transcript =JSON.parse(JSON.stringify(transcript)).data;
+ console.warn(transcript);
+ // Extract elements from the transcript
+ const textElements = transcript.match(/([^<]+)<\/text>/g);
+
+ console.warn(textElements);
+ // Initialize VTT output with header
+ let vttOutput = 'WEBVTT\n\n';
+ for (let i = 0; i < textElements.length; i++) {
+ let textElement = textElements[i];
+ const startMatch = textElement.match(/start="([\d.]+)"/);
+ const durMatch = textElement.match(/dur="([\d.]+)"/);
+ const contentMatch = textElement.match(/>([^<]+)<\/text>/);
+
+ if (startMatch && durMatch && contentMatch) {
+ const start = parseFloat(startMatch[1]);
+ const duration = parseFloat(durMatch[1]);
+ const content = decodeHtmlEntities(contentMatch[1].replace(/\+/g, ' ')); // Decode HTML entities
+
+ let end;
+ if (i+1 >= textElements.length) {
+ end = start + duration;
+ }
+ else {
+ end = textElements[i+1].match(/start="([\d.]+)"/)[1];
+ }
+ const startTime = secondsToVTTTime(start);
+ const endTime = secondsToVTTTime(end);
+
+ vttOutput += `${startTime} --> ${endTime}\n\n\n`; // margin bottom huh
+ vttOutput += `${startTime} --> ${endTime}\n${content}\n\n`;
+ }
+ }
+ return vttOutput.trim();
}
function linkParser(url) {
@@ -93,4 +151,5 @@ module.exports = {
delay,
parseEmoji,
humanFileSize,
+ convertTranscriptToVTT
};
diff --git a/NUXT/plugins/vuetube.js b/NUXT/plugins/vuetube.js
index 22c9da57..ec3407ee 100644
--- a/NUXT/plugins/vuetube.js
+++ b/NUXT/plugins/vuetube.js
@@ -107,12 +107,24 @@ const module = {
return true;
},
- resetBackActions() {
- backActions.reset();
+ async resetBackActions() {
+ try {
+ backActions.reset();
+
+ } catch (e) {
+ await this.launchBackHandling();
+ backActions.reset();
+ }
},
- addBackAction(action) {
- backActions.addAction(action);
+ async addBackAction(action) {
+ try {
+ backActions.addAction(action);
+
+ } catch (e) {
+ await this.launchBackHandling();
+ backActions.addAction(action);
+ }
},
back(listenerFunc) {
diff --git a/NUXT/plugins/youtube.js b/NUXT/plugins/youtube.js
index bcfb0884..e45d73e4 100644
--- a/NUXT/plugins/youtube.js
+++ b/NUXT/plugins/youtube.js
@@ -129,7 +129,8 @@ const innertubeModule = {
try {
return await InnertubeAPI.VidInfoAsync(id);
} catch (error) {
- console.error(error);
+ await this.getAPI();
+ return await InnertubeAPI.VidInfoAsync(id);
}
},