summaryrefslogtreecommitdiff
path: root/plugins/torrent/torrent.plugin.zsh
diff options
context:
space:
mode:
authorRobby Russell <robby@planetargon.com>2013-04-12 06:16:39 -0700
committerRobby Russell <robby@planetargon.com>2013-04-12 06:16:39 -0700
commitd4fb254d28a6621d08cfed124ad321ce18f3ad03 (patch)
tree4ad74c3a3212b8ff396e0f03d444ba80df459b13 /plugins/torrent/torrent.plugin.zsh
parent631da358a59026adec14a00c549ab6fa745bc400 (diff)
parent3362899493662ae8295521bc8fa8eccec79c7550 (diff)
downloadzsh-d4fb254d28a6621d08cfed124ad321ce18f3ad03.tar.gz
zsh-d4fb254d28a6621d08cfed124ad321ce18f3ad03.tar.bz2
zsh-d4fb254d28a6621d08cfed124ad321ce18f3ad03.zip
Merge pull request #1532 from ryanneufeld/torrent_tools
Adding torrent tools plugin.
Diffstat (limited to 'plugins/torrent/torrent.plugin.zsh')
-rw-r--r--plugins/torrent/torrent.plugin.zsh17
1 files changed, 17 insertions, 0 deletions
diff --git a/plugins/torrent/torrent.plugin.zsh b/plugins/torrent/torrent.plugin.zsh
new file mode 100644
index 000000000..656e337de
--- /dev/null
+++ b/plugins/torrent/torrent.plugin.zsh
@@ -0,0 +1,17 @@
+#
+# Algorithm borrowed from http://wiki.rtorrent.org/MagnetUri and adapted to work with zsh.
+#
+
+function magnet_to_torrent() {
+ [[ "$1" =~ xt=urn:btih:([^\&/]+) ]] || return 1
+
+ hashh=${match[1]}
+
+ if [[ "$1" =~ dn=([^\&/]+) ]];then
+ filename=${match[1]}
+ else
+ filename=$hashh
+ fi
+
+ echo "d10:magnet-uri${#1}:${1}e" > "$filename.torrent"
+} \ No newline at end of file