import os , urllib .request , re , time
from random import *
def folder( tag) :
try :
os .mkdir ( tag, mode= 0o777 )
except FileExistsError:
pass
os .chdir ( tag)
return "starting..."
def prev( tags, n) :
try :
n = int ( n)
except ValueError :
n = 2 **25
out = [ ]
k = 0
t = 0
req = 'http://g...content-available-to-author-only...u.com/index.php?page=post&s=list&tags='
pid = '&pid='
while len ( out) < n:
t = 0
page = urllib .request .urlopen ( req+tags+pid+str ( k) ) .read ( ) .decode ( )
time .sleep ( float ( '0.' +str ( randint( 2 , 9 ) ) ) ) #На всякий случай. А то вдруг нас примут за ботов и стукнут банхаммером. ^_^ По своему усмотрению удалите эту строчку.
for elem in re .findall ( r'id\= \d +\" ><img src=\" ([^\" ]+)' , page) :
out.append ( elem)
t+= 1
k+= 42
if t == 0 :
break
return out[ :n]
def link( pre) :
my_link = 'http://g...content-available-to-author-only...u.com//images'
p = re .sub ( r'thumbnail_' , '' , re .search ( r'(?<=nails)(.+)' , pre) .group ( ) )
return ( my_link+p, ( my_link+p) .replace ( 'jpg' , 'jpeg' ) ,
( my_link+p) .replace ( 'jpg' , 'gif' ) , ( my_link+p) .replace ( 'jpg' , 'png' ) )
def randname( x) :
return '' . join ( sample( str ( randint( 11111111111 , 99999999999 ) *3 ) + '' .join ( [ chr ( i) * randint( 1 , 3 ) for i in range ( 97 , 123 ) ] ) , x) )
def download( tag, x) :
prw = prev( tag, x)
print ( 'loading...' )
for i in prw:
q = link( i)
for elem in q:
try :
my_pic = urllib .request .urlopen ( elem) .read ( )
f = open ( randname( 16 ) + re .search ( r'\. [a-z]{3,4}(?=\? )' , elem) .group ( ) , 'wb' )
f.write ( my_pic)
f.close ( )
break
except urllib .error .HTTPError :
continue
print ( 'done' )
print ( 'Введите тэг(и) gelbooru здесь, разделяя их знаком "+" \n Например: "pino", "ononoki_yotsugi+blush", "nagato_yuki+bondage+mirror" (без кавычек): ' )
tag = input ( '\ ' )
print ( 'Укажите кол-во изображений.\n Если кол-во не указано, будут загружаться все доступные картинки по заданным тэгам: ' )
x = input ( '\ ' )
print ( folder( tag) )
download( tag, x)
aW1wb3J0IG9zLCB1cmxsaWIucmVxdWVzdCwgcmUsIHRpbWUKZnJvbSByYW5kb20gaW1wb3J0ICoKZGVmIGZvbGRlcih0YWcpOgogICAgdHJ5OgogICAgICAgIG9zLm1rZGlyKHRhZyxtb2RlPTBvNzc3KQogICAgZXhjZXB0IEZpbGVFeGlzdHNFcnJvcjoKICAgICAgICBwYXNzCiAgICBvcy5jaGRpcih0YWcpCiAgICByZXR1cm4gInN0YXJ0aW5nLi4uIgpkZWYgcHJldih0YWdzLCBuKToKICAgIHRyeToKICAgICAgICBuID0gaW50KG4pCiAgICBleGNlcHQgVmFsdWVFcnJvcjoKICAgICAgICBuID0gMioqMjUKICAgIG91dCA9IFtdCiAgICBrID0gMAogICAgdCA9IDAKICAgIHJlcSA9ICdodHRwOi8vZy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4udS5jb20vaW5kZXgucGhwP3BhZ2U9cG9zdCZzPWxpc3QmdGFncz0nCiAgICBwaWQgPSAnJnBpZD0nCiAgICB3aGlsZSBsZW4ob3V0KSA8IG46CiAgICAgICAgdCA9IDAKICAgICAgICBwYWdlID0gdXJsbGliLnJlcXVlc3QudXJsb3BlbihyZXErdGFncytwaWQrc3RyKGspKS5yZWFkKCkuZGVjb2RlKCkKICAgICAgICB0aW1lLnNsZWVwKGZsb2F0KCcwLicrc3RyKHJhbmRpbnQoMiw5KSkpKSAj0J3QsCDQstGB0Y/QutC40Lkg0YHQu9GD0YfQsNC5LiDQkCDRgtC+INCy0LTRgNGD0LMg0L3QsNGBINC/0YDQuNC80YPRgiDQt9CwINCx0L7RgtC+0LIg0Lgg0YHRgtGD0LrQvdGD0YIg0LHQsNC90YXQsNC80LzQtdGA0L7QvC4gXl9eINCf0L4g0YHQstC+0LXQvNGDINGD0YHQvNC+0YLRgNC10L3QuNGOINGD0LTQsNC70LjRgtC1INGN0YLRgyDRgdGC0YDQvtGH0LrRgy4KICAgICAgICBmb3IgZWxlbSBpbiByZS5maW5kYWxsKHInaWRcPVxkK1wiID48aW1nIHNyYz1cIihbXlwiXSspJywgcGFnZSk6CiAgICAgICAgICAgIG91dC5hcHBlbmQoZWxlbSkKICAgICAgICAgICAgdCs9MQogICAgICAgIGsrPTQyCiAgICAgICAgaWYgdCA9PSAwOgogICAgICAgICAgICBicmVhawogICAgcmV0dXJuIG91dFs6bl0KZGVmIGxpbmsocHJlKToKICAgIG15X2xpbmsgPSAnaHR0cDovL2cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnUuY29tLy9pbWFnZXMnCiAgICBwID0gcmUuc3ViKHIndGh1bWJuYWlsXycsICcnLCByZS5zZWFyY2gocicoPzw9bmFpbHMpKC4rKScscHJlKS5ncm91cCgpKQogICAgcmV0dXJuIChteV9saW5rK3AsIChteV9saW5rK3ApLnJlcGxhY2UoJ2pwZycsJ2pwZWcnKSwKICAgICAgICAgICAgKG15X2xpbmsrcCkucmVwbGFjZSgnanBnJywnZ2lmJyksKG15X2xpbmsrcCkucmVwbGFjZSgnanBnJywncG5nJykpCmRlZiByYW5kbmFtZSh4KToKICAgIHJldHVybiAnJy4gam9pbihzYW1wbGUoc3RyKHJhbmRpbnQoMTExMTExMTExMTEsIDk5OTk5OTk5OTk5KSozKSArICcnLmpvaW4oW2NocihpKSogcmFuZGludCgxLDMpIGZvciBpIGluIHJhbmdlKDk3LDEyMyldKSwgeCkpCmRlZiBkb3dubG9hZCh0YWcsIHgpOgogICAgcHJ3ID0gcHJldih0YWcsIHgpCiAgICBwcmludCgnbG9hZGluZy4uLicpCiAgICBmb3IgaSBpbiBwcnc6CiAgICAgICAgcSA9IGxpbmsoaSkKICAgICAgICBmb3IgZWxlbSBpbiBxOgogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICBteV9waWMgPSB1cmxsaWIucmVxdWVzdC51cmxvcGVuKGVsZW0pLnJlYWQoKQogICAgICAgICAgICAgICAgZiA9IG9wZW4ocmFuZG5hbWUoMTYpICsgcmUuc2VhcmNoKHInXC5bYS16XXszLDR9KD89XD8pJywgZWxlbSkuZ3JvdXAoKSwgJ3diJykKICAgICAgICAgICAgICAgIGYud3JpdGUobXlfcGljKQogICAgICAgICAgICAgICAgZi5jbG9zZSgpCiAgICAgICAgICAgICAgICBicmVhawogICAgICAgICAgICBleGNlcHQgdXJsbGliLmVycm9yLkhUVFBFcnJvcjoKICAgICAgICAgICAgICAgIGNvbnRpbnVlCiAgICBwcmludCgnZG9uZScpCnByaW50KCfQktCy0LXQtNC40YLQtSDRgtGN0LMo0LgpIGdlbGJvb3J1INC30LTQtdGB0YwsINGA0LDQt9C00LXQu9GP0Y8g0LjRhSDQt9C90LDQutC+0LwgIisiIFxuINCd0LDQv9GA0LjQvNC10YA6ICJwaW5vIiwgIm9ub25va2lfeW90c3VnaStibHVzaCIsICJuYWdhdG9feXVraStib25kYWdlK21pcnJvciIgKNCx0LXQtyDQutCw0LLRi9GH0LXQuik6ICcpCnRhZyA9IGlucHV0KCdcICcpCnByaW50KCfQo9C60LDQttC40YLQtSDQutC+0Lst0LLQviDQuNC30L7QsdGA0LDQttC10L3QuNC5LlxuINCV0YHQu9C4INC60L7Quy3QstC+INC90LUg0YPQutCw0LfQsNC90L4sINCx0YPQtNGD0YIg0LfQsNCz0YDRg9C20LDRgtGM0YHRjyDQstGB0LUg0LTQvtGB0YLRg9C/0L3Ri9C1INC60LDRgNGC0LjQvdC60Lgg0L/QviDQt9Cw0LTQsNC90L3Ri9C8INGC0Y3Qs9Cw0Lw6ICcpCnggPSBpbnB1dCgnXCAnKQpwcmludChmb2xkZXIodGFnKSkKZG93bmxvYWQodGFnLCB4KQ==