mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 11:00:55 +01:00 
			
		
		
		
	search for download
This commit is contained in:
		@@ -8,7 +8,7 @@ def banner():
 | 
			
		||||
    print '''       _   _            _        _
 | 
			
		||||
 _ __ | | | | ___ _ __ | |_ __ _(_)
 | 
			
		||||
| '_ \| |_| |/ _ \ '_ \| __/ _` | |
 | 
			
		||||
| | | |  _  |  __/ | | | || (_| |w |
 | 
			
		||||
| | | |  _  |  __/ | | | || (_| | |
 | 
			
		||||
|_| |_|_| |_|\___|_| |_|\__\__,_|_|
 | 
			
		||||
'''
 | 
			
		||||
 | 
			
		||||
@@ -30,7 +30,7 @@ def cmd_parser():
 | 
			
		||||
        _ = map(lambda id: id.strip(), args.ids.split(','))
 | 
			
		||||
        args.ids = set(map(int, ifilter(lambda id: id.isdigit(), _)))
 | 
			
		||||
 | 
			
		||||
    if args.is_download and not args.id and not args.ids:
 | 
			
		||||
    if args.is_download and not args.id and not args.ids and not args.keyword:
 | 
			
		||||
        logger.critical('Dojinshi id/ids is required for downloading')
 | 
			
		||||
        parser.print_help()
 | 
			
		||||
        raise SystemExit
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
SCHEMA = 'http://'
 | 
			
		||||
URL = '%snhentai.net' % SCHEMA
 | 
			
		||||
DETAIL_URL = '%s/g' % URL
 | 
			
		||||
IMAGE_URL = '%si.nhentai.net/galleries' % SCHEMA
 | 
			
		||||
IMAGE_URL = '%si.nhentai.net/galleries' % SCHEMA
 | 
			
		||||
SEARCH_URL = '%s/search/' % URL
 | 
			
		||||
@@ -87,4 +87,3 @@ class Downloader(object):
 | 
			
		||||
 | 
			
		||||
        # clean threads list
 | 
			
		||||
        self.threads = []
 | 
			
		||||
        logger.log(15, u'🍺 All done, saved to \'%s\'!' % folder)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,15 +2,15 @@ import sys
 | 
			
		||||
import re
 | 
			
		||||
import requests
 | 
			
		||||
from bs4 import BeautifulSoup
 | 
			
		||||
from constant import DETAIL_URL
 | 
			
		||||
from constant import DETAIL_URL, SEARCH_URL
 | 
			
		||||
from hentai.logger import logger
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def dojinshi_parser(id):
 | 
			
		||||
    logger.debug('Fetching dojinshi information')
 | 
			
		||||
    if not isinstance(id, (int, )) or (isinstance(id, (str, )) and not id.isdigit()):
 | 
			
		||||
    if not isinstance(id, (int, )) and (isinstance(id, (str, )) and not id.isdigit()):
 | 
			
		||||
        raise Exception('Dojinshi id(%s) is not valid' % str(id))
 | 
			
		||||
    id = int(id)
 | 
			
		||||
    logger.debug('Fetching dojinshi information of id %d' % id)
 | 
			
		||||
    dojinshi = dict()
 | 
			
		||||
    dojinshi['id'] = id
 | 
			
		||||
    url = '%s/%d/' % (DETAIL_URL, id)
 | 
			
		||||
@@ -50,12 +50,29 @@ def dojinshi_parser(id):
 | 
			
		||||
 | 
			
		||||
def search_parser(keyword):
 | 
			
		||||
    logger.debug('Searching dojinshis of keyword %s' % keyword)
 | 
			
		||||
    return []
 | 
			
		||||
    result = []
 | 
			
		||||
    response = requests.get(SEARCH_URL, params={'q': keyword}).content
 | 
			
		||||
    html = BeautifulSoup(response)
 | 
			
		||||
    dojinshi_search_result = html.find_all('div', attrs={'class': 'preview-container'})
 | 
			
		||||
    for dojinshi in dojinshi_search_result:
 | 
			
		||||
        dojinshi_container = dojinshi.find('div', attrs={'class': 'caption'})
 | 
			
		||||
        title = dojinshi_container.text.strip()
 | 
			
		||||
        id_ = re.search('/g/(\d+)/', dojinshi.a['href']).group(1)
 | 
			
		||||
        result.append({'id': id_, 'title': title})
 | 
			
		||||
    return result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def tag_parser(tag):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def print_dojinshi(dojinshi_list):
 | 
			
		||||
    logger.log(15, 'Print Dojinshi list')
 | 
			
		||||
    print '-' * 60
 | 
			
		||||
    for dojinshi in dojinshi_list:
 | 
			
		||||
        print dojinshi['id'], '-', dojinshi['title']
 | 
			
		||||
    print '-' * 60
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    print dojinshi_parser(32271)
 | 
			
		||||
		Reference in New Issue
	
	Block a user