This commit is contained in:
papuSpartan 2021-01-11 04:19:27 -06:00
parent 84ed0186f6
commit 1db3eacde9

100
pirokit
View File

@ -1,68 +1,60 @@
#!/usr/bin/bash #!/usr/bin/env bash
mkdir -p $HOME/.cache/pirokit #ensures there are no accidental downloads
set -eo pipefail
if [ -z $1 ]; then baseurl="https://www.1377x.to/"
query=$(echo "" | dmenu -p "Search Torrent: ") cachedir="$HOME/.cache/dl"
else
query=$1
fi
baseurl="https://1337x.to" #get query from dmenu(later rofi)
cachedir="$HOME/.cache/pirokit" query=$(echo "" | rofi -dmenu -p "Search Torrent" | sed 's/ /+/g')
query="$(sed 's/ /+/g' <<<$query)"
#curl -s https://1337x.to/category-search/$query/Movies/1/ > $cachedir/tmp.html #setup working dir
curl -s https://1337x.to/search/$query/1/ > $cachedir/tmp.html mkdir -p $cachedir
cd $cachedir
# Get Titles curl -s $baseurl/search/$query/1/ -o tmp.html
grep -o '<a href="/torrent/.*</a>' $cachedir/tmp.html |
sed 's/<[^>]*>//g' > $cachedir/titles.bw
result_count=$(wc -l $cachedir/titles.bw | awk '{print $1}')
if [ "$result_count" -lt 1 ]; then
notify-send "😔 No Result found. Try again 🔴"
exit 0
fi
# Seeders and Leechers #get titles
grep -o '<td class="coll-2 seeds.*</td>\|<td class="coll-3 leeches.*</td>' $cachedir/tmp.html | grep -o '<a href=./torrent/.*</a>' tmp.html |
sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > $cachedir/seedleech.bw sed 's/<[^>]*>//g' > titles.bw #deletes tags
#get seeders
grep -P '<td class="coll-2 seeds">\d*</td>' tmp.html |
sed 's/<[^>]*>//g' > seeders.bw
#get leechers
grep -P '<td class="coll-3 leeches">\d*</td>' tmp.html |
sed 's/<[^>]*>//g' > leechers.bw
#get sizes
grep -P '<td class="coll-4 size mob-uploader">.*</td>' tmp.html |
sed 's/<[^>]*>//g' > sizes.bw
#get links
grep -E '/torrent/' tmp.html |
sed -E 's#.*(/torrent/.*)/">.*/#\1#' |
sed 's/td>//g' > links.bw
# Size #generates line numbers
grep -o '<td class="coll-4 size.*</td>' $cachedir/tmp.html | awk '{print NR " - "$0""}' titles.bw > titlesNumbered.bw
sed 's/<span class="seeds">.*<\/span>//g' |
sed -e 's/<[^>]*>//g' > $cachedir/size.bw
# Links #gets line number (that groupthe user selected in dmenu)
grep -E '/torrent/' $cachedir/tmp.html | LINE=$(paste -d\| titlesNumbered.bw seeders.bw leechers.bw sizes.bw |
sed -E 's#.*(/torrent/.*)/">.*/#\1#' | rofi -dmenu -i -l 25 |
sed 's/td>//g' > $cachedir/links.bw cut -d- -f1
)
suburl=$(sed "${LINE}q;d" links.bw)
url="$baseurl$suburl/"
#get page that contains magnet link
curl -s $url > tmp.html
# Clearning up some data to display #scrape magnet link
sed 's/\./ /g; s/\-/ /g' $cachedir/titles.bw | magnet=$(paste tmp.html |
sed 's/[^A-Za-z0-9 ]//g' | tr -s " " > $cachedir/tmp && mv $cachedir/tmp $cachedir/titles.bw tr -d '\n' |
sed -E 's#.*(magnet:\?xt=urn:btih:[^"]*).*#\1#'
)
awk '{print NR " - ["$0"]"}' $cachedir/size.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/size.bw deluge-console add $magnet
awk '{print "[S:"$1 ", L:"$2"]" }' $cachedir/seedleech.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/seedleech.bw
# Getting the line number #notify the user that the download has started
LINE=$(paste -d\ $cachedir/size.bw $cachedir/seedleech.bw $cachedir/titles.bw | notify-send "⬇️ download started ⬇️"
dmenu -i -l 25 |
cut -d\- -f1 |
awk '{$1=$1; print}')
url=$(head -n $LINE $cachedir/links.bw | tail -n +$LINE)
fullURL="${baseurl}${url}/"
# Requesting page for magnet link
curl -s $fullURL > $cachedir/tmp.html
magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" $cachedir/tmp.html | head -n 1)
deluge-console add "$magnet"
# Simple notification
notify-send "⬇️ Start downloading File 📁"