Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download images from yande.re or konachan.com, only when the aspect ratio is 16:9 and the image is 1080p or above
import requests
import os
import sys
def downloadPostJson(limit=10000, page=0, tag="", board="konachan.com"):
url = "https://%s/post.json?tags=%s&limit=%s&page=%s" % (board, tag, limit, page)
r = requests.get(url)
if len(r.content) >= 1:
return r.json()
def downloadImage(url, path):
if not os.path.exists(path):
r = requests.get(url)
if len(r.content) >= 1000:
f = open(path, "wb")
f.write(r.content)
f.close()
def calculateGcd (a, b):
if b == 0:
return a
return calculateGcd(b, int(a % b))
def getImages(pageLimit=1000, pages=1000, tag="", board="konachan.com"):
imagePosition = 0
for currentPage in range(0, pages):
images = downloadPostJson(page=currentPage, limit=pageLimit, tag=tag, board=board)
if len(images) >= 1:
for image in images:
gcd = calculateGcd(image['width'], image['height'])
aspect = ("%s:%s" % (image['width']/gcd, image['height']/gcd))
if aspect == "16:9" and int(image['width']) >= 1920 and int(image['height']) >= 1080:
print("Downloading: %s" % (image['file_url']))
downloadImage(image['file_url'], os.path.join("images/", image['md5'] + ".png"))
imagePosition = imagePosition + 1
getImages(tag=sys.argv[1], board=sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment