tools: script for outputting SimpleTags as JSON

This commit is contained in:
Moritz Bunkus 2015-12-22 19:26:07 +01:00
parent 8f4f6a639a
commit 2c032a6e9a

View File

@ -0,0 +1,24 @@
#!/usr/bin/env ruby
require "json"
require "nokogiri"
require "pp"
fail "No file name" if ARGV.empty?
input = Nokogiri::XML(`mkvextract tags #{ARGV[0]}`)
new_tags = input.css("Tags Tag").collect do |tag|
uid = tag.css("Targets TrackUID").first
next unless uid
simple_tags = tag.css("Simple").collect do |simple|
[ simple.css("Name").first.text, simple.css("String").first.text ]
end
{ uid: uid.text.to_i,
tags: Hash[ *simple_tags.sort_by(&:first).flatten ],
}
end
puts JSON.pretty_generate(new_tags)