Advertisement
Guest User

Chaos

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