]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/torrent/torrent.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / torrent / torrent.plugin.zsh
1 #
2 # Algorithm borrowed from http://wiki.rtorrent.org/MagnetUri and adapted to work with zsh.
3 #
4
5 function 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 }