Handling magnet URIs with w3m 

Since The Pirate Bay moved from distributing torrent files to providing magnet links only, it became impractical to browse using w3m.
Here's a fix.

First, you'll need the following lines in your ~/.w3m/config file:
urimethodmap ~/.w3m/urimethodmap
cgi_bin ~/.w3m/cgi-bin

1st one points to a file that describes how to handle particular URI schemes.
2nd one points to a folder that will contain cgi scripts that w3m can handle on its own, acting as a HTTP server.

Then, you'll need to add a handler for magnet URIs in ~/.w3m/urimethodmap:
magnet: file:/cgi-bin/magnet.py?%s

And finally, a script that will handle the URIs, named ~/.w3m/cgi-bin/magnet.py:
#!/usr/bin/python
# coding=utf-8

import sys
import os
import subprocess

uri = os.environ.get('QUERY_STRING')
referer = os.environ.get('HTTP_REFERER')

if not uri:
print
print "Error: No URI"
sys.exit()

cmd_list = ("transmission-remote", "-a", uri)

subprocess.call(cmd_list)

if referer:
print "HTTP/1.1 303 See Other"
print "Location: %s" % referer

Don't forget to chmod +x ~/.w3m/cgi-bin/magnet.py, modify the cmd_list tuple to match your host, port, and authentication parameters, and you should be set. Hitting "Enter" on a magnet link should now add it to your queue.
[ view entry ] ( 17232 views ) permalink

<Back | 1 | 2 | 3 | 4 | Next> Last>>