Skip to content

Instantly share code, notes, and snippets.

@mkarmona
Last active November 17, 2021 17:23
Show Gist options
  • Select an option

  • Save mkarmona/51e06dbab7c8778775815ab3858f51cb to your computer and use it in GitHub Desktop.

Select an option

Save mkarmona/51e06dbab7c8778775815ab3858f51cb to your computer and use it in GitHub Desktop.
quick dirty script to transform from gotomeeting transcript to srt format scala ammonite
import $ivy.`com.github.pathikrit::better-files:3.9.1`
import better.files._
object OpenTargets {
case class Timestamp(h: Int, m: Int, s: Int, mm: Int) {
override def toString: String = f"$h%02d:$m%02d:$s%02d,$mm%03d"
}
object SRTTransformer {
def transformTime(s: String): Seq[Timestamp] =
s.split("-").map(t => t.trim.split(":").map(_.toInt).toList match {
case secs :: Nil => Timestamp(0, 0, secs, 0)
case mins :: secs :: Nil => Timestamp(0, mins, secs, 0)
case hours :: mins :: secs :: Nil => Timestamp(hours, mins, secs, 0)
case _ => Timestamp(0, 0, 0, 0)
})
def apply(inputFile: String, outputFile: String): Unit = {
val fin = inputFile.toFile
val fout = outputFile.toFile
val conversations = fin.lines.toIterator
.filter(l => l.nonEmpty)
.grouped(3)
.map {
case who :: time :: sentence :: Nil =>
val whot = if (who.matches(".*]:")) who else s"[$who]:"
val timet = transformTime(time)
if (timet.distinct.size == 1) Nil
else timet.map(_.toString).mkString(" --> ") :: s"$whot $sentence" :: "" :: Nil
case _ => Nil
}
.filter(l => l.nonEmpty)
.zip(Stream from 1 toIterator)
.flatMap {
case (str, i) => i.toString +: str
}
fout.printLines(conversations)
}
}
}
@main
def main(inputFile: String, outputFile: String): Unit = {
OpenTargets.SRTTransformer(inputFile, outputFile)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment