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