1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/ruby

require 'uuidtools'
require 'fileutils'

source = File.expand_path(ARGV.shift)
target = File.expand_path(ARGV.shift)

tmp_video       = "/tmp/#{UUIDTools::UUID.random_create.to_s}"
tmp_source_name = UUIDTools::UUID.random_create.to_s
tmp_source      = "#{tmp_video}/#{tmp_source_name}/#{File.basename(source)}"
tmp_target      = "#{tmp_video}/%#{tmp_source_name}/#{File.basename(source)}"

FileUtils.mkpath(tmp_source)
FileUtils.ln_s(target, File.dirname(tmp_target))

for file in Dir[source + '/*']
  if File.basename(file) != 'marks'
    FileUtils.ln_s(File.expand_path(file), tmp_source + '/' + File.basename(file))
  end
end

File.open(tmp_source + '/marks', 'w') do |marks|
  while mark = ARGV.shift do
    marks.puts(mark)
  end
end

puts `vdr -v '#{tmp_video}' --edit '#{tmp_source}'`

for file in Dir[tmp_target + '/*']
  FileUtils.mv(file, File.dirname(tmp_target))
end

FileUtils.rm_rf(tmp_target)
FileUtils.rm_rf(tmp_video)