mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-19 10:21:19 +02:00
search for download
This commit is contained in:
parent
e91457889e
commit
0583c7910c
@ -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)
|
11
nhentai.py
11
nhentai.py
@ -1,6 +1,6 @@
|
||||
#coding: utf-8
|
||||
from hentai.cmdline import cmd_parser, banner
|
||||
from hentai.parser import dojinshi_parser, search_parser
|
||||
from hentai.parser import dojinshi_parser, search_parser, print_dojinshi
|
||||
from hentai.dojinshi import Dojinshi
|
||||
from hentai.downloader import Downloader
|
||||
from hentai.logger import logger
|
||||
@ -15,10 +15,15 @@ def main():
|
||||
|
||||
logger.log(15, 'nHentai: あなたも変態。 いいね?')
|
||||
|
||||
dojinshi_ids = []
|
||||
dojinshi_list = []
|
||||
|
||||
if options.keyword:
|
||||
dojinshi_ids = search_parser(options.keyword)
|
||||
dojinshis = search_parser(options.keyword)
|
||||
if options.is_download:
|
||||
dojinshi_ids = map(lambda d: d['id'], dojinshis)
|
||||
else:
|
||||
print_dojinshi(dojinshis)
|
||||
else:
|
||||
dojinshi_ids = options.ids
|
||||
|
||||
@ -38,6 +43,8 @@ def main():
|
||||
else:
|
||||
map(lambda dojinshi: dojinshi.show(), dojinshi_list)
|
||||
|
||||
logger.log(15, u'🍺 All done.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user