Skip to content

Instantly share code, notes, and snippets.

@dyladan
Created March 8, 2013 22:11
Show Gist options
  • Save dyladan/5120324 to your computer and use it in GitHub Desktop.
Save dyladan/5120324 to your computer and use it in GitHub Desktop.
sorts torrent files into folder by tracker. Just put all your files in a folder called torrents and run this file one level above that folder.
require 'bencode'
require 'fileutils'
Dir.glob('torrents/*.torrent') do |item|
if File.directory?(item)
next
end
tracker = BEncode.load_file(item)["announce"].gsub("http://", "").split('/')[0]
if tracker == nil
next
end
Dir.mkdir("torrents/"+tracker) unless File.exists?("torrents" + tracker)
FileUtils.mv(item, "torrents/" + tracker + "/" + item.split('/')[-1])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment