mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 11:00:55 +01:00 
			
		
		
		
	a shocking typo: dojinshi -> doujinsi
This commit is contained in:
		@@ -1,2 +1,2 @@
 | 
			
		||||
include README.md
 | 
			
		||||
include requirements.txt
 | 
			
		||||
include requirements.txt
 | 
			
		||||
 
 | 
			
		||||
@@ -19,18 +19,18 @@ def banner():
 | 
			
		||||
 | 
			
		||||
def cmd_parser():
 | 
			
		||||
    parser = OptionParser()
 | 
			
		||||
    parser.add_option('--download', dest='is_download', action='store_true', help='download dojinshi or not')
 | 
			
		||||
    parser.add_option('--id', type='int', dest='id', action='store', help='dojinshi id of nhentai')
 | 
			
		||||
    parser.add_option('--ids', type='str', dest='ids', action='store', help='dojinshi id set, e.g. 1,2,3')
 | 
			
		||||
    parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not')
 | 
			
		||||
    parser.add_option('--id', type='int', dest='id', action='store', help='doujinshi id of nhentai')
 | 
			
		||||
    parser.add_option('--ids', type='str', dest='ids', action='store', help='doujinshi id set, e.g. 1,2,3')
 | 
			
		||||
    parser.add_option('--search', type='string', dest='keyword', action='store', help='keyword searched')
 | 
			
		||||
    parser.add_option('--page', type='int', dest='page', action='store', default=1,
 | 
			
		||||
                      help='page number of search result')
 | 
			
		||||
    parser.add_option('--path', type='string', dest='saved_path', action='store', default='',
 | 
			
		||||
                      help='path which save the dojinshi')
 | 
			
		||||
                      help='path which save the doujinshi')
 | 
			
		||||
    parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
 | 
			
		||||
                      help='thread count of download dojinshi')
 | 
			
		||||
                      help='thread count of download doujinshi')
 | 
			
		||||
    parser.add_option('--timeout', type='int', dest='timeout', action='store', default=30,
 | 
			
		||||
                      help='timeout of download dojinshi')
 | 
			
		||||
                      help='timeout of download doujinshi')
 | 
			
		||||
    args, _ = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
    if args.ids:
 | 
			
		||||
@@ -38,7 +38,7 @@ def cmd_parser():
 | 
			
		||||
        args.ids = set(map(int, filter(lambda id: id.isdigit(), _)))
 | 
			
		||||
 | 
			
		||||
    if args.is_download and not args.id and not args.ids and not args.keyword:
 | 
			
		||||
        logger.critical('Dojinshi id/ids is required for downloading')
 | 
			
		||||
        logger.critical('Doujinshi id/ids is required for downloading')
 | 
			
		||||
        parser.print_help()
 | 
			
		||||
        raise SystemExit
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,8 @@
 | 
			
		||||
# coding: utf-8
 | 
			
		||||
import signal
 | 
			
		||||
from cmdline import cmd_parser, banner
 | 
			
		||||
from parser import dojinshi_parser, search_parser, print_dojinshi
 | 
			
		||||
from dojinshi import Dojinshi
 | 
			
		||||
from parser import doujinshi_parser, search_parser, print_doujinshi
 | 
			
		||||
from doujinshi import Doujinshi
 | 
			
		||||
from downloader import Downloader
 | 
			
		||||
from logger import logger
 | 
			
		||||
 | 
			
		||||
@@ -14,32 +14,32 @@ def main():
 | 
			
		||||
 | 
			
		||||
    logger.log(15, 'nHentai: あなたも変態。 いいね?')
 | 
			
		||||
 | 
			
		||||
    dojinshi_ids = []
 | 
			
		||||
    dojinshi_list = []
 | 
			
		||||
    doujinshi_ids = []
 | 
			
		||||
    doujinshi_list = []
 | 
			
		||||
 | 
			
		||||
    if options.keyword:
 | 
			
		||||
        dojinshis = search_parser(options.keyword, options.page)
 | 
			
		||||
        print_dojinshi(dojinshis)
 | 
			
		||||
        doujinshis = search_parser(options.keyword, options.page)
 | 
			
		||||
        print_doujinshi(doujinshis)
 | 
			
		||||
        if options.is_download:
 | 
			
		||||
            dojinshi_ids = map(lambda d: d['id'], dojinshis)
 | 
			
		||||
            doujinshi_ids = map(lambda d: d['id'], doujinshis)
 | 
			
		||||
    else:
 | 
			
		||||
        dojinshi_ids = options.ids
 | 
			
		||||
        doujinshi_ids = options.ids
 | 
			
		||||
 | 
			
		||||
    if dojinshi_ids:
 | 
			
		||||
        for id in dojinshi_ids:
 | 
			
		||||
            dojinshi_info = dojinshi_parser(id)
 | 
			
		||||
            dojinshi_list.append(Dojinshi(**dojinshi_info))
 | 
			
		||||
    if doujinshi_ids:
 | 
			
		||||
        for id in doujinshi_ids:
 | 
			
		||||
            doujinshi_info = doujinshi_parser(id)
 | 
			
		||||
            doujinshi_list.append(Doujinshi(**doujinshi_info))
 | 
			
		||||
    else:
 | 
			
		||||
        raise SystemExit
 | 
			
		||||
 | 
			
		||||
    if options.is_download:
 | 
			
		||||
        downloader = Downloader(path=options.saved_path,
 | 
			
		||||
                                thread=options.threads, timeout=options.timeout)
 | 
			
		||||
        for dojinshi in dojinshi_list:
 | 
			
		||||
            dojinshi.downloader = downloader
 | 
			
		||||
            dojinshi.download()
 | 
			
		||||
        for doujinshi in doujinshi_list:
 | 
			
		||||
            doujinshi.downloader = downloader
 | 
			
		||||
            doujinshi.download()
 | 
			
		||||
    else:
 | 
			
		||||
        map(lambda dojinshi: dojinshi.show(), dojinshi_list)
 | 
			
		||||
        map(lambda doujinshi: doujinshi.show(), doujinshi_list)
 | 
			
		||||
 | 
			
		||||
    logger.log(15, u'🍺 All done.')
 | 
			
		||||
 | 
			
		||||
@@ -50,4 +50,4 @@ def signal_handler(signal, frame):
 | 
			
		||||
 | 
			
		||||
signal.signal(signal.SIGINT, signal_handler)
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    main()
 | 
			
		||||
    main()
 | 
			
		||||
 
 | 
			
		||||
@@ -2,4 +2,4 @@ SCHEMA = 'http://'
 | 
			
		||||
URL = '%snhentai.net' % SCHEMA
 | 
			
		||||
DETAIL_URL = '%s/g' % URL
 | 
			
		||||
IMAGE_URL = '%si.nhentai.net/galleries' % SCHEMA
 | 
			
		||||
SEARCH_URL = '%s/search/' % URL
 | 
			
		||||
SEARCH_URL = '%s/search/' % URL
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ from constant import DETAIL_URL, IMAGE_URL
 | 
			
		||||
from logger import logger
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Dojinshi(object):
 | 
			
		||||
class Doujinshi(object):
 | 
			
		||||
    def __init__(self, name=None, subtitle=None, id=None, img_id=None, ext='jpg', pages=0):
 | 
			
		||||
        self.name = name
 | 
			
		||||
        self.subtitle = subtitle
 | 
			
		||||
@@ -16,17 +16,17 @@ class Dojinshi(object):
 | 
			
		||||
        self.url = '%s/%d' % (DETAIL_URL, self.id)
 | 
			
		||||
 | 
			
		||||
    def __repr__(self):
 | 
			
		||||
        return '<Dojinshi: %s>' % self.name
 | 
			
		||||
        return '<Doujinshi: %s>' % self.name
 | 
			
		||||
 | 
			
		||||
    def show(self):
 | 
			
		||||
        logger.info('Print dojinshi information')
 | 
			
		||||
        print('Dojinshi: %s' % self.name)
 | 
			
		||||
        logger.info('Print doujinshi information')
 | 
			
		||||
        print('Doujinshi: %s' % self.name)
 | 
			
		||||
        print('Subtitle: %s' % self.subtitle)
 | 
			
		||||
        print('URL: %s' % self.url)
 | 
			
		||||
        print('Pages: %d' % self.pages)
 | 
			
		||||
 | 
			
		||||
    def download(self):
 | 
			
		||||
        logger.info('Start download dojinshi: %s' % self.name)
 | 
			
		||||
        logger.info('Start download doujinshi: %s' % self.name)
 | 
			
		||||
        if self.downloader:
 | 
			
		||||
            download_queue = []
 | 
			
		||||
            for i in xrange(1, self.pages + 1):
 | 
			
		||||
@@ -37,7 +37,7 @@ class Dojinshi(object):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    test = Dojinshi(name='test nhentai dojinshi', id=1)
 | 
			
		||||
    test = Doujinshi(name='test nhentai doujinshi', id=1)
 | 
			
		||||
    print(test)
 | 
			
		||||
    test.show()
 | 
			
		||||
    try:
 | 
			
		||||
 
 | 
			
		||||
@@ -9,13 +9,13 @@ from logger import logger
 | 
			
		||||
from tabulate import tabulate
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def dojinshi_parser(id):
 | 
			
		||||
def doujinshi_parser(id):
 | 
			
		||||
    if not isinstance(id, (int, )) and (isinstance(id, (str, )) and not id.isdigit()):
 | 
			
		||||
        raise Exception('Dojinshi id(%s) is not valid' % str(id))
 | 
			
		||||
        raise Exception('Doujinshi id(%s) is not valid' % str(id))
 | 
			
		||||
    id = int(id)
 | 
			
		||||
    logger.debug('Fetching dojinshi information of id %d' % id)
 | 
			
		||||
    dojinshi = dict()
 | 
			
		||||
    dojinshi['id'] = id
 | 
			
		||||
    logger.debug('Fetching doujinshi information of id %d' % id)
 | 
			
		||||
    doujinshi = dict()
 | 
			
		||||
    doujinshi['id'] = id
 | 
			
		||||
    url = '%s/%d/' % (DETAIL_URL, id)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
@@ -25,54 +25,54 @@ def dojinshi_parser(id):
 | 
			
		||||
        sys.exit()
 | 
			
		||||
 | 
			
		||||
    html = BeautifulSoup(response)
 | 
			
		||||
    dojinshi_info = html.find('div', attrs={'id': 'info'})
 | 
			
		||||
    doujinshi_info = html.find('div', attrs={'id': 'info'})
 | 
			
		||||
 | 
			
		||||
    title = dojinshi_info.find('h1').text
 | 
			
		||||
    subtitle = dojinshi_info.find('h2')
 | 
			
		||||
    title = doujinshi_info.find('h1').text
 | 
			
		||||
    subtitle = doujinshi_info.find('h2')
 | 
			
		||||
 | 
			
		||||
    dojinshi['name'] = title
 | 
			
		||||
    dojinshi['subtitle'] = subtitle.text if subtitle else ''
 | 
			
		||||
    doujinshi['name'] = title
 | 
			
		||||
    doujinshi['subtitle'] = subtitle.text if subtitle else ''
 | 
			
		||||
 | 
			
		||||
    dojinshi_cover = html.find('div', attrs={'id': 'cover'})
 | 
			
		||||
    img_id = re.search('/galleries/([\d]+)/cover\.(jpg|png)$', dojinshi_cover.a.img['src'])
 | 
			
		||||
    doujinshi_cover = html.find('div', attrs={'id': 'cover'})
 | 
			
		||||
    img_id = re.search('/galleries/([\d]+)/cover\.(jpg|png)$', doujinshi_cover.a.img['src'])
 | 
			
		||||
    if not img_id:
 | 
			
		||||
        logger.critical('Tried yo get image id failed')
 | 
			
		||||
        sys.exit()
 | 
			
		||||
    dojinshi['img_id'] = img_id.group(1)
 | 
			
		||||
    dojinshi['ext'] = img_id.group(2)
 | 
			
		||||
    doujinshi['img_id'] = img_id.group(1)
 | 
			
		||||
    doujinshi['ext'] = img_id.group(2)
 | 
			
		||||
 | 
			
		||||
    pages = 0
 | 
			
		||||
    for _ in dojinshi_info.find_all('div', class_=''):
 | 
			
		||||
    for _ in doujinshi_info.find_all('div', class_=''):
 | 
			
		||||
        pages = re.search('([\d]+) pages', _.text)
 | 
			
		||||
        if pages:
 | 
			
		||||
            pages = pages.group(1)
 | 
			
		||||
            break
 | 
			
		||||
    dojinshi['pages'] = int(pages)
 | 
			
		||||
    return dojinshi
 | 
			
		||||
    doujinshi['pages'] = int(pages)
 | 
			
		||||
    return doujinshi
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def search_parser(keyword, page):
 | 
			
		||||
    logger.debug('Searching dojinshis of keyword %s' % keyword)
 | 
			
		||||
    logger.debug('Searching doujinshis of keyword %s' % keyword)
 | 
			
		||||
    result = []
 | 
			
		||||
    response = requests.get(SEARCH_URL, params={'q': keyword, 'page': page}).content
 | 
			
		||||
    html = BeautifulSoup(response)
 | 
			
		||||
    dojinshi_search_result = html.find_all('div', attrs={'class': 'gallery'})
 | 
			
		||||
    for dojinshi in dojinshi_search_result:
 | 
			
		||||
        dojinshi_container = dojinshi.find('div', attrs={'class': 'caption'})
 | 
			
		||||
        title = dojinshi_container.text.strip()
 | 
			
		||||
    doujinshi_search_result = html.find_all('div', attrs={'class': 'gallery'})
 | 
			
		||||
    for doujinshi in doujinshi_search_result:
 | 
			
		||||
        doujinshi_container = doujinshi.find('div', attrs={'class': 'caption'})
 | 
			
		||||
        title = doujinshi_container.text.strip()
 | 
			
		||||
        title = (title[:85] + '..') if len(title) > 85 else title
 | 
			
		||||
        id_ = re.search('/g/(\d+)/', dojinshi.a['href']).group(1)
 | 
			
		||||
        id_ = re.search('/g/(\d+)/', doujinshi.a['href']).group(1)
 | 
			
		||||
        result.append({'id': id_, 'title': title})
 | 
			
		||||
    return result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def print_dojinshi(dojinshi_list):
 | 
			
		||||
    if not dojinshi_list:
 | 
			
		||||
def print_doujinshi(doujinshi_list):
 | 
			
		||||
    if not doujinshi_list:
 | 
			
		||||
        return
 | 
			
		||||
    dojinshi_list = [i.values() for i in dojinshi_list]
 | 
			
		||||
    headers = ['id', 'dojinshi']
 | 
			
		||||
    doujinshi_list = [i.values() for i in doujinshi_list]
 | 
			
		||||
    headers = ['id', 'doujinshi']
 | 
			
		||||
    logger.info('Search Result\n' +
 | 
			
		||||
                tabulate(tabular_data=dojinshi_list, headers=headers, tablefmt='rst'))
 | 
			
		||||
                tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    print(dojinshi_parser("32271"))
 | 
			
		||||
    print(doujinshi_parser("32271"))
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
requests>=2.5.0
 | 
			
		||||
BeautifulSoup4>=4.0.0
 | 
			
		||||
threadpool>=1.2.7
 | 
			
		||||
tabulate>=0.7.5
 | 
			
		||||
tabulate>=0.7.5
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								setup.py
									
									
									
									
									
								
							@@ -11,8 +11,8 @@ setup(
 | 
			
		||||
 | 
			
		||||
    author=__author__,
 | 
			
		||||
    author_email=__email__,
 | 
			
		||||
    keywords='nhentai, dojinshi',
 | 
			
		||||
    description='nhentai.net dojinshis downloader',
 | 
			
		||||
    keywords='nhentai, doujinshi',
 | 
			
		||||
    description='nhentai.net doujinshis downloader',
 | 
			
		||||
    url='https://github.com/RicterZ/nhentai',
 | 
			
		||||
    include_package_data=True,
 | 
			
		||||
    zip_safe=False,
 | 
			
		||||
@@ -24,4 +24,4 @@ setup(
 | 
			
		||||
        ]
 | 
			
		||||
    },
 | 
			
		||||
    license='MIT',
 | 
			
		||||
)
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user