torrent.plugin.zsh
344 bytes
1#
2# Algorithm borrowed from http://wiki.rtorrent.org/MagnetUri and adapted to work with zsh.
3#
4
5function magnet_to_torrent() {
6 [[ "$1" =~ xt=urn:btih:([^\&/]+) ]] || return 1
7
8 hashh=${match[1]}
9
10 if [[ "$1" =~ dn=([^\&/]+) ]];then
11 filename=${match[1]}
12 else
13 filename=$hashh
14 fi
15
16 echo "d10:magnet-uri${#1}:${1}e" > "$filename.torrent"
17}