diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 0450f61..e88a80f 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -124,6 +124,8 @@ def cmd_parser(): help='clean download history') parser.add_option('--template', dest='viewer_template', action='store', help='set viewer template', default='') + parser.add_option('--legacy', dest='legacy', action='store_true', default=False, + help='use legacy searching method') try: sys.argv = [unicode(i.decode(sys.stdin.encoding)) for i in sys.argv] diff --git a/nhentai/command.py b/nhentai/command.py index 2995fee..4230d08 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -8,7 +8,7 @@ import time from nhentai import constant from nhentai.cmdline import cmd_parser, banner -from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser +from nhentai.parser import doujinshi_parser, search_parser, legacy_search_parser, print_doujinshi, favorites_parser from nhentai.doujinshi import Doujinshi from nhentai.downloader import Downloader from nhentai.logger import logger @@ -55,8 +55,10 @@ def main(): if constant.CONFIG['language']: logger.info('Using default language: {0}'.format(constant.CONFIG['language'])) options.keyword += ' language:{}'.format(constant.CONFIG['language']) - doujinshis = search_parser(options.keyword, sorting=options.sorting, page=page_list, - is_page_all=options.page_all) + + _search_parser = legacy_search_parser if options.legacy else search_parser + doujinshis = _search_parser(options.keyword, sorting=options.sorting, page=page_list, + is_page_all=options.page_all) elif not doujinshi_ids: doujinshi_ids = options.id diff --git a/nhentai/constant.py b/nhentai/constant.py index e100898..435ac78 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -14,6 +14,7 @@ BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net') __api_suspended_DETAIL_URL = '%s/api/gallery' % BASE_URL DETAIL_URL = '%s/g' % BASE_URL +LEGACY_SEARCH_URL = '%s/search/' % BASE_URL SEARCH_URL = '%s/api/galleries/search' % BASE_URL diff --git a/nhentai/parser.py b/nhentai/parser.py index 3ebcabb..85b20d0 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -177,9 +177,11 @@ def doujinshi_parser(id_): return doujinshi -def old_search_parser(keyword, sorting='date', page=1): +def legacy_search_parser(keyword, sorting='date', page=1, is_page_all=False): + logger.warning('Using legacy searching method, `--all` options will not be supported') logger.debug('Searching doujinshis of keyword {0}'.format(keyword)) - response = request('get', url=constant.SEARCH_URL, params={'q': keyword, 'page': page, 'sort': sorting}).content + response = request('get', url=constant.LEGACY_SEARCH_URL, + params={'q': keyword, 'page': page, 'sort': sorting}).content result = _get_title_and_id(response) if not result: