Skip to content

Commit d6475ec

Browse files
author
Pietro Passarelli - News Labs
committed
cleaned up code for subtitles parsing
1 parent 3b7ae7f commit d6475ec

File tree

1 file changed

+7
-9
lines changed
  • packages/export-adapters/subtitles-generator

1 file changed

+7
-9
lines changed

packages/export-adapters/subtitles-generator/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,25 @@ function segmentedTextToList(text) {
2121
return result;
2222
}
2323

24-
function countWords(text) {
24+
function countEndWordPosition(text) {
2525
return text
2626
.trim()
2727
.replace(/\n /g, '')
2828
.replace(/\n/g, ' ')
29-
.split(' ').length;
30-
}
31-
32-
function countList(list) {
33-
return list.length - 1;
29+
.split(' ').length - 1;
3430
}
3531

3632
function addTimecodesToLines(wordsList, lines) {
3733
let startWordCounter = 0;
3834
let endWordCounter = 0;
3935
const results = lines.map((line) => {
40-
endWordCounter += countWords(line);
36+
endWordCounter += countEndWordPosition(line);
4137
const jsonLine = { text: line.trim() };
38+
4239
jsonLine.start = wordsList[startWordCounter].start;
43-
jsonLine.end = wordsList[endWordCounter - 1].end;
44-
startWordCounter = endWordCounter;
40+
jsonLine.end = wordsList[endWordCounter].end;
41+
42+
startWordCounter = endWordCounter + 1;
4543

4644
return jsonLine;
4745
});

0 commit comments

Comments
 (0)