Created
July 30, 2012 10:38
-
-
Save zuf/3206118 to your computer and use it in GitHub Desktop.
kdenlive dissolve transition fixer. Prints fixed project xml contents. (See kdenlive bug: http://www.kdenlive.org/mantis/view.php?id=2668)
This file contains hidden or 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 | |
require 'rubygems' | |
require 'nokogiri' | |
if ARGV.size != 1 | |
$stderr.puts "kdenlive dissolve transition fixer. Prints fixed project xml contents. (See kdenlive bug: http://www.kdenlive.org/mantis/view.php?id=2668)" | |
$stderr.puts "Usage: #{File.basename $PROGRAM_NAME} <project.kdenlive>" | |
$stderr.puts | |
#$stderr.puts "How to write output to file:" | |
#$stderr.puts " #{File.basename $PROGRAM_NAME} project.kdenlive > fixed_project.kdenlive" | |
#$stderr.puts | |
exit -1 | |
else | |
begin | |
@file_path = ARGV[0] | |
@modified = false | |
doc=Nokogiri::XML.parse(open(@file_path)) | |
producers_hash = doc.xpath("//playlist/entry").map{|e| e['producer']}.inject(Hash.new(0)) {|h,p| h[p] += 1; h } | |
producers_hash.each do |producer, count| | |
if count > 1 | |
producer_element = doc.xpath("//producer[@id='#{producer}']").first | |
doc.xpath("//playlist/entry[@producer='#{producer}']").each_with_index do |entry, index| | |
if index>0 | |
new_producer_name = "#{producer}_#{index+1}" | |
entry['producer'] = new_producer_name | |
new_producer = producer_element.dup(1) | |
new_producer['id'] = new_producer_name | |
producer_element.add_next_sibling(new_producer) | |
@modified = true | |
end | |
end | |
end | |
end | |
if @modified | |
puts doc.to_s | |
else | |
$stderr.puts "This file is already ok and not need to be fixed." | |
end | |
rescue Errno::ENOENT | |
$stderr.puts "Wrong file name or file not exits!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment