mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 02:50:55 +01:00 
			
		
		
		
	max page #26
This commit is contained in:
		@@ -47,6 +47,8 @@ def cmd_parser():
 | 
				
			|||||||
    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('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag')
 | 
					    parser.add_option('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag')
 | 
				
			||||||
 | 
					    parser.add_option('--max-page', type='int', dest='max_page', action='store', default=1,
 | 
				
			||||||
 | 
					                      help='The max page when recursive download tagged doujinshi')
 | 
				
			||||||
    parser.add_option('--output', type='string', dest='output_dir', action='store', default='',
 | 
					    parser.add_option('--output', type='string', dest='output_dir', action='store', default='',
 | 
				
			||||||
                      help='output dir')
 | 
					                      help='output dir')
 | 
				
			||||||
    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,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ def main():
 | 
				
			|||||||
    if options.tag:
 | 
					    if options.tag:
 | 
				
			||||||
        tag_id = tag_guessing(options.tag)
 | 
					        tag_id = tag_guessing(options.tag)
 | 
				
			||||||
        if tag_id:
 | 
					        if tag_id:
 | 
				
			||||||
            doujinshis = tag_parser(tag_id)
 | 
					            doujinshis = tag_parser(tag_id, max_page=options.max_page)
 | 
				
			||||||
            print_doujinshi(doujinshis)
 | 
					            print_doujinshi(doujinshis)
 | 
				
			||||||
            if options.is_download:
 | 
					            if options.is_download:
 | 
				
			||||||
                doujinshi_ids = map(lambda d: d['id'], doujinshis)
 | 
					                doujinshi_ids = map(lambda d: d['id'], doujinshis)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -161,15 +161,22 @@ def print_doujinshi(doujinshi_list):
 | 
				
			|||||||
    logger.info('Search Result\n{}'.format(data))
 | 
					    logger.info('Search Result\n{}'.format(data))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def tag_parser(tag_id):
 | 
					def tag_parser(tag_id, max_page=1):
 | 
				
			||||||
    logger.info('Get doujinshi of tag id: {0}'.format(tag_id))
 | 
					    logger.info('Get doujinshi of tag id: {0}'.format(tag_id))
 | 
				
			||||||
    result = []
 | 
					    result = []
 | 
				
			||||||
    response = request('get', url=constant.TAG_API_URL, params={'sort': 'popular', 'tag_id': tag_id}).json()
 | 
					    response = request('get', url=constant.TAG_API_URL, params={'sort': 'popular', 'tag_id': tag_id}).json()
 | 
				
			||||||
 | 
					    page = max_page if max_page <= response['num_pages'] else int(response['num_pages'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for row in response['result']:
 | 
					    for i in range(1, page+1):
 | 
				
			||||||
        title = row['title']['english']
 | 
					        logger.info('Get page {} ...'.format(i))
 | 
				
			||||||
        title = title[:85] + '..' if len(title) > 85 else title
 | 
					
 | 
				
			||||||
        result.append({'id': row['id'], 'title': title})
 | 
					        if page != 1:
 | 
				
			||||||
 | 
					            response = request('get', url=constant.TAG_API_URL, params={'sort': 'popular', 'tag_id': tag_id}).json()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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:
 | 
					    if not result:
 | 
				
			||||||
        logger.warn('Not found anything of tag id {}'.format(tag_id))
 | 
					        logger.warn('Not found anything of tag id {}'.format(tag_id))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user