mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 02:50:55 +01:00 
			
		
		
		
	support #291
This commit is contained in:
		@@ -73,6 +73,8 @@ def cmd_parser():
 | 
			
		||||
                      help='search doujinshi by keyword')
 | 
			
		||||
    parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
 | 
			
		||||
                      help='list or download your favorites')
 | 
			
		||||
    parser.add_option('--artist', '-a', action='store', dest='artist',
 | 
			
		||||
                      help='list doujinshi by artist name')
 | 
			
		||||
 | 
			
		||||
    # page options
 | 
			
		||||
    parser.add_option('--page-all', dest='page_all', action='store_true', default=False,
 | 
			
		||||
@@ -216,7 +218,7 @@ def cmd_parser():
 | 
			
		||||
        parser.print_help()
 | 
			
		||||
        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()
 | 
			
		||||
        sys.exit(1)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,10 @@ def main():
 | 
			
		||||
        doujinshis = _search_parser(options.keyword, sorting=options.sorting, page=page_list,
 | 
			
		||||
                                    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:
 | 
			
		||||
        doujinshi_ids = options.id
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,12 +11,14 @@ BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net')
 | 
			
		||||
DETAIL_URL = f'{BASE_URL}/g'
 | 
			
		||||
LEGACY_SEARCH_URL = f'{BASE_URL}/search/'
 | 
			
		||||
SEARCH_URL = f'{BASE_URL}/api/galleries/search'
 | 
			
		||||
ARTIST_URL = f'{BASE_URL}/artist/'
 | 
			
		||||
 | 
			
		||||
TAG_API_URL = f'{BASE_URL}/api/galleries/tagged'
 | 
			
		||||
LOGIN_URL = f'{BASE_URL}/login/'
 | 
			
		||||
CHALLENGE_URL = f'{BASE_URL}/challenge'
 | 
			
		||||
FAV_URL = f'{BASE_URL}/favorites/'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries'
 | 
			
		||||
 | 
			
		||||
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')
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    print(response)
 | 
			
		||||
    html = BeautifulSoup(response, 'html.parser')
 | 
			
		||||
    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'))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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}')
 | 
			
		||||
    result = []
 | 
			
		||||
 | 
			
		||||
    if type_ not in ('SEARCH', 'ARTIST', ):
 | 
			
		||||
        raise ValueError('Invalid type')
 | 
			
		||||
 | 
			
		||||
    if is_page_all:
 | 
			
		||||
        response = request('get', url=constant.LEGACY_SEARCH_URL,
 | 
			
		||||
                           params={'q': keyword, 'page': 1, 'sort': sorting}).content
 | 
			
		||||
        if type_ == 'SEARCH':
 | 
			
		||||
            response = request('get', url=constant.LEGACY_SEARCH_URL,
 | 
			
		||||
                               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')
 | 
			
		||||
        pagination = html.find(attrs={'class': 'pagination'})
 | 
			
		||||
        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:
 | 
			
		||||
        logger.info(f'Fetching page {p} ...')
 | 
			
		||||
        response = request('get', url=constant.LEGACY_SEARCH_URL,
 | 
			
		||||
                           params={'q': keyword, 'page': p, 'sort': sorting}).content
 | 
			
		||||
        if type_ == 'SEARCH':
 | 
			
		||||
            response = request('get', url=constant.LEGACY_SEARCH_URL,
 | 
			
		||||
                               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:
 | 
			
		||||
            logger.warning(f'No result in response in page {p}')
 | 
			
		||||
            continue
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user