Skip to content

Instantly share code, notes, and snippets.

@kovacshuni
Last active August 2, 2020 22:54
Show Gist options
  • Save kovacshuni/d3bdb376b7053923cfeccebf3ee6d5b5 to your computer and use it in GitHub Desktop.
Save kovacshuni/d3bdb376b7053923cfeccebf3ee6d5b5 to your computer and use it in GitHub Desktop.
subtitles-shift-up
# Appends a new line with a - to every frame of movie subtitles to shift
# the overall position up when the tv cuts down the bottom.
#
# ruby subtitles-shift-up.rb Titanic.srt
# or
# ruby subtitles-shift-up.rb Titanic.srt UTF-8
#
# result: Titanic-shifted.srt
def addEmptyLine(inFile, outFile)
inFile.each_line do |line|
if line.strip.empty?
outFile.puts "-"
outFile.puts
else
outFile.puts line
end
end
end
inFile =
if ARGV[1].nil?
File.open(ARGV[0], "r", :encoding => ARGV[1])
else
File.open(ARGV[0], "r", :encoding => 'ISO-8859-1')
end
outFile = File.open("#{ARGV[0]}-shifted.srt", "w", :encoding => 'UTF-8')
addEmptyLine(inFile, outFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment