update to beta 0.7
+colored output
+duplicated downloads are now highlighted
Code:
#!/bin/bash
#
# GetTorrent version beta 0.7
#
#
#
######################################################################################################
## default search category [all|audio|games|video|tv|unsorted|software]
CATEGORY=Audio
## default browser [links|lynx|w3m]
BROWSER=lynx
## default download dir
TORRENTDIR=$HOME/torrent
## number of printed torrents
NR=20
########################################################################################################
tmp="/tmp/gettorrent.tmp"
tmp2="/tmp/gettorrent2.tmp"
log="$TORRENTDIR/gettorrent.log"
version="beta 0.7"
DATE=$(date +%Y.%m.%d@%H:%M:%S)
match=`awk -F/ 'BEGIN {n='$NR'+1;} {if (n < FNR) exit;}/torrent/{printf "%s", $3" "} ' $tmp2`
## functions
matcher () {
for C in $match; do
if [ -n "`grep $C $log`" ]; then
sed -i '/'$C'/s/8%/1/g;' $tmp2
else
sed -i '/'$C'/s/8%/2/g;' $tmp2
fi
done
}
spinner () {
echo -ne "\033[u"
while [ $[i+=1] != 8 ]; do
for I in "-" "\\" "|" "/"; do
echo -ne "\033[u$I"
sleep .03
done
done
}
runner () {
echo -ne "\033[s"
i=1
while [ $i == 1 ]; do
for I in "D" "o" "w" "n" "l" "o" "a" "d" "e" "d" " " "f" "i" "l" "e" "s"\
" " "w" "i" "t" "h" " " "G" "e" "t" "T" "o" "r" "r" "e" "n" "t"": " ;
do
echo -ne "\033[u$I"
sleep .01
echo -ne "\033[s"
i=0
done
done
}
## check torrentdir and logfile
if [ -d $TORRENTDIR ]; then
touch $log
else
mkdir $TORRENTDIR
touch $log
fi
## check browser
for B in $BROWSER; do
case $B in
links) brw='links -source' ;;
lynx) brw='lynx -source' ;;
w3m) brw='w3m -dump_source' ;;
esac
done
## check category
if [ -n "$2" ]; then
CATEGORY=$2
fi
for C in $CATEGORY; do
case $C in
all|ALL|All) cgy='&c=0&t=1&o=52' ;;
audio|AUDIO|Audio) cgy='&c=1&t=1&o=52' ;;
games|GAMES|Games) cgy='&c=2&t=1&o=52' ;;
video|VIDEO|Video) cgy='&c=6&t=1&o=52' ;;
software|SOFTWARE|Software) cgy='&c=3&t=1&o=52' ;;
TV|tv) cgy='&c=4&t=1&o=52' ;;
unsorted|UNSORTED|Unsorted) cgy='&c=5&t=1&o=52' ;;
*) echo "" ;
echo -e "\t\tplease select a valid category\n\t\t-h for help" ;
echo -e "\t\tor try your search like this: 'bob+marley [all|audio|games|video]'" ;
echo "" ;
exit ;;
esac
done
## check help
url="$1$cgy"
if [ -n "$1" ]; then
case $1 in
-v|--version) echo "" ;
echo -e "\t GetTorrent version $version" ;
echo "" ; exit ;;
-h|--help) echo ""
echo -e "\t\t\tTry your search like this:" ;
echo -e "\t\t\t'bob+marley [all|audio|games|video|tv|unsorted|software]'\n" ;
echo -e "\t\t\tcurrent Category: $CATEGORY\n\t\t\tcurrent Browser: $BROWSER" ;
echo -e "\t -h --help\tprint help";
echo -e "\t -v --version\tprint version\n";
exit ;;
esac
elif [ "$url" = "$cgy" ]; then
echo ""
echo -e "\t\tTry your search like this: 'bob+marley [all|audio|games|video]'"
echo -e "\t\t-h for help"
echo ""
exit
fi
## get source
`$brw http://db2.btjunkie.org/search?q=$url | \
awk -F'["<>]' '/return|LightOrange|808080|32CD32|00CED1/ {print $3,$11,$13}' > $tmp`
sed -ne '/torrent/!H;/'$1'/x;s/\n/ /gp;' $tmp > $tmp2
sed -i 's|files/'$1'|download.torrent|g;' $tmp2; matcher
## create list
echo -e 'for I in $input; do\n case $I in' > $tmp
awk -F'[/ ]' \
'BEGIN {n='$NR'+1;} {if (n < FNR) exit;} \
/torrent/{i+=1; d=$1"/"$2"/"$3"/"$4"/"$5; print \
i")","wget -q","http://db2.btjunkie.org"d,''"&&","mv download.torrent", \
$3".torrent","; echo -e $DATE", $3, ">> $log","; echo -e","tttttttt", $3,\
"\\033[1;31mdone\\033[0m tttttttt", ";;"}' $tmp2 >> $tmp
sed -i '/done/s/tttttttt/"/g;' $tmp
echo -e '*) exit ;;\n esac\n done' >> $tmp
## print list
clear
echo -en "\n Chosen Category:\e[1;31m $CATEGORY\n\e[0m"
echo ""
echo "Result For $1 Cotegory Size Seeds Leech Date" | \
awk '{d=$1" "$2" "$3;} { printf "%7s %-38s %-1s %10s %8s %7s %7s %8s\n","|",\
substr(d,0,37),"|", $4" |", $5" |", $6" |", $7" |", $8" |"}'
echo " =====|========================================|==========|========|=======|=======|========|"
awk -F'[/ ]' \
'BEGIN {n='$NR'+1;} {if (n < FNR) exit;} {if ($8 == 1) m="\033[1;31m""*""\033[0m"; else m="";} \
{if ($8 == 1) f="\033[1;31m"$3; else f="\033[1;00m"$3;} /torrent/{i+=1; d=$20"/"$21; \
printf " %1s %4s %-45s %-1s %10s %8s %7s %7s %8s\n", \
m, i")|", substr(f,0,45),"\033[0m""|", $11" |", $16" |", $25" |", $29" |", d" |"}' $tmp2
echo " ============================================================================================"
echo ""
## get torrent
cd $TORRENTDIR
echo ""
echo -en " Files \e[1;31mwith '*' in red\e[0m were downloaded in the past!\n"
echo -en " Try your choice like that: '1 2 5 10' or q for quit\n\n"
echo -en " \e[1mYour choice : "
echo -en "\033[0m"
read -e input
echo ""
source $tmp
echo -en "\033[1m\n"
runner; spinner
echo -ne "\033[u\e[1;31m`awk '/'$DATE'/{i++;}END{print i}' $log` \e[0moverall:\e[1;31m `awk '{i++;}END{print i}' $log`\e[0m"
echo -e "\n"
exit 0