From 13fd4e8a5f614d49650efb09c3655abad989bfa1 Mon Sep 17 00:00:00 2001 From: N0H3dy Date: Thu, 2 Mar 2023 22:28:20 -0500 Subject: [PATCH] Fixed the inconsistancy in transcript --- static/js/video-editing.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/static/js/video-editing.js b/static/js/video-editing.js index 3e3d4eb..3af8ca7 100644 --- a/static/js/video-editing.js +++ b/static/js/video-editing.js @@ -1,3 +1,5 @@ +console.log("last line test case"); + let transcriptArea = document.getElementById("transcript"); let transcriptHTML = ` `; @@ -5,9 +7,8 @@ function load(){ fetch('/static/assets/output.json') .then(response => response.json()) .then(data => { - console.log('Hello world'); console.log("Data from output.json"); - console.log(data); + // console.log(data); // Use the data object here processData(data); }); @@ -16,30 +17,54 @@ fetch('/static/assets/output.json') function processData(data) { line = ''; - paragraph = `

` + paragraph = `

`; console.log(data["timestamps"]); data = data["timestamps"]; + for (i = 0; i < data.length; i++) { + // iterates through each line of transcript for (j=0; j 40) { + if (line.length + word.length > 38) { + // checks if the line is longer than 38 characters and if so it creates a new paragraph (goes to next line) + console.log(i + " " + line + ", " + word); paragraph += `

`; transcriptHTML += paragraph; + //ends the paragraph + + //new paragraph paragraph = '

'; line = word; + paragraph += ` ${word}`; + } else { + line += ` ${word}`; paragraph += ` ${word}`; } + + if (j == data[i]["words"].length-1 && i == data.length-1){ + // checks if the last word has been reached + paragraph += `

`; + transcriptHTML += paragraph; + } + + } } // transcriptHTML += `

${line.trim()}

`; + console.log("*********************** The Transcript HTML ****************************"); transcriptArea.innerHTML = transcriptHTML; + console.log(transcriptArea); + // Add event listeners to the lines var words = transcriptArea.getElementsByTagName("span"); for (var i = 0; i < words.length; i++) {