torrent.plugin.zsh 344 B

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