lib/handbrake/cli.rb in handbrake-0.2.1 vs lib/handbrake/cli.rb in handbrake-0.3.0
- old
+ new
@@ -66,20 +66,23 @@
# @option options [Boolean,:ignore] :overwrite (true) determines
# the behavior if the desired output file already exists. If
# `true`, the file is replaced. If `false`, an exception is
# thrown. If `:ignore`, the file is skipped; i.e., HandBrakeCLI
# is not invoked.
- # @option options [Boolean] :atomic (false) provides a
+ # @option options [Boolean, String] :atomic (false) provides a
# pseudo-atomic mode for transcoded output. If true, the
# transcode will go into a temporary file and only be copied to
- # the specified filename if it completes. The temporary filename
- # is the target filename with `.handbraking` inserted before the
- # extension. Any `:overwrite` checking will be applied to the
- # target filename both before and after the transcode happens
- # (the temporary file will always be overwritten). This option
- # is intended to aid in writing automatically resumable batch
- # scripts.
+ # the specified filename if it completes. If the value is
+ # literally `true`, the temporary filename is the target
+ # filename with `.handbraking` inserted before the extension. If
+ # the value is a string, it is interpreted as a path; the
+ # temporary file is written to this path instead of in the
+ # ultimate target directory. Any `:overwrite` checking will be
+ # applied to the target filename both before and after the
+ # transcode happens (the temporary file will always be
+ # overwritten). This option is intended to aid in writing
+ # automatically resumable batch scripts.
#
# @return [void]
def output(filename, options={})
overwrite = options.delete :overwrite
case overwrite
@@ -96,14 +99,19 @@
raise "Unsupported value for :overwrite: #{overwrite.inspect}"
end
atomic = options.delete :atomic
interim_filename =
- if atomic
+ case atomic
+ when true
partial_filename(filename)
- else
+ when String
+ partial_filename(File.join(atomic, File.basename(filename)))
+ when false, nil
filename
+ else
+ fail "Unsupported value for :atomic: #{atomic.inspect}"
end
unless options.empty?
raise "Unknown options for output: #{options.keys.inspect}"
end
@@ -125,11 +133,11 @@
true
end
else
true
end
- FileUtils.mv interim_filename, filename if replace
+ FileUtils.mv(interim_filename, filename, :verbose => trace?) if replace
end
end
def partial_filename(name)
if File.basename(name).index '.'
@@ -145,17 +153,26 @@
# Performs a title scan. Unlike HandBrakeCLI, if you do not
# specify a title, this method will return information for all
# titles. (HandBrakeCLI defaults to only returning information for
# title 1.)
#
- # @return [Titles]
+ # @return [Disc,Title] a {Disc} when scanning for all titles, or a
+ # {Title} when scanning for one title.
def scan
- if arguments.include?('--title')
- result = run('--scan')
- Titles.from_output(result.output)
+ one_title = arguments.include?('--title')
+
+ args = %w(--scan)
+ unless one_title
+ args.unshift('--title', '0')
+ end
+
+ disc = Disc.from_output(run(*args).output)
+
+ if one_title
+ disc.titles.values.first
else
- title(0).scan
+ disc
end
end
##
# Checks to see if the `HandBrakeCLI` instance designated by
@@ -262,10 +279,10 @@
cmd = "'" + arguments.unshift(@cli.bin_path).join("' '") + "' 2>&1"
$stderr.puts "Spawning HandBrakeCLI using #{cmd.inspect}" if @cli.trace?
IO.popen(cmd) do |io|
- while line = io.gets
+ while line = io.read(60)
output << line
$stderr.write(line) if @cli.trace?
end
end
RunnerResult.new(output, $?)