Created
March 13, 2020 04:51
-
-
Save Freaky/4d56ce547a97946ef2e49a0122ca4257 to your computer and use it in GitHub Desktop.
Split an NZB into multiple smaller NZBs
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 | |
def usage() abort("#{$0} [base nzb] [number of new nzbs]") end | |
file = ARGV.shift | |
nzb = File.read(file) | |
num = Integer(ARGV.shift) rescue usage | |
header, nzb = nzb.split(/(?=<file)/, 2) | |
files = nzb.scan(/<file.*?<\/file>/m) | |
files_per_nzb = (files.size / num.to_f).ceil | |
1.upto(num) do |n| | |
fn = "#{File.basename(file, ".nzb")}.#{n}.nzb" | |
puts fn | |
File.open(fn, "w") do |f| | |
f.write header | |
files.shift(files_per_nzb).each do |file| | |
f.write(file) | |
end | |
f.write("</nzb>") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment