Krolyxon
Commit 4cc2e43

Branches

Refs →

dotfiles-x11.localbinpirokit

68 lines · 2.0 KB · Bourne Again Shell (bash)

1#!/usr/bin/bash
2
3mkdir -p $HOME/.cache/pirokit
4
5if [ -z $1 ]; then
6 query=$(echo "" | dmenu -p "Search Torrent: ")
7else
8 query=$1
9fi
10
11baseurl="https://1337x.to"
12cachedir="$HOME/.cache/pirokit"
13query="$(sed 's/ /+/g' <<<$query)"
14
15#curl -s https://1337x.to/category-search/$query/Movies/1/ > $cachedir/tmp.html
16curl -s https://1337x.to/search/$query/1/ > $cachedir/tmp.html
17
18# Get Titles
19grep -o '<a href="/torrent/.*</a>' $cachedir/tmp.html |
20 sed 's/<[^>]*>//g' > $cachedir/titles.bw
21
22result_count=$(wc -l $cachedir/titles.bw | awk '{print $1}')
23if [ "$result_count" -lt 1 ]; then
24 notify-send "😔 No Result found. Try again 🔴"
25 exit 0
26fi
27
28
29# Seeders and Leechers
30grep -o '<td class="coll-2 seeds.*</td>\|<td class="coll-3 leeches.*</td>' $cachedir/tmp.html |
31 sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > $cachedir/seedleech.bw
32
33# Size
34grep -o '<td class="coll-4 size.*</td>' $cachedir/tmp.html |
35 sed 's/<span class="seeds">.*<\/span>//g' |
36 sed -e 's/<[^>]*>//g' > $cachedir/size.bw
37
38# Links
39grep -E '/torrent/' $cachedir/tmp.html |
40 sed -E 's#.*(/torrent/.*)/">.*/#\1#' |
41 sed 's/td>//g' > $cachedir/links.bw
42
43
44
45# Clearning up some data to display
46sed 's/\./ /g; s/\-/ /g' $cachedir/titles.bw |
47 sed 's/[^A-Za-z0-9 ]//g' | tr -s " " > $cachedir/tmp && mv $cachedir/tmp $cachedir/titles.bw
48
49awk '{print NR " - ["$0"]"}' $cachedir/size.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/size.bw
50awk '{print "[S:"$1 ", L:"$2"]" }' $cachedir/seedleech.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/seedleech.bw
51
52# Getting the line number
53LINE=$(paste -d\ $cachedir/size.bw $cachedir/seedleech.bw $cachedir/titles.bw |
54 dmenu -i -l 25 |
55 cut -d\- -f1 |
56 awk '{$1=$1; print}')
57
58url=$(head -n $LINE $cachedir/links.bw | tail -n +$LINE)
59fullURL="${baseurl}${url}/"
60
61# Requesting page for magnet link
62curl -s $fullURL > $cachedir/tmp.html
63magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" $cachedir/tmp.html | head -n 1)
64
65transadd "$magnet"
66
67# Simple notification
68notify-send "⬇️ Start downloading File 📁"