-
Notifications
You must be signed in to change notification settings - Fork 39
/
magnetlink
executable file
·40 lines (37 loc) · 1.24 KB
/
magnetlink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
###############################################################################
#
# magnetlink
# --------------
# A utility to convert a magnet link to a .torrent file and add it to the
# watch directory so that rtorrent can find it.
#
# @author Isis Agora Lovecruft, 0x2cdb8b35 ;
# Max Gonzih,
# blog.gonzih.org/blog/2012/02/17/how-to-use-magnet-links-with-rtorrent/
# @date 21 August 2012
# @version 0.0.1
#______________________________________________________________________________
# Changelog:
###############################################################################
## set your watch directory here:
WATCH_DIRECTORY="$HOME/video/watch"
#cd $WATCH_DIRECTORY
#
#[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || echo "bad magnet link..." && \
# logger "magnetlink error: bad magnet link!" && exit 1 ;
#
#echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent" && \
# logger "magnetlink: link copied as torrent to watch directory" && \
# exit 0 ;
cd $WATCH_DIRECTORY || exit
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit
hashh=${BASH_REMATCH[1]}
if [[ "$1" =~ dn=([^&/]+) ]];then
filename=${BASH_REMATCH[1]}
else
filename=$hashh
fi
fn="meta-"$filename".torrent"
touch $fn
echo "d10:magnet-uri${#1}:${1}e" | cat > $fn