From 2c032a6e9af08870e1abf11db495ac9f842281d9 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 22 Dec 2015 19:26:07 +0100 Subject: [PATCH] tools: script for outputting SimpleTags as JSON --- src/scripts/simpletags_to_json.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 src/scripts/simpletags_to_json.rb diff --git a/src/scripts/simpletags_to_json.rb b/src/scripts/simpletags_to_json.rb new file mode 100755 index 000000000..46a664ef5 --- /dev/null +++ b/src/scripts/simpletags_to_json.rb @@ -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)