Commits

Xu Xiaodong  committed 16fc091

add fix_subtitle.rb

  • Participants
  • Parent commits f1d082d

Comments (0)

Files changed (1)

File fix_subtitle.rb

+#!/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