mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-30 08:10:46 +02:00
support #291
This commit is contained in:
parent
a893f54da1
commit
d8e4f50609
@ -73,6 +73,8 @@ def cmd_parser():
|
|||||||
help='search doujinshi by keyword')
|
help='search doujinshi by keyword')
|
||||||
parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
|
parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
|
||||||
help='list or download your favorites')
|
help='list or download your favorites')
|
||||||
|
parser.add_option('--artist', '-a', action='store', dest='artist',
|
||||||
|
help='list doujinshi by artist name')
|
||||||
|
|
||||||
# page options
|
# page options
|
||||||
parser.add_option('--page-all', dest='page_all', action='store_true', default=False,
|
parser.add_option('--page-all', dest='page_all', action='store_true', default=False,
|
||||||
@ -216,7 +218,7 @@ def cmd_parser():
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not args.keyword and not args.id and not args.favorites:
|
if not args.keyword and not args.id and not args.favorites and not args.artist:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -57,6 +57,10 @@ def main():
|
|||||||
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)
|
is_page_all=options.page_all)
|
||||||
|
|
||||||
|
elif options.artist:
|
||||||
|
doujinshis = legacy_search_parser(options.artist, sorting=options.sorting, page=page_list,
|
||||||
|
is_page_all=options.page_all, type_='ARTIST')
|
||||||
|
|
||||||
elif not doujinshi_ids:
|
elif not doujinshi_ids:
|
||||||
doujinshi_ids = options.id
|
doujinshi_ids = options.id
|
||||||
|
|
||||||
|
@ -11,12 +11,14 @@ BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net')
|
|||||||
DETAIL_URL = f'{BASE_URL}/g'
|
DETAIL_URL = f'{BASE_URL}/g'
|
||||||
LEGACY_SEARCH_URL = f'{BASE_URL}/search/'
|
LEGACY_SEARCH_URL = f'{BASE_URL}/search/'
|
||||||
SEARCH_URL = f'{BASE_URL}/api/galleries/search'
|
SEARCH_URL = f'{BASE_URL}/api/galleries/search'
|
||||||
|
ARTIST_URL = f'{BASE_URL}/artist/'
|
||||||
|
|
||||||
TAG_API_URL = f'{BASE_URL}/api/galleries/tagged'
|
TAG_API_URL = f'{BASE_URL}/api/galleries/tagged'
|
||||||
LOGIN_URL = f'{BASE_URL}/login/'
|
LOGIN_URL = f'{BASE_URL}/login/'
|
||||||
CHALLENGE_URL = f'{BASE_URL}/challenge'
|
CHALLENGE_URL = f'{BASE_URL}/challenge'
|
||||||
FAV_URL = f'{BASE_URL}/favorites/'
|
FAV_URL = f'{BASE_URL}/favorites/'
|
||||||
|
|
||||||
|
|
||||||
IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries'
|
IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries'
|
||||||
|
|
||||||
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
|
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
|
||||||
|
@ -135,6 +135,7 @@ def doujinshi_parser(id_, counter=0):
|
|||||||
logger.warning(f'Error: {e}, ignored')
|
logger.warning(f'Error: {e}, ignored')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
print(response)
|
||||||
html = BeautifulSoup(response, 'html.parser')
|
html = BeautifulSoup(response, 'html.parser')
|
||||||
doujinshi_info = html.find('div', attrs={'id': 'info'})
|
doujinshi_info = html.find('div', attrs={'id': 'info'})
|
||||||
|
|
||||||
@ -240,13 +241,21 @@ def print_doujinshi(doujinshi_list):
|
|||||||
print(tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
print(tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
||||||
|
|
||||||
|
|
||||||
def legacy_search_parser(keyword, sorting, page, is_page_all=False):
|
def legacy_search_parser(keyword, sorting, page, is_page_all=False, type_='SEARCH'):
|
||||||
logger.info(f'Searching doujinshis of keyword {keyword}')
|
logger.info(f'Searching doujinshis of keyword {keyword}')
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
if type_ not in ('SEARCH', 'ARTIST', ):
|
||||||
|
raise ValueError('Invalid type')
|
||||||
|
|
||||||
if is_page_all:
|
if is_page_all:
|
||||||
|
if type_ == 'SEARCH':
|
||||||
response = request('get', url=constant.LEGACY_SEARCH_URL,
|
response = request('get', url=constant.LEGACY_SEARCH_URL,
|
||||||
params={'q': keyword, 'page': 1, 'sort': sorting}).content
|
params={'q': keyword, 'page': 1, 'sort': sorting}).content
|
||||||
|
else:
|
||||||
|
url = constant.ARTIST_URL + keyword + '/' + ('' if sorting == 'recent' else sorting)
|
||||||
|
response = request('get', url=url, params={'page': 1}).content
|
||||||
|
|
||||||
html = BeautifulSoup(response, 'lxml')
|
html = BeautifulSoup(response, 'lxml')
|
||||||
pagination = html.find(attrs={'class': 'pagination'})
|
pagination = html.find(attrs={'class': 'pagination'})
|
||||||
last_page = pagination.find(attrs={'class': 'last'})
|
last_page = pagination.find(attrs={'class': 'last'})
|
||||||
@ -258,8 +267,14 @@ def legacy_search_parser(keyword, sorting, page, is_page_all=False):
|
|||||||
|
|
||||||
for p in pages:
|
for p in pages:
|
||||||
logger.info(f'Fetching page {p} ...')
|
logger.info(f'Fetching page {p} ...')
|
||||||
|
if type_ == 'SEARCH':
|
||||||
response = request('get', url=constant.LEGACY_SEARCH_URL,
|
response = request('get', url=constant.LEGACY_SEARCH_URL,
|
||||||
params={'q': keyword, 'page': p, 'sort': sorting}).content
|
params={'q': keyword, 'page': p, 'sort': sorting}).content
|
||||||
|
else:
|
||||||
|
url = constant.ARTIST_URL + keyword + '/' + ('' if sorting == 'recent' else sorting)
|
||||||
|
print(url)
|
||||||
|
response = request('get', url=url, params={'page': p}).content
|
||||||
|
|
||||||
if response is None:
|
if response is None:
|
||||||
logger.warning(f'No result in response in page {p}')
|
logger.warning(f'No result in response in page {p}')
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user