Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #coded by Agunq
- #email agunq.e@gmail.com
- #last test 25 Feb 2021
- import re
- import sys
- import os
- import threading
- if sys.version_info[0] < 3:
- class urllib:
- request = __import__("urllib2")
- input = raw_input
- else:
- import urllib.request
- def nhentai_get_page(gid):
- host = "nhentai"
- url = "%s://%s.net/g/%s/1/" % ("ht" + "tps", host, gid)
- hdr = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)' }
- req = urllib.request.Request(url, headers = hdr)
- resp = urllib.request.urlopen(req).read().decode("utf-8")
- pages = re.search("<span class=\"num-pages\">(.*?)<\/span><\/button>", resp)
- if pages:
- pages = int(pages.group(1))
- img = re.findall("<img src=\"(.*?)\"(.*?|)>", resp)
- if len(img) > 0:
- img = img[1][0]
- imgid = img.split("/")[4]
- ext = img.split(".")[-1]
- newset = []
- for i in range(1, pages + 1):
- url_image = "%s://i.%s.net/galleries/%s/%s.%s" % ("ht" + "tps", host, imgid, i, ext)
- newset.append(url_image)
- return newset
- def nhentai_get_image(gid, url_images):
- host = "nhentai"
- for url in url_images:
- try:
- if not os.path.exists('%s-%s' % (host, gid)):
- os.makedirs('%s-%s' % (host, gid))
- hdr = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)' }
- req = urllib.request.Request(url, headers = hdr)
- resp = urllib.request.urlopen(req).read()
- print("[now] [download] %s-%s/%s" % (host, gid, url.split("/")[-1]))
- f = open("%s-%s/%s" % (host, gid, url.split("/")[-1]), "wb+")
- f.write(resp)
- f.close()
- except:
- print("[error] [failed] [download] %s-%s/%s" % (host, gid, url.split("/")[-1]))
- next
- def chunk_list(lis, chunk_size):
- for i in range(0, len(lis), chunk_size):
- yield lis[i:i + chunk_size]
- def nhentai(gid):
- print("[start] [download] %s" % gid)
- url_images = nhentai_get_page(gid)
- url_images = chunk_list(url_images, int(int(len(url_images))/5)) # 5 = total threads, you can change it to 10 or more
- thread_list = []
- num = 0
- for url in url_images:
- th = threading.Thread(target=nhentai_get_image, args=(gid, url, ))
- th.start()
- thread_list.append(th)
- num += 1
- for thread in thread_list:
- thread.join()
- print("[finish] [done] %s" % gid)
- #example
- nhentai("161745")
Add Comment
Please, Sign In to add comment