jollygamer321

download_full_db.sh 3

Nov 9th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #### Varliables ####
  4. NUMBER_OF_PAGES=3600
  5.  
  6.  
  7. #### Directories and file location ####
  8. TOP_DIR="$HOME/tvtz"
  9. PAGES_DOWNLOAD="$TOP_DIR/pages"
  10. PAGES_DELETE="$TOP_DIR/pages_delete"
  11. COOKIE="$TOP_DIR/cookie.txt"
  12. ID_LIST="$TOP_DIR/id_list.txt"
  13.  
  14.  
  15. #### Funtions ####
  16. download_pages ()
  17. {
  18.     for i in `cat $ID_LIST`;
  19.     do
  20.         if [ $NUMBER_OF_PAGES -lt 1 ]
  21.         then
  22.             exit
  23.         else
  24.             if [ -f $PAGES_DOWNLOAD/$i.html ]
  25.             then
  26.                 continue
  27.             else
  28.                 curl -o $PAGES_DOWNLOAD/$i.html -b $COOKIE "http://tvtorrentz.org/details.php?id=$i&filelist=1"
  29.                 NUMBER_OF_PAGES=$(( NUMBER_OF_PAGES-1 ))
  30.                 echo $NUMBER_OF_PAGES
  31.                 sleep 8
  32.                 continue
  33.             fi
  34.         fi
  35.     done
  36. }
  37.  
  38. delete_pages ()
  39. {
  40.     mkdir $TOP_DIR/temp/
  41.  
  42.     for i in `cat $ID_LIST`;
  43.     do
  44.         if [ -f $PAGES_DOWNLOAD/$i.html ]
  45.         then
  46.             mv $PAGES_DOWNLOAD/$i.html $TOP_DIR/temp/
  47.             continue
  48.         fi
  49.     done
  50.  
  51.     mv -v $PAGES_DOWNLOAD/* $PAGES_DELETE/
  52.     mv $TOP_DIR/temp/* $PAGES_DOWNLOAD/
  53.     rm -R $TOP_DIR/temp/
  54. }
  55.  
  56.  
  57. #### Program start ####
  58.  
  59. #Check directories
  60. if [ ! -d $TOP_DIR ]
  61. then
  62.     mkdir -v -p $TOP_DIR
  63. fi
  64.  
  65. if [ ! -d $PAGES_DOWNLOAD ]
  66. then
  67.     mkdir -v -p $PAGES_DOWNLOAD
  68. fi
  69.  
  70. if [ ! -d $PAGES_DELETE ]
  71. then
  72.     mkdir -v -p $PAGES_DELETE
  73. fi
  74.  
  75.  
  76. #Check cookie
  77. if [ ! -s $COOKIE ]
  78. then
  79.     if [ -s $HOME/.tvtz/tvtz_cookie.txt ]
  80.     then
  81.         cp -v $HOME/.tvtz/tvtz_cookie.txt $COOKIE
  82.     else
  83.         printf "\nERROR: $COOKIE is empty or does not exist\n"
  84.         exit
  85.     fi
  86. fi
  87.  
  88. #Get ID_LIST
  89. curl -b $COOKIE "http://tvtorrentz.org/godzilla_api.php?ak=76b4f23b3c4711b3cb1fe4caa1bf4ab5&action=get_torrent_ids" > $ID_LIST
  90.  
  91. #Check ID_LIST and run functions
  92. if [ -s $ID_LIST ]
  93. then
  94.     download_pages
  95.     delete_pages
  96.     exit
  97. else
  98.     printf "\nERROR: $ID_LIST is empty or does not exist\n"
  99.     exit
  100. fi
  101.  
Add Comment
Please, Sign In to add comment