Skip to content

Instantly share code, notes, and snippets.

@exegeteio
Created May 4, 2023 22:41
Show Gist options
  • Save exegeteio/c8d9337e2518b4be79d3678879219b2e to your computer and use it in GitHub Desktop.
Save exegeteio/c8d9337e2518b4be79d3678879219b2e to your computer and use it in GitHub Desktop.
SRT Formatter for Matty Twoshoes on twitch.
#!/usr/bin/env ruby
require "csv"
# Going to store each line into an array.
output = []
# Loop over input from STDIN
ARGF.each do |line|
# Removes newlines and such.
line.chomp!
# If a blank line, output and continue skip the rest.
if line == ""
puts (output[0..2] + [output[3..].join(" ")]).to_csv
output = []
next
end
# Process timestamps if this matches.
if line.match(/ --> /)
output += line.split(/ --> /)
next
end
# Append to the array.
output << line
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment