Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: Python | Size: 6.76 KB | Hits: 50 | Expires: Never
Copy text to clipboard
  1. #4olderDumper v1.00
  2. #By ~ dark.chaos.0@gmail.com
  3.  
  4. from random import *
  5. import os
  6. import sys
  7. import getopt
  8. import pycurl
  9. from StringIO import StringIO
  10. from mimetypes import guess_type
  11. from time import sleep
  12.  
  13. def post(server, board, thread, post="", image=None, name="", email="", subject="", password="lol123", proxy=None):
  14.    
  15.     FF_XP2 = {
  16.         'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5)',
  17.         'Accept': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
  18.         'Accept-Language': 'en-us,en;q=0.5',
  19.         #'Accept-Encoding': 'gzip,deflate',
  20.         'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  21.         'Referer' : "http://boards.4chan.org/%s/res/%s.html" % (board, thread),
  22.     }
  23.    
  24.     curl_headers = [v is not None and '%s: %s' % (k, v) or '%s:' % k
  25.      for k, v in FF_XP2.items()]
  26.    
  27.     post = [('MAX_FILE_SIZE', '3145728'),
  28.             ('resto', thread),
  29.             ('name', name),
  30.             ('email', email),
  31.             ('sub', subject),
  32.             ('com', post),
  33.             ('pwd', password),
  34.             ('mode', 'regist'),
  35.            ]
  36.  
  37.     processor = {"orz":"tmp", "zip":"bin", "img":"dat", "cgi":"nov"}
  38.  
  39.     curl = pycurl.Curl()
  40.     curl.setopt(pycurl.SSL_VERIFYPEER, 0)
  41.     if proxy:
  42.         curl.setopt(pycurl.PROXY, proxy)
  43.     curl.setopt(pycurl.URL, "http://sys.4chan.org/%s/imgboard.php" % board)
  44.  
  45.     curl.setopt(pycurl.POST, 1)
  46.     curl.setopt(pycurl.HTTPHEADER, curl_headers)
  47.     #curl.setopt(pycurl.POSTFIELDS, urlencode(post))
  48.  
  49.     if image:
  50.         post.append(('upfile', (pycurl.FORM_CONTENTTYPE, guess_type(image)[0], pycurl.FORM_FILENAME, os.path.basename(image), pycurl.FORM_FILE, image)))
  51.        
  52.     curl.setopt(pycurl.HTTPPOST, post)
  53.  
  54.     body = StringIO(); header = StringIO()
  55.     curl.setopt(pycurl.WRITEFUNCTION, body.write)
  56.     curl.setopt(pycurl.HEADERFUNCTION, header.write)
  57.  
  58.     for i in range(5):
  59.         try:
  60.             curl.perform()
  61.             res = body.getvalue()
  62.         except KeyboardInterrupt:
  63.             return False
  64.         except:
  65.             print sys.exc_info()[1]
  66.             continue
  67.         if not res.find("SQLFAILS_") > 0:
  68.             break
  69.    
  70.     curl.close()
  71.     #print res
  72.     if (res.find("file entry detected") > 0):
  73.         print "Duplicate File Entry"
  74.         return False
  75.     elif res.find("Flood detected") > 0:
  76.         print "Flood Detected"
  77.         return False
  78.     elif res.find("404") > 0 or res.find("Thread specified does not exist") > 0:
  79.         print "404'd"
  80.         return True
  81.     elif res.find("Updating") > 0:
  82.         print "Uploaded", os.path.basename(image)
  83.         return True
  84.     else:
  85.         print "Unknown Error"
  86.         #z = open("error.html", "w")
  87.         #z.write(res)
  88.         #z.close()
  89.         return False
  90.  
  91. def usage():
  92.     print """4olderDump - 4chan Folder Dumper
  93. usage : %s [options]
  94. Options and arguments:
  95. -s,--server   : Server of the board. (Ex. zip, orz, img) [Required]
  96. -b,--board    : Board. (Ex. g, b, v no slashes) [Required]
  97. -t,--thread   : Thread id. (Ex. http://zip.4chan.org/board/res/1337.html, 1337 is the Thread id. [Required]
  98.                (That means you must make the thread first).
  99. -f,--folder   : Path/to/folder. [Required]
  100. -c,           :      Displays Current Image / Total Images as the comment.
  101. --comment-enabled
  102. -n,--name     : Name/Tripcode faggotry. (Ex. Iam##afaggot)
  103. -e,--email    : Email. (Noko, Sage)
  104. -S,--subject  : Subject.
  105. -p,--password : Password. (For Post deletion)
  106. -h,--help     : Display this help.
  107. -w,--wait     : Delay between posts. Default : 30 seconds.
  108. -r,           : Maxium retries before giving up on uploading an image. Default : 3.
  109. --max-retries
  110.  
  111. Example:
  112. %s -s img -b b -t 1337331 -f home/shit/CP -c -S "Am I Kewl Yet Guize?"
  113. """ % (os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0]))
  114.  
  115. def main():
  116.     try:
  117.         opts, args = getopt.getopt(sys.argv[1:], "s:b:t:f:cn:e:S:p:w:r:h", ["-server", "-board", "-thread", "-folder", "-comment-enabled", "-name", "-email", "-subject", "-password", "-wait", "-max-retries", "-help"])
  118.     except getopt.GetoptError, err:
  119.         print "Error:", str(err)
  120.         print ""
  121.         usage()
  122.         sys.exit(2)
  123.  
  124.     usettings = {}
  125.     settings = {"server":"","board":"","thread":"","folder":"","comment":False,"name":"","email":"","subject":"","password":"pyegase","retry":3,"wait":30}
  126.    
  127.     dhelp = False
  128.     for o, a in opts:
  129.         if o in ("-h", "--help"):
  130.             dhelp = True
  131.         elif o in ("-s", "--server"):
  132.             usettings['server'] = a
  133.         elif o in ("-b", "--board"):
  134.             usettings['board'] = a
  135.         elif o in ("-t", "--thread"):
  136.             usettings['thread'] = a
  137.         elif o in ("-f", "--folder"):
  138.             usettings['folder'] = a
  139.         elif o in ("-c", "--comment-enabled"):
  140.             usettings['comment'] = True
  141.         elif o in ("-n", "--name"):
  142.             usettings['name'] = a
  143.         elif o in ("-e", "--email"):
  144.             usettings['email'] = a
  145.         elif o in ("-S", "--subject"):
  146.             usettings['subject'] = a
  147.         elif o in ("-p", "--password"):
  148.             usettings['password'] = a
  149.         elif o in ("-r", "--max-retries"):
  150.             usettings['retry'] = int(a)
  151.         elif o in ("-w", "--wait"):
  152.             usettings['wait'] = int(a)
  153.  
  154.     req = ["server", "board", "thread", "folder"]
  155.     for k in req:
  156.         if k not in settings:
  157.             print "Error: Missing required option", k
  158.             print ""
  159.             usage()
  160.             sys.exit(2)
  161.             break
  162.  
  163.     settings.update(usettings)
  164.  
  165.     if not os.path.isdir(settings['folder']):
  166.         print "Error: Folder",settings['folder'],"does not exist."
  167.         print ""
  168.         usage()
  169.         sys.exit(2)
  170.        
  171.     print "Starting..."
  172.     files = os.listdir(settings['folder'])
  173.     images = []
  174.     for f in files:
  175.         if os.path.splitext(os.path.join(settings['folder'],f))[1].lower() in (".gif", ".jpg", ".png", ".jpeg"):
  176.             images.append(os.path.join(settings['folder'],f))
  177.     print "Dumping", len(images), "images."
  178.     i=1
  179.     shuffle(files)
  180.     for image in images:
  181.         print "Dumping image %d of %d." % (i,len(images))
  182.         comment = ("Image %d of %d." % (i,len(images))) if settings['comment'] else ""
  183.         for r in range(settings['retry']):
  184.             z = post(settings['server'], settings['board'], settings['thread'], comment, image, settings['name'], settings['email'], settings['subject'], settings['password'])
  185.             if (z): break
  186.         print "Waiting..."
  187.         sleep(settings['wait'])
  188.         i += 1
  189.  
  190.     print "Done!"    
  191.  
  192.  
  193. if __name__ == "__main__":
  194.     main()
  195.     raw_input()