Skip to content

Instantly share code, notes, and snippets.

@zuf
Created July 30, 2012 10:38
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 zuf/3206118 to your computer and use it in GitHub Desktop.
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)
#!/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