-
-
Save hinc/6b39f53fbd99fe6460abe39bc5d34a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Requires that you have ./bin/dcpTool from https://sourceforge.net/projects/dcptool/ | |
require 'rubygems' | |
require 'bundler/setup' | |
require 'nokogiri' | |
input_camera_model = ARGV[0] || "LEICA Q (Typ 116)" | |
output_camera_model = ARGV[1] || "LEICA M10" | |
input_dir = ARGV[2] || "./input" | |
output_dir = ARGV[3] || "./output" | |
def convert_profile_name(profile_name, input_camera_model, output_camera_model) | |
File.basename(profile_name.gsub(/#{input_camera_model.gsub(/\(/, "\\(").gsub(/\)/, "\\)")}/, output_camera_model), ".dcp") | |
end | |
def replace_camera_model(xml_profile_filename, output_camera_model) | |
profile_doc = Nokogiri::XML(File.read(xml_profile_filename)) | |
profile_doc.xpath('//UniqueCameraModelRestriction').first.content = output_camera_model | |
File.open(xml_profile_filename, "w+") { |file| file.write(profile_doc.to_xml) } | |
end | |
Dir.entries(input_dir).reject { |file| file =~ /^(\.|\.\.)$/ }.each do |existing_profile| | |
converted_profile = convert_profile_name(existing_profile, input_camera_model, output_camera_model) | |
existing_dcp_filename = File.join(input_dir, existing_profile) | |
xml_filename = "#{File.join(output_dir, converted_profile)}.xml" | |
decompile_command = "./bin/dcpTool -d '#{existing_dcp_filename}' '#{xml_filename}'" | |
puts "Decompiling #{existing_dcp_filename} into XML" | |
`#{decompile_command}` | |
puts "Replacing camera model: #{input_camera_model} -> #{output_camera_model}" | |
replace_camera_model(xml_filename, output_camera_model) | |
converted_dcp_filename = "#{File.join(output_dir, converted_profile)}.dcp" | |
recompile_command = "./bin/dcpTool -c '#{xml_filename}' '#{converted_dcp_filename}'" | |
puts "Recompiling XML into #{converted_dcp_filename}" | |
`#{recompile_command}` | |
File.delete(xml_filename) | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment