#!/usr/bin/bash
# 1337x.to, if this domain is blocked for you try to use 1377x.to or 1337xx.to.
clear
mkdir -p $HOME/.cache/1337x
query=$*
baseurl="https://1337x.to"
cachedir="$HOME/.cache/1337x"
query="$(sed 's/ /+/g' <<<$query)"
# This is where default database can be chaned ie. Television, Movies, Music etc.
# See https://1337x.to/ for a list of query strings.
# curl -s https://www.1377x.to/category-search/$query/TV/1/ > $cachedir/tmp.html
# curl -s https://www.1377x.to/category-search/$query/Music/1/ > $cachedir/tmp.html
curl -s https://1337x.to/category-search/$query/Movies/1/ > $cachedir/tmp.html
# Get Titles
grep -o '' $cachedir/tmp.html |
sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > $cachedir/seedleech.bw
# Size
grep -o '
.*<\/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
# Clearning up some data to display.
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
# Getting the line number.
LINE=$(paste -d\ $cachedir/size.bw $cachedir/seedleech.bw $cachedir/titles.bw |
fzf -i |
cut -d\- -f1 |
awk '{$1=$1; print}')
url=$(head -n $LINE $cachedir/links.bw 2> /dev/null | tail -n +$LINE 2> /dev/null)
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 2> /dev/null)
if [[ $magnet == '' ]]; then
exit 0
fi
# Default username:password passed by default.
transmission-remote -n transmission:transmission --add "$magnet" && notify-send "Torrent added to queue."
|