timestamp,name,text,initials
2010-04-18 08:01:54,PIT,Lewis last car's coming into position now.,PW
2010-04-18 08:02:05,PIT,All cars in position.,PW
2010-04-18 08:02:59,COM,0802: The race has started,CM
My first thought was to just format it in Excel but quickly got frustrated with the way it handles dates/time, so instead uploaded it to Google Spreadsheet. Shown below is how the same data appears:
Having played around with the timed-text XML format I knew the goal was to convert each row into something like (of course wrapping with the obligatory XML header and footer):
<p style="s1" begin="00:00:00" id="p1" end="00:00:11">PIT: Lewis last car's coming into position now.</p>
Previously I've played with Google Apps Script to produce an events booking systems, which uses various components of Google Apps (spreadsheet, calendar, contacts and site), so it made sense to use the power of Scripts for timed text. A couple of hours later I came up with this spreadsheet (once you open it click File –> Make a copy to allow you to edit).
On the first sheet you can import your timed data (it doesn't have to be *.csv, it only has to be readable by Google Spreadsheet), and then clicking 'Subtitle Gen –> Timed Data to XML' on the XMLOut sheet it generates and timed text XML.
Below is the main function which is doing most of the work, the comments indicating what's going on:
01 | function writeTTXML() { |
02 | var ss = SpreadsheetApp.getActiveSpreadsheet(); |
03 | var dataSheet = ss.getSheets()[0]; |
04 | var data = getRowsData(dataSheet); |
05 | var sheet = ss.getSheetByName( "XMLOut" ) || ss.insertSheet( "XMLOut" ); |
09 | var startTime = data[0].timestamp; |
10 | for ( var i = 0; i < (data.length-1); ++i) { |
12 | var nextRow = data[i+1]; |
15 | var begin = Utilities.formatDate( new Date(row.timestamp-startTime), "GMT" , "HH:mm:ss" ); |
16 | var end = Utilities.formatDate( new Date(nextRow.timestamp-startTime), "GMT" , "HH:mm:ss" ); |
18 | var str = "<p style=\"s1\" begin=\"" +begin+ "\" id=\"p" +row.rowNumber+ "\" end=\"" +end+ "\">" +row.name+ ": " +row.text+ "</p>" ;; |
20 | var out = sheet.getRange(row.rowNumber+1, 1).setValue(str); |
22 | var lastRow = sheet.getLastRow()+1; |
24 | var out = sheet.getRange(lastRow, 1).setValue( "</div></body></tt>" ); |
If your timed data has different headers you can tweak this by clicking 'Tools –> Script –> Script editor …' and changing how the str
on line 18 is constructed.
I'm the first one to admit that this spreadsheet isn't the most user friendly and it only includes the tt-XML format, but hopefully there is enough structure for you to go, play and expand (if you do please use the post comments to share your findings)
Комментариев нет:
Отправить комментарий