Guest User

Derpibooru Downloader

a guest
Feb 15th, 2014
544
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. #Written by X41
  4.  
  5. #            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  6. #                    Version 2, December 2004
  7. #
  8. # Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
  9. #
  10. # Everyone is permitted to copy and distribute verbatim or modified
  11. # copies of this license document, and changing it is allowed as long
  12. # as the name is changed.
  13. #
  14. #            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  15. #   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  16. #
  17. #  0. You just DO WHAT THE FUCK YOU WANT TO.
  18.  
  19.  
  20. import json
  21. import urllib.request
  22. import sys
  23.  
  24. links= []
  25. page = 0
  26. pic = 0
  27. tag = ' '.join(sys.argv[1:])
  28. data = ""
  29.  
  30. while True:
  31.     page += 1
  32.     url = "http://derpibooru.org/search.json?q=" + str(tag) + "&page=" + str(page)
  33.     print(url)
  34.     print("downloading data page " + str(page))
  35.     json_data = urllib.request.urlopen(url).read().decode("utf-8")
  36.     if json_data == "[]":
  37.         break
  38.     data = json.loads(json_data)
  39.     for entry in data:
  40.         links.append("http:" + entry['image'])
  41. if len(links) == 0:
  42.     print("No pics with that tag found")
  43.     exit()
  44. for link in links:
  45.     pic +=1
  46.     print("downloading pic " + str(pic) + " of " + str(len(links)))
  47.     try:
  48.         urllib.request.urlretrieve(link,link.split("/")[-1])
  49.     except:
  50.         print("Something went wrong with picture " + str(pic) +". Continuing with other pics.")
  51. print("All done. May Celestia be with you.")
  52. exit()
RAW Paste Data