| 1 | #!/usr/bin/bash |
| 2 | |
| 3 | mkdir -p $HOME/.cache/pirokit |
| 4 | |
| 5 | if [ -z $1 ]; then |
| 6 | query=$(echo "" | dmenu -p "Search Torrent: ") |
| 7 | else |
| 8 | query=$1 |
| 9 | fi |
| 10 | |
| 11 | baseurl="https://1337x.to" |
| 12 | cachedir="$HOME/.cache/pirokit" |
| 13 | query="$(sed 's/ /+/g' <<<$query)" |
| 14 | |
| 15 | #curl -s https://1337x.to/category-search/$query/Movies/1/ > $cachedir/tmp.html |
| 16 | curl -s https://1337x.to/search/$query/1/ > $cachedir/tmp.html |
| 17 | |
| 18 | # Get Titles |
| 19 | grep -o '<a href="/torrent/.*</a>' $cachedir/tmp.html | |
| 20 | sed 's/<[^>]*>//g' > $cachedir/titles.bw |
| 21 | |
| 22 | result_count=$(wc -l $cachedir/titles.bw | awk '{print $1}') |
| 23 | if [ "$result_count" -lt 1 ]; then |
| 24 | notify-send "😔 No Result found. Try again 🔴" |
| 25 | exit 0 |
| 26 | fi |
| 27 | |
| 28 | |
| 29 | # Seeders and Leechers |
| 30 | grep -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 |
| 34 | grep -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 |
| 39 | grep -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 |
| 46 | sed '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 | |
| 49 | awk '{print NR " - ["$0"]"}' $cachedir/size.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/size.bw |
| 50 | awk '{print "[S:"$1 ", L:"$2"]" }' $cachedir/seedleech.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/seedleech.bw |
| 51 | |
| 52 | # Getting the line number |
| 53 | LINE=$(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 | |
| 58 | url=$(head -n $LINE $cachedir/links.bw | tail -n +$LINE) |
| 59 | fullURL="${baseurl}${url}/" |
| 60 | |
| 61 | # Requesting page for magnet link |
| 62 | curl -s $fullURL > $cachedir/tmp.html |
| 63 | magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" $cachedir/tmp.html | head -n 1) |
| 64 | |
| 65 | transadd "$magnet" |
| 66 | |
| 67 | # Simple notification |
| 68 | notify-send "⬇️ Start downloading File 📁" |