summaryrefslogtreecommitdiff
path: root/lib/search/1337x
blob: 7464fcdadd0f58a85cfb34a8899cd0bb4dd97f08 (plain)
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
#! /bin/bash

source ./util/menu/deasy
source ./util/notify

CACHEDIR="$HOME/.cache/notflix-mod"
[ -d "$CACHEDIR" ] || mkdir -p "$CACHEDIR"

BASEURL='https://1337x.to'

query="$(echo $(deasy "$1" 'Search 1337x') | sed 's/ /+/g')"
curl -s "$BASEURL/search/$query/1/" > "$CACHEDIR/tmp.html"

# Titles
grep -o '<a href="/torrent/.*</a>' "$CACHEDIR/tmp.html" \
    | sed 's/<[^>]*>//g' > "$CACHEDIR/titles.bw"

# Void Check
count=$(wc -l "$CACHEDIR/titles.bw" | awk '{print $1}')
[ $count -lt 1 ] && notify 'Empty Response' && exit 0

# Seeders & Leechers
grep -o '<td class="coll-2 seeds.*</td>\|<td class="coll-3 leeches.*</td>' "$CACHEDIR/tmp.html" \
    | sed 's/<[^>]*>//g' \
    | sed 'N;s/\n/ /' > "$CACHEDIR/seedleech.bw"

# Size
grep -o '<td class="coll-4 size.*</td>' "$CACHEDIR/tmp.html" \
    | sed 's/<span class="seeds">.*<\/span>//g' \
    | sed -e 's/<[^>]*>//g' > "$CACHEDIR/size.bw"

# Links
grep -E '/torrent/' "$CACHEDIR/tmp.html" \
    | sed -E 's#.*(/torrent/.*)/">.*/#\1#' \
    | sed 's/td>//g' > "$CACHEDIR/links.bw"

# Cleanup
sed 's/\./ /g; s/\-/ /g' "$CACHEDIR/titles.bw" \
    | sed 's/[^A-Za-z0-9 ]//g' \
    | tr -s ' ' > "$CACHEDIR/tmp" && mv "$CACHEDIR/tmp" "$CACHEDIR/titles.bw"

awk '{print NR " - ["$0"]"}' "$CACHEDIR/size.bw" > "$CACHEDIR/tmp" && mv "$CACHEDIR/tmp" "$CACHEDIR/size.bw"
awk '{print "[S:"$1 ", L:"$2"]" }' "$CACHEDIR/seedleech.bw" > "$CACHEDIR/tmp" && mv "$CACHEDIR/tmp" "$CACHEDIR/seedleech.bw"

# Line
line="$(paste -d\   "$CACHEDIR/size.bw" "$CACHEDIR/seedleech.bw" "$CACHEDIR/titles.bw" \
    | dmenu -i \
            -l 20 \
            -p 'Select Torrent:' \
            -nb '#ffffff' \
            -nf '#000080' \
            -sb '#000080' \
            -sf '#ffffff' \
    | cut -d\- -f1 \
    | awk '{$1=$1; print}')"
[ -z "$line" ] && exit 0

# 1. Magnet Page
tailurl="$(head -n $line "$CACHEDIR/links.bw" | tail -n +$line)"
curl -s "${BASEURL}${tailurl}/" > "$CACHEDIR/tmp.html"

# 2. Magnet Link
magnet="$(grep -Po 'magnet:\?xt=urn:btih:[a-zA-Z0-9]*' "$CACHEDIR/tmp.html" | head -n 1)"

# 3. Magnet Action
./rmt-action 'Torrent' "$magnet"