public
Created

kdenlive dissolve transition fixer. Prints fixed project xml contents. (See kdenlive bug: http://www.kdenlive.org/mantis/view.php?id=2668)

  • Download Gist
kdenlive-transition-fixer.rb
Ruby
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 37 38 39 40 41 42 43 44 45 46 47 48
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.