Hacking on Empty

eat something, you'll feel better

Posts Tagged ‘automator

BitTorrent InfoHash to Magnet URI Service on OSX

leave a comment »

Some public torrent sites display on a torrent detail page an “infohash,” a SHA1 hash that uniquely identifies a Torrent, in hex format. An example would be “ffcbc1ea9ec0bc557f8fa42e673cdda0aea4d7e7.” Some sites provide a “magnet” URI that lets you download the torrent without a torrent file, possibly without a tracker. Magnet URIs for BitTorrent simply contain the infohash in a different encoding and look like this: “magnet:?xt=urn:btih:77F4D2U6YC6FK74PUQXGOPG5UCXKJV7H”

The cool thing about a magnet URI is it will let you download a torrent without using any trackers or conveniently send a torrent to someone else in a tweet or email. The client will go to the DHT and download the torrent file from other peers and not use a tracker.  Some sites don’t publish the magnet URI but do show the infohash.  For those you can convert the infohash to a magnet URI.  It won’t work for “private” torrents because most clients won’t announce their contact information to the DHT for those.

If you’re on a Mac, it’s easy to use Automator to create a Service menu item that will take an infohash selected in any application, turn it into a magnet URI, and put it back on the pasteboard. Then you just have to go to your favorite BT client and open it.  Some clients will automatically grab whats on the pasteboard for you.

  1. Open Automator and use the Service template.
  2. Add a “Run Shell Script” action from Library > Utilities
  3. Make sure “Shell: /bin/bash” and “Pass Input: to stdin” is set
  4. Paste in this code:

    python -c "import sys;import base64;sys.stdout.write('magnet:?xt=urn:btih:%s' % base64.b32encode(sys.argv[1].decode('hex')))" $@ | pbcopy

  5. Save as “To Magnet” or whatever

Now you can select an infohash in a browser or wherever (copy is not necessary,) go to the Services menu, and hit “To Magnet.”  Then just paste your magnet URI into your torrent client or wherever necessary!

    Written by hackingonempty

    2011/04/07 at 1:02 am

    Posted in tricks

    Tagged with , , , ,

    Design a site like this with WordPress.com
    Get started