mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-29 06:15:24 +00:00
tools: script for outputting SimpleTags as JSON
This commit is contained in:
parent
8f4f6a639a
commit
2c032a6e9a
24
src/scripts/simpletags_to_json.rb
Executable file
24
src/scripts/simpletags_to_json.rb
Executable 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)
|
Loading…
Reference in New Issue
Block a user