Skip to content

Instantly share code, notes, and snippets.

@theirix
Created February 8, 2012 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theirix/1768296 to your computer and use it in GitHub Desktop.
Save theirix/1768296 to your computer and use it in GitHub Desktop.
magnet2uri [PROPER]
#!/usr/bin/env ruby
require 'uri'
magnet = URI.unescape ARGV.first
benc = "d10:magnet-uri#{magnet.size}:#{magnet}e"
exit(1) unless magnet =~ /xt=urn:btih:([a-zA-Z0-9]+)/
File.open("meta-#{$1}.torrent", 'w') { |f| f.write benc }
#[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
#echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"
# vim: ft=ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment