Skip to content

Instantly share code, notes, and snippets.

@jitingcn
Created January 25, 2021 21:34
Show Gist options
  • Save jitingcn/3820478aad710eae7931cfac6815c4f6 to your computer and use it in GitHub Desktop.
Save jitingcn/3820478aad710eae7931cfac6815c4f6 to your computer and use it in GitHub Desktop.
Extract translated danmu from rec.danmuji.org's recorder xml file
#!/usr/bin/env ruby
require 'nokogiri'
exit if ARGV.empty?
filename = ARGV[0]
doc = Nokogiri::XML(File.open(filename))
danmus = doc.xpath("//d").map do |el|
sec = el.attributes['p'].value.split(',')[0]
[Time.at(sec.to_f).utc.strftime("%H:%M:%S"), el.text]
end
danmus.select { |i| i[1][0] == "【" }.each { |i| puts "#{i[0]} |#{i[1]}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment