Last active
October 15, 2017 12:43
-
-
Save itochan/57181195dafab93aef10190d1cde67ff to your computer and use it in GitHub Desktop.
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
require 'rexml/document' | |
require 'rexml/formatters/pretty' | |
# xspfjoiner.rb | |
# (C) itochan 2017 | |
# License: MIT | |
# Usage: ruby xspfjoiner.rb [xspf_file ...] | |
# Output: Merged xspf file | |
URL_LENGTH = 2048 | |
out_xspf = REXML::Document.new | |
out_xspf << REXML::XMLDecl.new('1.0', 'UTF-8') | |
out_xspf.add_element('playlist', 'version' => '1', 'xmlns' => 'http://xspf.org/ns/0/') | |
out_xspf.root.add_element('trackList') | |
ARGV.each do |file| | |
xspf = REXML::Document.new(File.open(file)) | |
track = xspf.elements['/playlist/trackList/track'] | |
out_xspf.elements['/playlist/trackList'].add_element(track) | |
end | |
pretty_formatter = REXML::Formatters::Pretty.new(0) | |
pretty_formatter.compact = true | |
pretty_formatter.width = URL_LENGTH | |
pretty_formatter.write(out_xspf, STDOUT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment