Advertisement
Guest User

Untitled

a guest
May 23rd, 2010
1,292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. #!/bin/bash
  2. # privatetracker auto-upload script by user
  3. # noobs want to read the next couple of lines:
  4. # 1. replace the below PIN and LOGINURL values with your login details
  5. # 2. make the script executable by using chmod +x privatetracker-upload.sh
  6. # 3. place this script into /usr/bin, /usr/local/bin or any other path that is included
  7. # in the output of echo $PATH
  8. # 4. execute it by calling privatetracker-upload.sh .. if you didn't rename the file
  9. # 5. don't bug me with stupid questions ;-P
  10.  
  11. PIN=42235
  12. LOGINURL="https://www.privatetracker.net/login.php?id=1337&hash=64ef367018099de4d4183ffa3bc0848a"
  13. ######################################
  14.  
  15. TMPPAGE="$(mktemp /tmp/privatetracker-page.XXXXXX)"
  16. COOKIES="$(mktemp /tmp/privatetracker-cookie.XXXXXX)"
  17. CGREEN="\033[0;32m"
  18. CRED="\033[0;31m"
  19. privatetrackerORM="\033[0m"
  20. TORRENT=""
  21. INT=0
  22. NFOFILE=""
  23. FORMATS="XviD=1;x264=3;HD=5;DVDR=7;BRRiP=29"
  24.  
  25. function help(){
  26. cat << EOF
  27. privatetracker auto-uploader script by user
  28. ================================
  29. Syntax:
  30. privatetracker-upload.sh -torrent <torrentfile> -nfo <nfo or description> -format <format> [-anonymous] [-interval 0,1,2,3] [-o file]
  31. -torrent specify the torrent file you want to upload
  32. -nfo specity the nfo or description file you want to upload
  33. -format specify the format your upload is in, have a look at the botttom of this help to see the options
  34. -anonymous using this option (without a parameter) your nick won't be displayed as Uploader on the site
  35. -interval specify the permaseeding interval you want to use after the upload, 0 is the default
  36. -o specify the output file rather than overwriting the original torrent file when downloading
  37.  
  38. Example:
  39. privatetracker-upload.sh -interval 2 -torrent foobar.torrent -nfo foobar.txt -format xvid
  40.  
  41. The torrent file you created will get overwritten on a successful upload, so you can directly
  42. put it into your torrent client. The file is downloaded afterwards. By using -interval
  43. you can control which permaseeding interval this torrent should be.
  44.  
  45. Remember to put your pin code and your login URL into the beginning section of this script
  46. EOF
  47.  
  48. echo "Available formats are: $(echo $FORMATS | sed -re 's,=[0-9]+;*, ,g')"
  49. }
  50.  
  51. function login(){
  52. echo -n "[+] Logging in to privatetracker...."
  53. if ! curl -c $COOKIES -d "action=login&pincode=${PIN}" -i -s $LOGINURL -o $TMPPAGE || ! grep -q "Location: index.php" $TMPPAGE; then
  54. echo -e "${CRED}couldn't login to privatetracker, aborting script, please check your login URL, pin code${privatetrackerORM} and network connectivity"
  55. exit 256
  56. else
  57. echo -e "${CGREEN}logged in${privatetrackerORM}"
  58. fi
  59. }
  60.  
  61. function check_curl(){
  62. if ! which curl > /dev/null; then
  63. echo -e "${CRED}THIS SCRIPT NEEDS curl IN ORDER TO WORK${privatetrackerORM}"
  64. echo "either you don't have curl installed or it is not in your \$PATH"
  65. echo "please obtain a copy from http://curl.haxx.se/ and retry"
  66. exit 1
  67. fi
  68. }
  69.  
  70. if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
  71. help
  72. exit 0
  73. fi
  74.  
  75. while [[ "$#" -gt "0" ]]; do
  76. if [[ ${1:0:1} == "-" ]]; then
  77. if [[ $1 == "-torrent" ]]; then
  78. TORRENT="$2"
  79. shift
  80. elif [[ $1 == "-nfo" ]]; then
  81. NFOFILE="$2"
  82. shift
  83. elif [[ $1 == "-format" ]]; then
  84. FORMAT="$2"
  85. shift
  86. elif [[ $1 == "-interval" ]]; then
  87. INT=$2
  88. shift
  89. elif [[ $1 == "-o" ]]; then
  90. OUTFILE="$2"
  91. shift
  92. elif [[ $1 == "-anonymous" ]]; then
  93. ANONYMOUS="yes"
  94. else
  95. echo -e "unknown option: ${CRED}$1${privatetrackerORM}"
  96. help
  97. exit 1
  98. fi
  99. else
  100. help
  101. exit 1
  102. fi
  103. shift
  104. done
  105.  
  106. if [ "x$FORMAT" == "x" ]; then
  107. echo "You need to specify a format to use"
  108. help
  109. exit 1
  110. fi
  111.  
  112. if ! file $TORRENT | grep "BitTorrent file" > /dev/null 2>&1 ; then
  113. echo -e "${CRED}$TORRENT${privatetrackerORM} is no valid torrent file, please check"
  114. exit 1
  115. fi
  116.  
  117. if ! echo $FORMATS | grep -iE "(^|;)$FORMAT=" > /dev/null; then
  118. echo -e "${CRED}$FORMAT${privatetrackerORM} is no accepted format"
  119. help
  120. exit 1
  121. fi
  122.  
  123. if ! echo $INT | grep -E '[0123]{1}' > /dev/null; then
  124. echo -e "${CRED}$INT${privatetrackerORM} is not a valid permaseeding interval, please check"
  125. help
  126. exit 1
  127. fi
  128.  
  129. UPFORM=$(echo $FORMATS | sed -re "s,(^|.*;)$FORMAT=([0-9]+).*,\2,gi")
  130.  
  131. check_curl
  132. login
  133.  
  134. if [ "x$ANONYMOUS" == "xyes" ]; then
  135. echo -e "[+] Uploading this torrent ${CGREEN}anonymously${privatetrackerORM}"
  136. else
  137. echo -e "[!] Uploading this torrent ${CRED}not anonymously${privatetrackerORM}"
  138. fi
  139.  
  140. echo -e "[+] Uploading as ${CGREEN}$FORMAT${privatetrackerORM}"
  141. echo -ne "[+] Trying to upload ${CGREEN}$TORRENT${privatetrackerORM} - ${CGREEN}$NFOFILE${privatetrackerORM}..."
  142.  
  143. if curl -b $COOKIES -F "file=@$TORRENT" -F "nfo=@$NFOFILE" -F "type=$UPFORM" -F "uplver=$ANONYMOUS" -s https://www.privatetracker.net/takeupload.php -o $TMPPAGE; then
  144. if grep "Upload failed" $TMPPAGE > /dev/null; then
  145. REASON="$(grep -A1 "Upload failed" $TMPPAGE | tail -1 | sed -re 's,.*<p>(.*)</p>.*,\1,')"
  146. echo -e "${CRED}failed ($REASON)${privatetrackerORM}"
  147. exit 1
  148. else
  149. echo -e "${CGREEN}success${privatetrackerORM}"
  150. fi
  151. echo
  152. LINK="$(grep 'http-equiv="refresh"' $TMPPAGE | sed -re 's,.*url=(.*)" />.*,\1,')"
  153. echo "Find your new upload on: $LINK"
  154.  
  155. ID=$(echo $LINK | sed -re 's,.*id=([0-9]+).*,\1,')
  156. if [ "x$OUTFILE" != "x" ]; then
  157. echo -ne "[+] Writing new torrent file to ${CGREEN}$OUTFILE${privatetrackerORM}..."
  158. TORRENT=$OUTFILE
  159. else
  160. echo -ne "[+] Overwriting the initial torrent file ${CGREEN}$TORRENT${privatetrackerORM}..."
  161. fi
  162. if curl -g -b $COOKIES -o "$TORRENT" -s "https://www.privatetracker.net/download.php/$ID/$INT/$(basename $TORRENT)"; then
  163. echo -e "${CGREEN}success${privatetrackerORM}"
  164. else
  165. echo -e "${CRED}failure${privatetrackerORM}"
  166. echo "please check file permissions and $TMPPAGE"
  167. exit 1
  168. fi
  169.  
  170. else
  171. echo -e "${CRED}failure${privatetrackerORM}"
  172. echo
  173. echo "There has been a problem uploading your torrent file, please check the submitted files, network connectivity, login details..."
  174. echo "Additionally you check check $TMPPAGE for possible error output, this file may include html"
  175. exit 1
  176. fi
  177.  
  178. rm -f $COOKIES $TMPPAGE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement