Skip to content

Commit

Permalink
cleaned up code for subtitles parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Passarelli - News Labs committed Aug 1, 2019
1 parent 3b7ae7f commit d6475ec
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/export-adapters/subtitles-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,25 @@ function segmentedTextToList(text) {
return result;
}

function countWords(text) {
function countEndWordPosition(text) {
return text
.trim()
.replace(/\n /g, '')
.replace(/\n/g, ' ')
.split(' ').length;
}

function countList(list) {
return list.length - 1;
.split(' ').length - 1;
}

function addTimecodesToLines(wordsList, lines) {
let startWordCounter = 0;
let endWordCounter = 0;
const results = lines.map((line) => {
endWordCounter += countWords(line);
endWordCounter += countEndWordPosition(line);
const jsonLine = { text: line.trim() };

jsonLine.start = wordsList[startWordCounter].start;
jsonLine.end = wordsList[endWordCounter - 1].end;
startWordCounter = endWordCounter;
jsonLine.end = wordsList[endWordCounter].end;

startWordCounter = endWordCounter + 1;

return jsonLine;
});
Expand Down

0 comments on commit d6475ec

Please sign in to comment.