Ruby script to extract Renoise version info from xrns file
#!/usr/bin/env ruby | |
require 'fileutils' | |
=begin | |
An xrns file is just a zip file with a special file extension. | |
That archive holds a number of files. One of these is Song.xml. | |
This XML has a root element with an attribute named 'doc_version' | |
<RenoiseSong doc_version="63"> | |
This version seems to differ with each Renoise release. | |
This script attempts to grab and parse Song.xml, inspect that attribute, | |
and report back a Renoise version number. | |
So far it's only been run on Windows 10 and assumes you have 7z.exe | |
installed and on your path | |
There are pure-ruby zip libraries, but they can be a pain in the butt. | |
It's kinda hacky; feel free to make it super-awesome. | |
Add more doc_version => renoise_version mappings as you learn them. | |
James Britt / Neurogami | |
james@neurogami.com | |
Now go listen to my music and buy my albums for all your friends and family: | |
http://music.jamesbritt.com | |
http://music.neurogami.com | |
=end | |
RE = /(doc_version=")(.+)(".*)/ | |
TMP = '_tmp' | |
# h/t http://forum.renoise.com/index.php/topic/49519-rns-files-have-the-renoise-version-info/#entry356566 | |
VERSIONS = { | |
4 => 1.8, | |
9 => 1.9, | |
10 => 1.9.1, | |
14 => 2.0, | |
15 => 2.1, | |
21 => 2.5, | |
22 => 2.6, | |
30 => 2.7, | |
37 => 2.8, | |
54 => 3.0, | |
63 => 3.1 | |
} | |
xrns = ARGV.shift | |
if !xrns | |
warn "Usage: #{__FILE__} <path to xrns file> [-c]" | |
warn "The optional -c arg will clean up the tmp folder created when extracting the song info." | |
exit | |
end | |
unless File.exist? xrns | |
warn "Cannot find '#{xrns}'" | |
exit | |
end | |
unless xrns =~ /\.xrns$/ | |
warn "'#{xrns}' is not an xrns file" | |
exit | |
end | |
unless File.exist? TMP | |
Dir.mkdir TMP | |
end | |
FileUtils.cp xrns, TMP | |
Dir.chdir(TMP) do | |
if File.exist? 'Song.xml' | |
FileUtils.rm_rf 'Song.xml' | |
end | |
cmd = %~7za.exe x "../#{xrns}" Song.xml ~ | |
warn cmd | |
warn `#{cmd}` | |
lines = IO.readlines 'Song.xml' | |
root = lines[1] | |
m = RE.match root | |
renoise_version = VERSIONS[m[2]] | |
puts '.' * 90 | |
puts | |
if renoise_version | |
puts "'#{xrns}' was made using Renoise #{renoise_version}" | |
else | |
puts "Sorry. Do not have any info for doc_version #{m[2]}" | |
end | |
end | |
if ARGV.first =~ /-c/ | |
FileUtils.rm_rf TMP | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment