blob: 04254a7d84974b450f7d8d960b22fd336057e252 (
plain) (
blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#!/bin/sh
url_1337x="https://1337x.to"
proxy_1337x="https://1337x.torrentbay.to"
menu="wmenu"
die()
{
: "${1:?}"
command -v notify-send > /dev/null &&
notify-send " 1337x" "$1"
printf "\033[31;1merr: %b\033[0m\n" "$1"
exit "${2:-1}"
}
dep_check()
{
: "${1:?}"
for dep; do
command -v "$dep" 1>/dev/null ||
die "$dep not found, please install it" 127
done
unset dep
}
get_1337x()
{
: "${1:?}"
dep_check "curl"
curl --silent -H 'Accept-Encoding: gzip,deflate, br' --compressed "${url_1337x}/$1"
}
search_1337x()
{
: "${1:?}"
get_1337x "search/$(echo "$1" | tr ' ' '+')/1/" |
grep -o "[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/[^/]*"
}
magnet_1337x()
{
: "${1:?}"
get_1337x "torrent/$1/" |
grep -om1 "magnet:?xt=urn:btih:.*announce"
}
main()
{
fetch=
select=
magnet=
out=
query=
[ -z "$WAYLAND_DISPLAY" ] &&
menu="dmenu"
if [ "$#" -gt 0 ] && [ "$1" = "-o" ]
then
out=true
shift
fi
dep_check "$menu"
curl -Is "$url_1337x" > /dev/null ||
url_1337x="$proxy_1337x"
query="${*:-$(printf "" | "$menu" -p " ")}"
[ -z "$query" ] &&
die "please enter a query"
fetch="$(search_1337x "$query")"
select="$(echo "$fetch" | sed -e's/^.*\///g' | tr '-' ' ' | "$menu" -l 25 -p " " | tr ' ' '-')"
magnet="$(magnet_1337x "$(echo "$fetch" | grep "$select")")"
[ -z "$magnet" ] &&
die "empty magnet"
if [ "$out" = true ]
then
echo "$magnet"
else
dep_check "pirowatch"
pirowatch "$magnet"
fi
}
main "$@"
|