Skip to content

Instantly share code, notes, and snippets.

@passingloop
Created October 31, 2011 04:07
Show Gist options
  • Save passingloop/1326892 to your computer and use it in GitHub Desktop.
Save passingloop/1326892 to your computer and use it in GitHub Desktop.
iphone 動画変換作業用スクリプト
require 'tmpdir'
class MovieImporter
def initialize(src)
@src = src
end
def self.import(src)
MovieImporter.new(src).run
end
def run
Dir.mktmpdir do |tmpdir|
@tmpdir = tmpdir
IO.popen('osascript', 'w+') do |io|
io.puts(script)
end
end
end
private
def script
<<-EOS
tell application "QuickTime Player 7"
open "#{source_file_path}"
export document 1 to "#{target_file_path}" as iPhone with replacing
close document 1
end tell
tell application "iTunes"
set m4v to POSIX file "#{target_file_path}"
add m4v
end tell
EOS
end
def source_file_path
File.expand_path(@src)
end
def target_file_path
File.expand_path(File.basename(@src) + '.m4v', @tmpdir)
end
end
if __FILE__ == $0
ARGV.each do |movie_file|
MovieImporter.import(movie_file)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment