From 2f8919f0ffb38be67368914a11d003c62c49ecc7 Mon Sep 17 00:00:00 2001 From: pietrop Date: Wed, 28 Sep 2016 12:45:15 -0400 Subject: [PATCH] split srt lines into 8 words max --- .../demo/frontEnd/js/models/transcription.js | 58 +++++++--- frontEnd/js/models/transcription.js | 101 ++++++++---------- 2 files changed, 87 insertions(+), 72 deletions(-) diff --git a/docs/public/demo/frontEnd/js/models/transcription.js b/docs/public/demo/frontEnd/js/models/transcription.js index f51a431..50df64f 100755 --- a/docs/public/demo/frontEnd/js/models/transcription.js +++ b/docs/public/demo/frontEnd/js/models/transcription.js @@ -83,9 +83,7 @@ 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 = [] @@ -93,24 +91,54 @@ app.Transcription = Backbone.Model.extend({ 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 diff --git a/frontEnd/js/models/transcription.js b/frontEnd/js/models/transcription.js index 3ba551a..cc238a5 100755 --- a/frontEnd/js/models/transcription.js +++ b/frontEnd/js/models/transcription.js @@ -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