159 lines
4.1 KiB
Python
159 lines
4.1 KiB
Python
import urllib.request
|
|
|
|
tags = "wedding_dress" #separate with +
|
|
rating = "rating%3A" + "all" #all, safe, questionable, questionableplus, explicit
|
|
order = "order%3A" + "date" #date, fav, score, random, wide, nonwide
|
|
site = "konachan.com" #konachan.com, yande.re, danbooru.donmai.us
|
|
downloadnummer = 1
|
|
|
|
def konaBild(nummer):
|
|
postnummer = nummer
|
|
|
|
|
|
url = 'https://'+site+'/post.xml?page='+str(postnummer)+'&limit=1&tags=' + tags + '+' + order + '+' + rating
|
|
req = urllib.request.Request(url, headers={'User-Agent': 'XYZ/3.0'})
|
|
response = urllib.request.urlopen(req, timeout=100)
|
|
text = str(response.read())
|
|
|
|
if len(text)<100:
|
|
print("end of list")
|
|
return 403
|
|
|
|
|
|
text = formatText(text)
|
|
#Debugtext(text)
|
|
urllib.request.urlretrieve(getBild(text), "konachan/" + getId(text) + ".jpg")
|
|
return ("konachan/" + getId(text) + ".jpg")
|
|
|
|
|
|
def getAll():
|
|
postnummer = 1
|
|
url = 'https://'+site+'/post.xml?page='+str(postnummer)+'&limit=100&tags=' + tags + '+' + rating
|
|
req = urllib.request.Request(url, headers={'User-Agent': 'XYZ/3.0'})
|
|
response = urllib.request.urlopen(req, timeout=100)
|
|
text = str(response.read())
|
|
|
|
postanzahl = int(getPostanzahl(text))
|
|
|
|
print("Postanzahl: "+ str(postanzahl))
|
|
|
|
for i in range(int(postanzahl/100)+1):
|
|
konaMasse(i+1)
|
|
|
|
def getPostanzahl(input):
|
|
output = ""
|
|
CountStart = input.find('posts count')
|
|
CountStart = CountStart + 13
|
|
while 1:
|
|
if input[CountStart]=="\"":
|
|
break
|
|
output = output + input[CountStart]
|
|
CountStart = CountStart + 1
|
|
return output
|
|
|
|
|
|
def konaMasse(nummer):
|
|
postnummer = nummer
|
|
url = 'https://'+site+'/post.xml?page='+str(postnummer)+'&limit=100&tags=' + tags + '+' + rating #loli+rating%3Aexplicit
|
|
req = urllib.request.Request(url, headers={'User-Agent': 'XYZ/3.0'})
|
|
response = urllib.request.urlopen(req, timeout=100)
|
|
text = str(response.read())
|
|
|
|
text = formatText(text)
|
|
#print(text[0:20000])
|
|
|
|
for i in range(110):
|
|
global downloadnummer
|
|
|
|
if len(text)<1000:
|
|
print("end of list")
|
|
return 403
|
|
|
|
urllib.request.urlretrieve(getBild(text), "konachan/" + getId(text) + ".jpg")
|
|
print("Downloadnummer:" + str(downloadnummer))
|
|
downloadnummer = downloadnummer + 1
|
|
print(getBild(text))
|
|
print("Id:"+getId(text))
|
|
print("len:"+str(len(text)))
|
|
print(text.find("sample_file_size="))
|
|
text = text[text.find("sample_file_size=")+30:]
|
|
|
|
|
|
|
|
|
|
def Debugtext(text):
|
|
print (text)
|
|
print(getBild(text))
|
|
print(getId(text))
|
|
print ("\n\n\n\n")
|
|
|
|
def formatText(input):
|
|
schrägstrich = 0
|
|
fuehrungzeichen = 0
|
|
output = ""
|
|
for x in input:
|
|
if x=="\"":
|
|
if fuehrungzeichen:
|
|
output = output + x
|
|
fuehrungzeichen = 1
|
|
continue
|
|
|
|
if x=="\\":
|
|
if schrägstrich:
|
|
output = output + x
|
|
schrägstrich = 1
|
|
continue
|
|
|
|
if fuehrungzeichen&(x==" "):
|
|
output = output + "\"\n"
|
|
fuehrungzeichen = 0
|
|
continue
|
|
|
|
if schrägstrich&(x=="n"):
|
|
output = output + "\n"
|
|
schrägstrich = 0
|
|
continue
|
|
|
|
if fuehrungzeichen:
|
|
output = output + "\""
|
|
fuehrungzeichen = 0
|
|
|
|
if schrägstrich:
|
|
output = output + "\\"
|
|
schrägstrich = 0
|
|
|
|
output = output + x
|
|
return output
|
|
|
|
def getBild(input):
|
|
output = ""
|
|
UrlStart = input.find('file_url')
|
|
UrlStart = UrlStart + 10
|
|
while 1:
|
|
if input[UrlStart]=="\"":
|
|
break
|
|
output = output + input[UrlStart]
|
|
UrlStart = UrlStart + 1
|
|
return output
|
|
|
|
def getId(input):
|
|
output = ""
|
|
IdStart = input.find('\nid=')
|
|
IdStart = IdStart + 5
|
|
while 1:
|
|
if input[IdStart]=="\"":
|
|
break
|
|
output = output + input[IdStart]
|
|
IdStart = IdStart + 1
|
|
return output
|
|
|
|
#for i in range(60):
|
|
#print(i)
|
|
#konaBild(i)
|
|
#konaBild(9)
|
|
#konaMasse(1)
|
|
getAll()
|
|
|
|
|
|
#urllib.request.urlretrieve("https://i.pinimg.com/236x/27/5b/57/275b57e1d12078cb48891894a78400e0.jpg", "local-filename.jpg")
|