Skip to content

Commit

Permalink
split srt lines into 8 words max
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrop committed Sep 28, 2016
1 parent df41cd9 commit 2f8919f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 72 deletions.
58 changes: 43 additions & 15 deletions docs/public/demo/frontEnd/js/models/transcription.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,62 @@ app.Transcription = Backbone.Model.extend({
//TODO: change this to returnSrt coz that's what it is doing
//and make rturns srtJson in helper function in model

returnSrtContent: function(text){

function loopThroughStuff(text, cb){
function loopThroughStuff(text, cb){
// var text = app.TranscriptionsList.get(8).get("text");

var newLinesAr = []
var newLine ={}
var counter = 1

_.each(text, function(paragraphs){

_.each(paragraphs.paragraph, function(paragraph){
newLine.id = counter;
counter+=1

newLine.startTime = fromSecondsForSrt(paragraph.line[0].startTime)
newLine.endTime = fromSecondsForSrt(paragraph.line[paragraph.line.length -1].endTime)
newLine.text = ""
_.each(paragraph.line, function(word){
// console.log(word)
newLine.text += word.text +" "
})//line
newLinesAr.push(newLine)
newLine={}

if(paragraph.line.length > 8){
// console.log(JSON.stringify(paragraph))
// console.log(JSON.stringify(paragraph.line.length))
// console.log("---")
var regroupLines = split(paragraph.line, 8)
// console.log(regroupLines)
//make srt lines
_.each(regroupLines, function(l){
console.log(JSON.stringify(l))
console.log("---")
newLine.id = counter;
counter+=1;
newLine.startTime = fromSecondsForSrt(l[0].startTime);
newLine.endTime = fromSecondsForSrt(l[l.length-1].endTime);
newLine.text = "";
_.each(l, function(w){
// console.log("---");
// console.log(JSON.stringify(w));
newLine.text += w.text +" ";
})//words
newLinesAr.push(newLine)
newLine={}
})//lines in regrouped lines

}else{
newLine.id = counter;
counter+=1
newLine.startTime = fromSecondsForSrt(paragraph.line[0].startTime)
newLine.endTime = fromSecondsForSrt(paragraph.line[paragraph.line.length -1].endTime)
newLine.text = ""
_.each(paragraph.line, function(word){
// console.log(word)
newLine.text += word.text +" "
})//line
newLinesAr.push(newLine)
newLine={}
}


})//paragraph
})//paragraphs

cb(newLinesAr)
}
}

//in order to sue this
//TODO: this needs to be moved/used from the srt lib
Expand Down
101 changes: 44 additions & 57 deletions frontEnd/js/models/transcription.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,65 +85,52 @@ app.Transcription = Backbone.Model.extend({


function loopThroughStuff(text, cb){
// var text = app.TranscriptionsList.get(8).get("text");

var newLinesAr = []
var newLine ={}
var counter = 1

_.each(text, function(paragraphs){

_.each(paragraphs.paragraph, function(paragraph){


if(paragraph.line.length > 8){
// console.log(JSON.stringify(paragraph))
// console.log(JSON.stringify(paragraph.line.length))
// console.log("---")
var regroupLines = split(paragraph.line, 8)
// console.log(regroupLines)
//make srt lines
_.each(regroupLines, function(l){
console.log(JSON.stringify(l))
console.log("---")
newLine.id = counter;
counter+=1;
newLine.startTime = fromSecondsForSrt(l[0].startTime);
newLine.endTime = fromSecondsForSrt(l[l.length-1].endTime);
newLine.text = "";
_.each(l, function(w){
// console.log("---");
// console.log(JSON.stringify(w));
newLine.text += w.text +" ";
})//words
newLinesAr.push(newLine)
newLine={}
})//lines in regrouped lines

}else{
newLine.id = counter;
counter+=1
newLine.startTime = fromSecondsForSrt(paragraph.line[0].startTime)
newLine.endTime = fromSecondsForSrt(paragraph.line[paragraph.line.length -1].endTime)
newLine.text = ""
_.each(paragraph.line, function(word){
// console.log(word)
newLine.text += word.text +" "
})//line
// var text = app.TranscriptionsList.get(8).get("text");
var newLinesAr = []
var newLine ={}
var counter = 1
_.each(text, function(paragraphs){
_.each(paragraphs.paragraph, function(paragraph){
if(paragraph.line.length > 8){
// console.log(JSON.stringify(paragraph))
// console.log(JSON.stringify(paragraph.line.length))
// console.log("---")
var regroupLines = split(paragraph.line, 8)
// console.log(regroupLines)
//make srt lines
_.each(regroupLines, function(l){
console.log(JSON.stringify(l))
console.log("---")
newLine.id = counter;
counter+=1;
newLine.startTime = fromSecondsForSrt(l[0].startTime);
newLine.endTime = fromSecondsForSrt(l[l.length-1].endTime);
newLine.text = "";
_.each(l, function(w){
// console.log("---");
// console.log(JSON.stringify(w));
newLine.text += w.text +" ";
})//words
newLinesAr.push(newLine)
newLine={}
}






})//paragraph
})//paragraphs

cb(newLinesAr)
}
})//lines in regrouped lines
}else{
newLine.id = counter;
counter+=1
newLine.startTime = fromSecondsForSrt(paragraph.line[0].startTime)
newLine.endTime = fromSecondsForSrt(paragraph.line[paragraph.line.length -1].endTime)
newLine.text = ""
_.each(paragraph.line, function(word){
// console.log(word)
newLine.text += word.text +" "
})//line
newLinesAr.push(newLine)
newLine={}
}
})//paragraph
})//paragraphs
cb(newLinesAr)
}

//in order to sue this
//TODO: this needs to be moved/used from the srt lib
Expand Down

0 comments on commit 2f8919f

Please sign in to comment.