Created
January 25, 2021 21:34
-
-
Save jitingcn/3820478aad710eae7931cfac6815c4f6 to your computer and use it in GitHub Desktop.
Extract translated danmu from rec.danmuji.org's recorder xml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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