Skip to content

Instantly share code, notes, and snippets.

@torque
Created June 28, 2012 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torque/3009235 to your computer and use it in GitHub Desktop.
Save torque/3009235 to your computer and use it in GitHub Desktop.
Matroska mux script for Koi Kaze
#!/usr/bin/env ruby
# Usage: ./mux.rb 1 "Spring Breeze" rel
require 'zlib'
require 'fileutils'
epnum = "%02d" % ARGV[0].to_i;
epraw = File.expand_path((Dir["Koi_Kaze_-_Ep#{epnum}_10bit_Raw*.mkv"])[0]) # Get the raw for the main episode
chiraw = File.expand_path((Dir["Koi_Kaze_-_Ex#{epnum}_10bit_Raw*.mkv"])[0]) # Get the raw for Chidori
chapters = File.expand_path("Chapters/Koi Kaze #{epnum}.xml")
fonts = Dir['fonts/*.ttf','fonts/*.otf'] # j-j-j-jam all of the fonts in
subs = File.expand_path("Koi Kaze - #{epnum}.ass") # SUBTITLES ARE IMPORTANT
title = "Koi Kaze - #{epnum} - #{ARGV[1]}"
case ARGV[2]
when "rel"
out = File.expand_path("[drawn-reality] Koi Kaze - #{epnum}")
patchfile = File.expand_path("Koi Kaze - #{epnum} raw-QC patch.xdelta3")
else
out = File.expand_path("Koi Kaze - #{epnum} QC")
patchfile = File.expand_path("Koi Kaze - #{epnum} raw-QC patch.xdelta3")
end
mux = "\"mkvmerge\" -o \"#{out}\" --default-track \"0:yes\" --forced-track \"0:no\" --language \"1:jpn\" --default-track \"1:yes\" --forced-track \"1:no\" -a 1 -d 0 -S --no-global-tags --no-chapters \"(\" \"#{epraw}\" \")\" -a 1 -d 0 -S -T --no-global-tags --no-chapters + \"(\" \"#{chiraw}\" \")\" --language \"0:eng\" --track-name \"0:English Styled Subs\" --default-track \"0:yes\" --forced-track \"0:no\" -s 0 -D -A -T --no-global-tags --no-chapters \"(\" \"#{subs}\" \")\" --track-order \"0:0,0:1,2:0\" --append-to \"1:0:0:0,1:1:0:1\""
fonts.each { |fon| # Attachments
mux << " --attachment-mime-type \"application/x-truetype-font\" --attachment-name \"#{fon[6..-1]}\" --attach-file \"#{File.expand_path("#{fon}")}\""
}
mux << " --title \"\" --chapters \"#{chapters}\""
muxing = IO.popen(mux)
while (status = muxing.gets)
puts status
end
old = out
crc = 0
file = File.open(out,'rb')
buffer = 65536 # magic numbers
while (true) do
str = file.read(buffer)
break if (!str)
crc = Zlib.crc32(str, crc)
end
#something about unsigned ints
crc = (crc%(2**32)) if (crc < 0)
out += " [%08X].mkv" % [crc]
FileUtils.mv(old,out)
patch = "xdelta3 -e9vI 0 -s \"#{File.basename(epraw)}\" \"#{File.basename(out)}\" \"#{patchfile}\""
patching = IO.popen(patch)
while (status = patching.gets)
puts status
end
pwd = Dir.pwd
case ARGV[2]
when "rel"
puts "not doing anything"
else
FileUtils.mv(File.basename(out),"#{pwd}/../QC/#{File.basename(out)}")
FileUtils.mv(File.basename(patchfile),"#{pwd}/../QC/#{File.basename(patchfile)}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment