diff --git a/MANIFEST.in b/MANIFEST.in index 3d387c3..8afbefe 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include README.md -include requirements.txt \ No newline at end of file +include requirements.txt diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 380757c..891d1ab 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -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 diff --git a/nhentai/command.py b/nhentai/command.py index 87bc795..647952c 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -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() \ No newline at end of file + main() diff --git a/nhentai/constant.py b/nhentai/constant.py index 476978c..5196bd7 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -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 \ No newline at end of file +SEARCH_URL = '%s/search/' % URL diff --git a/nhentai/dojinshi.py b/nhentai/dojinshi.py index 8d9afaa..a954b80 100644 --- a/nhentai/dojinshi.py +++ b/nhentai/dojinshi.py @@ -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 '' % self.name + return '' % 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: diff --git a/nhentai/parser.py b/nhentai/parser.py index 9c51a87..7585a29 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -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")) diff --git a/requirements.txt b/requirements.txt index 6d113e0..b48abcf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ requests>=2.5.0 BeautifulSoup4>=4.0.0 threadpool>=1.2.7 -tabulate>=0.7.5 \ No newline at end of file +tabulate>=0.7.5 diff --git a/setup.py b/setup.py index 199b3ca..00eb635 100644 --- a/setup.py +++ b/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', -) \ No newline at end of file +)