summaryrefslogtreecommitdiff
path: root/lib/search/1337x
diff options
context:
space:
mode:
Diffstat (limited to 'lib/search/1337x')
-rwxr-xr-xlib/search/1337x67
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/search/1337x b/lib/search/1337x
new file mode 100755
index 0000000..7464fcd
--- /dev/null
+++ b/lib/search/1337x
@@ -0,0 +1,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"
+