Register
It is currently Thu Oct 23, 2014 5:39 am

gettorrent script for searching torrents


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Tue May 08, 2007 4:08 pm   

Joined: Tue May 08, 2007 3:49 pm
Posts: 5
hi, that's my first useful script. it's searching for torrents on www.btjunkie.com. please let me know about bugs or improvements

Code:
#!/bin/bash
#set -xv

#
# gettorrent version beta 0.5
#
#
#
######################################################################################################

## default search category [all|audio|games|video]
CATEGORY=Audio

## default browser [links|lynx|w3m]
BROWSER=lynx

## default download dir
TORRENTDIR=$HOME/torrent

## number of printed torrents
NR=20

########################################################################################################

tmp="/tmp/get.tmp"
tmp2="/tmp/get2.tmp"
version="beta 0.5"

## 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' ;;
      *)                  echo "" ;
                          echo -e "\t\tplease select a valid category" ;
                          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\tgettorrent version $version" ;
                  echo "" ; exit ;;
    -h|--help)    echo ""
                  echo -e "\t\tTry your search like this: 'bob+marley [all|audio|games|video]'";
                  echo "" ; exit ;;
  esac

elif [ "$url" = "$cgy" ]; then
      echo ""
      echo -e "\t\tTry your search like this: 'bob+marley [all|audio|games|video]'"
      echo ""
      exit
fi

## get source

`$brw http://db2.btjunkie.org/search?q=$url | \
  awk -F'["<>]' '/return|808080|32CD32|00CED1/ {print $3,$13}' > $tmp`
    sed -ne '/torrent/!H;/'$1'/x;s/\n/ /gp;' $tmp > $tmp2
      sed -i 's|files/'$1'|download.torrent|g;' $tmp2


## 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", $3,"done" ";;"}' $tmp2 >> $tmp

echo -e 'esac\n done' >> $tmp

## print list

clear
echo ""
echo "'Result_For_$1' Size Seeds Leech Date" | \
        awk '{ printf "%6s %-46s %-1s %10s %7s %7s %8s\n","|", substr($1,0,40),"|", $2" |", $3" |", $4" |", $5" |"}'
echo " ====|================================================|==========|=======|=======|========|"

awk -F'[/ ]' \
'BEGIN {n='$NR'+1;} {if (n < FNR) exit;} \
  /torrent/{i+=1; d=$10"/"$11; \
    printf "%6s %-46s %-1s %10s %7s %7s %8s\n", \
    i")|", substr($3,0,45),"|", $8" |", $13" |", $15" |", d" |"}' $tmp2

echo " =========================================================================================="
echo ""

## get torrent

cd $TORRENTDIR
echo -en " welche "
read -e input


source $tmp

exit 0


Top
 Profile  
 PostPosted: Thu May 10, 2007 6:46 am   

Joined: Tue May 08, 2007 3:49 pm
Posts: 5
update to beta 0.6 ;)
    +more categories
    +logfile
    +edit help text
    +edit output list

Code:
#!/bin/bash
#
# GetTorrent version beta 0.6
#
#
#
######################################################################################################

## 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.6"
DATE=$(date +%Y.%m.%d@%H:%M:%S)

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


## 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", $3,"done" ";;"}' $tmp2 >> $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 "%6s %-46s %-1s %10s %8s %7s %7s %8s\n","|",\
            substr(d,0,40),"|", $4" |", $5" |", $6" |", $7" |", $8" |"}'
echo " ====|================================================|==========|========|=======|=======|========|"

awk -F'[/ ]' \
'BEGIN {n='$NR'+1;} {if (n < FNR) exit;} \
  /torrent/{i+=1; d=$20"/"$21; \
    printf "%6s %-46s %-1s %10s %8s %7s %7s %8s\n", \
    i")|", substr($3,0,45),"|", $11" |", $16" |", $25" |", $29" |", d" |"}' $tmp2

echo " ==================================================================================================="
echo ""


## get torrent

cd $TORRENTDIR
echo ""
echo -en "Try your choice like that: '1 2 5 10' or q for quit\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


Top
 Profile  
 PostPosted: Thu May 10, 2007 1:48 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Nice Script!


Top
 Profile YIM  
 PostPosted: Fri May 11, 2007 12:39 pm   

Joined: Tue May 08, 2007 3:49 pm
Posts: 5
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


Top
 Profile  
 PostPosted: Fri Feb 13, 2009 6:31 pm   

Joined: Fri Jan 02, 2009 10:40 pm
Posts: 2
maybe i am a tard but am getting:
awk: fatal: cannot open file `/tmp/gettorrent2.tmp' for reading (No such file or directory)

2.6.21-7.fc7xen #1 SMP Tue Feb 12 12:32:24 EST 2008 i686 i686 i386 GNU/Linux


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP