daily pastebin goal
5%
SHARE
TWEET

Derpibooru Downloader

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