Source

utils / fix_subtitle.rb

Full commit
#!/usr/bin/env ruby
# coding: utf-8
#
# name:      code/utils/fix_subtitle.rb
# author:    Xu Xiaodong <xxdlhy@gmail.com>
# license:   GPL
# created:   2011 Dec 04
# modified:  2011 Dec 04
#

def rename_file
  old_name = Dir['*.srt'][0]
  new_name = File.basename(Dir['*.mkv'][0], '.mkv') + '.chs.srt'
  puts "#{old_name} renamed to #{new_name}" if File.rename(old_name, new_name)
end

def convert_encode
  srt = Dir['*.srt'][0]
  if %x|file #{srt}| =~ /UTF-16/
    system("iconv -f UTF-16 -t UTF-8 -o #{srt}.out #{srt}")
  end
end

if __FILE__ == $0
  rename_file
  convert_encode
end

# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=ruby