Last active
April 22, 2021 12:38
-
-
Save donnaken15/cc3f5a4370f46225a0bb41b0e95e448f to your computer and use it in GitHub Desktop.
Generate subtitles file in Drive from current (Excel) spreadsheet, formatted like https://docs.google.com/spreadsheets/d/1nzDgRlGuB6SY2cvfsJLH7u3_G0Ouucm-l8xsCzmfukw/edit?usp=sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SRTstamp(_time) { | |
if (_time !== undefined) | |
{ | |
if (_time.lastIndexOf(":") < 4) | |
_time = "00:"+_time | |
_time = _time.replace(".",",")+"0" | |
return _time | |
} | |
else throw("Invalid argument") | |
} | |
function genSubs() { | |
var final = "" | |
var capnum = 0 | |
var subs = SpreadsheetApp.getActiveSheet(); | |
cont = subs.getDataRange().getValues(); | |
cont.forEach(function (row) { | |
if (capnum > 0) | |
final += capnum.toString()+"\n"+(SRTstamp(row[0])+" --> "+SRTstamp(row[1]))+"\n"+row[2]+"\n\n"; | |
capnum++; | |
}); | |
final += "\n" | |
var newF = DriveApp.createFile("Captiongen"+Date.now()+"_"+subs.getSheetName()+".srt".toString(),final); | |
SpreadsheetApp.getUi().alert("File created at:\n" + newF.getUrl()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment