mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 11:01:17 +02:00
merge to functions
This commit is contained in:
parent
139e01d3ca
commit
f157ac3246
@ -6,11 +6,11 @@ import platform
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from nhentai.cmdline import cmd_parser, banner
|
from nhentai.cmdline import cmd_parser, banner
|
||||||
from nhentai.parser import doujinshi_parser, search_parser, search_parser_all, print_doujinshi, favorites_parser
|
from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser
|
||||||
from nhentai.doujinshi import Doujinshi
|
from nhentai.doujinshi import Doujinshi
|
||||||
from nhentai.downloader import Downloader
|
from nhentai.downloader import Downloader
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
from nhentai.constant import BASE_URL
|
from nhentai.constant import BASE_URL, LANGUAGE
|
||||||
from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, \
|
from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, \
|
||||||
paging, check_cookie, signal_handler, DB
|
paging, check_cookie, signal_handler, DB
|
||||||
|
|
||||||
@ -40,19 +40,12 @@ def main():
|
|||||||
|
|
||||||
doujinshis = favorites_parser(page=page_list)
|
doujinshis = favorites_parser(page=page_list)
|
||||||
|
|
||||||
elif options.keyword and options.page_all:
|
|
||||||
from nhentai.constant import LANGUAGE
|
|
||||||
if LANGUAGE:
|
|
||||||
logger.info('Using default language: {0}'.format(LANGUAGE))
|
|
||||||
options.keyword += ', language:{}'.format(LANGUAGE)
|
|
||||||
doujinshis = search_parser_all(options.keyword)
|
|
||||||
|
|
||||||
elif options.keyword:
|
elif options.keyword:
|
||||||
from nhentai.constant import LANGUAGE
|
|
||||||
if LANGUAGE:
|
if LANGUAGE:
|
||||||
logger.info('Using default language: {0}'.format(LANGUAGE))
|
logger.info('Using default language: {0}'.format(LANGUAGE))
|
||||||
options.keyword += ', language:{}'.format(LANGUAGE)
|
options.keyword += ', language:{}'.format(LANGUAGE)
|
||||||
doujinshis = search_parser(options.keyword, sorting=options.sorting, page=page_list)
|
doujinshis = search_parser(options.keyword, sorting=options.sorting, page=page_list,
|
||||||
|
is_page_all=options.page_all)
|
||||||
|
|
||||||
elif not doujinshi_ids:
|
elif not doujinshi_ids:
|
||||||
doujinshi_ids = options.id
|
doujinshi_ids = options.id
|
||||||
|
@ -193,15 +193,23 @@ def print_doujinshi(doujinshi_list):
|
|||||||
tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
||||||
|
|
||||||
|
|
||||||
def search_parser(keyword, sorting, page):
|
def search_parser(keyword, sorting, page, is_page_all=False):
|
||||||
# keyword = '+'.join([i.strip().replace(' ', '-').lower() for i in keyword.split(',')])
|
# keyword = '+'.join([i.strip().replace(' ', '-').lower() for i in keyword.split(',')])
|
||||||
result = []
|
result = []
|
||||||
if not page:
|
if not page:
|
||||||
page = [1]
|
page = [1]
|
||||||
|
|
||||||
|
if is_page_all:
|
||||||
|
url = request('get', url=constant.SEARCH_URL, params={'query': keyword}).url
|
||||||
|
init_response = request('get', url.replace('%2B', '+')).json()
|
||||||
|
page = range(1, init_response['num_pages']+1)
|
||||||
|
|
||||||
for p in page:
|
for p in page:
|
||||||
i = 0
|
i = 0
|
||||||
logger.info('Searching doujinshis using keywords "{0}" on page {1}'.format(keyword, p))
|
if is_page_all:
|
||||||
|
total = '/{0}'.format(page[-1])
|
||||||
|
|
||||||
|
logger.info('Searching doujinshis using keywords "{0}" on page {1}{2}'.format(keyword, p, total))
|
||||||
while i < 3:
|
while i < 3:
|
||||||
try:
|
try:
|
||||||
url = request('get', url=constant.SEARCH_URL, params={'query': keyword,
|
url = request('get', url=constant.SEARCH_URL, params={'query': keyword,
|
||||||
@ -227,38 +235,6 @@ def search_parser(keyword, sorting, page):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def search_parser_all(keyword):
|
|
||||||
logger.debug('Searching doujinshis using keywords {0}'.format(keyword))
|
|
||||||
|
|
||||||
result = []
|
|
||||||
|
|
||||||
url = request('get', url=constant.SEARCH_URL, params={'query': keyword}).url
|
|
||||||
init_response = request('get', url.replace('%2B', '+')).json()
|
|
||||||
|
|
||||||
for page in range(init_response['num_pages']):
|
|
||||||
try:
|
|
||||||
url = request('get', url=constant.SEARCH_URL, params={'query': keyword, 'page': page+1}).url
|
|
||||||
response = request('get', url.replace('%2B', '+')).json()
|
|
||||||
|
|
||||||
print('Obtained %d / %d pages.' % (page+1, init_response['num_pages']), end='\r')
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.critical(str(e))
|
|
||||||
|
|
||||||
if 'result' not in response:
|
|
||||||
raise Exception('No result in response')
|
|
||||||
|
|
||||||
for row in response['result']:
|
|
||||||
title = row['title']['english']
|
|
||||||
title = title[:85] + '..' if len(title) > 85 else title
|
|
||||||
result.append({'id': row['id'], 'title': title})
|
|
||||||
|
|
||||||
if not result:
|
|
||||||
logger.warn('No results for keywords {}'.format(keyword))
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def __api_suspended_doujinshi_parser(id_):
|
def __api_suspended_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('Doujinshi id({0}) is not valid'.format(id_))
|
raise Exception('Doujinshi id({0}) is not valid'.format(id_))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user