mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-07-01 16:09:28 +02:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
f04359e486 | |||
6861cbcbc1 | |||
e0938c5a0e | |||
641f8e4c51 | |||
b2fae226f9 | |||
f157ac3246 | |||
139e01d3ca | |||
4d870e36a1 | |||
74b0df26a9 | |||
1746e731ec | |||
be05b9c0eb | |||
9054b98934 | |||
b82201ff27 | |||
532c74e075 | |||
5a50a5b1ba | |||
b5fe48746e | |||
94d8da655a | |||
6ff2816d95 | |||
0a94ef9cf1 |
@ -1,3 +1,3 @@
|
|||||||
__version__ = '0.4.2'
|
__version__ = '0.4.5'
|
||||||
__author__ = 'RicterZ'
|
__author__ = 'RicterZ'
|
||||||
__email__ = 'ricterzheng@gmail.com'
|
__email__ = 'ricterzheng@gmail.com'
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from itertools import ifilter as filter
|
from itertools import ifilter as filter
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -35,7 +37,29 @@ def banner():
|
|||||||
''' % __version__)
|
''' % __version__)
|
||||||
|
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
if not os.path.exists(constant.NHENTAI_CONFIG_FILE):
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(constant.NHENTAI_CONFIG_FILE, 'r') as f:
|
||||||
|
constant.CONFIG = json.load(f)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
logger.error('Failed to load config file.')
|
||||||
|
write_config()
|
||||||
|
|
||||||
|
|
||||||
|
def write_config():
|
||||||
|
if not os.path.exists(constant.NHENTAI_HOME):
|
||||||
|
os.mkdir(constant.NHENTAI_HOME)
|
||||||
|
|
||||||
|
with open(constant.NHENTAI_CONFIG_FILE, 'w') as f:
|
||||||
|
f.write(json.dumps(constant.CONFIG))
|
||||||
|
|
||||||
|
|
||||||
def cmd_parser():
|
def cmd_parser():
|
||||||
|
load_config()
|
||||||
|
|
||||||
parser = OptionParser('\n nhentai --search [keyword] --download'
|
parser = OptionParser('\n nhentai --search [keyword] --download'
|
||||||
'\n NHENTAI=http://h.loli.club nhentai --id [ID ...]'
|
'\n NHENTAI=http://h.loli.club nhentai --id [ID ...]'
|
||||||
'\n nhentai --file [filename]'
|
'\n nhentai --file [filename]'
|
||||||
@ -54,10 +78,10 @@ def cmd_parser():
|
|||||||
help='list or download your favorites.')
|
help='list or download your favorites.')
|
||||||
|
|
||||||
# page options
|
# page options
|
||||||
parser.add_option('--page', type='int', dest='page', action='store', default=1,
|
parser.add_option('--page-all', dest='page_all', action='store_true', default=False,
|
||||||
help='page number of search results')
|
help='all search results')
|
||||||
parser.add_option('--page-range', type='string', dest='page_range', action='store',
|
parser.add_option('--page', '--page-range', type='string', dest='page', action='store', default='',
|
||||||
help='page range of favorites. e.g. 1,2-5,14')
|
help='page number of search results. e.g. 1,2-5,14')
|
||||||
parser.add_option('--sorting', dest='sorting', action='store', default='recent',
|
parser.add_option('--sorting', dest='sorting', action='store', default='recent',
|
||||||
help='sorting of doujinshi (recent / popular / popular-[today|week])',
|
help='sorting of doujinshi (recent / popular / popular-[today|week])',
|
||||||
choices=['recent', 'popular', 'popular-today', 'popular-week'])
|
choices=['recent', 'popular', 'popular-today', 'popular-week'])
|
||||||
@ -71,7 +95,7 @@ def cmd_parser():
|
|||||||
help='timeout for downloading doujinshi')
|
help='timeout for downloading doujinshi')
|
||||||
parser.add_option('--delay', '-d', type='int', dest='delay', action='store', default=0,
|
parser.add_option('--delay', '-d', type='int', dest='delay', action='store', default=0,
|
||||||
help='slow down between downloading every doujinshi')
|
help='slow down between downloading every doujinshi')
|
||||||
parser.add_option('--proxy', '-p', type='string', dest='proxy', action='store', default='',
|
parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
|
||||||
help='store a proxy, for example: -p \'http://127.0.0.1:1080\'')
|
help='store a proxy, for example: -p \'http://127.0.0.1:1080\'')
|
||||||
parser.add_option('--file', '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
|
parser.add_option('--file', '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
|
||||||
parser.add_option('--format', type='string', dest='name_format', action='store',
|
parser.add_option('--format', type='string', dest='name_format', action='store',
|
||||||
@ -96,6 +120,8 @@ def cmd_parser():
|
|||||||
help='set cookie of nhentai to bypass Google recaptcha')
|
help='set cookie of nhentai to bypass Google recaptcha')
|
||||||
parser.add_option('--language', type='str', dest='language', action='store',
|
parser.add_option('--language', type='str', dest='language', action='store',
|
||||||
help='set default language to parse doujinshis')
|
help='set default language to parse doujinshis')
|
||||||
|
parser.add_option('--clean-language', dest='clean_language', action='store_true', default=False,
|
||||||
|
help='set DEFAULT as language to parse doujinshis')
|
||||||
parser.add_option('--save-download-history', dest='is_save_download_history', action='store_true',
|
parser.add_option('--save-download-history', dest='is_save_download_history', action='store_true',
|
||||||
default=False, help='save downloaded doujinshis, whose will be skipped if you re-download them')
|
default=False, help='save downloaded doujinshis, whose will be skipped if you re-download them')
|
||||||
parser.add_option('--clean-download-history', action='store_true', default=False, dest='clean_download_history',
|
parser.add_option('--clean-download-history', action='store_true', default=False, dest='clean_download_history',
|
||||||
@ -126,69 +152,37 @@ def cmd_parser():
|
|||||||
logger.info('Download history cleaned.')
|
logger.info('Download history cleaned.')
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if os.path.exists(constant.NHENTAI_COOKIE):
|
# --- set config ---
|
||||||
with open(constant.NHENTAI_COOKIE, 'r') as f:
|
if args.cookie is not None:
|
||||||
constant.COOKIE = f.read()
|
constant.CONFIG['cookie'] = args.cookie
|
||||||
|
|
||||||
if args.cookie:
|
|
||||||
try:
|
|
||||||
if not os.path.exists(constant.NHENTAI_HOME):
|
|
||||||
os.mkdir(constant.NHENTAI_HOME)
|
|
||||||
|
|
||||||
with open(constant.NHENTAI_COOKIE, 'w') as f:
|
|
||||||
f.write(args.cookie)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
logger.info('Cookie saved.')
|
logger.info('Cookie saved.')
|
||||||
|
write_config()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if os.path.exists(constant.NHENTAI_LANGUAGE) and not args.language:
|
if args.language is not None:
|
||||||
with open(constant.NHENTAI_LANGUAGE, 'r') as f:
|
constant.CONFIG['language'] = args.language
|
||||||
constant.LANGUAGE = f.read()
|
logger.info('Default language now set to \'{0}\''.format(args.language))
|
||||||
args.language = f.read()
|
write_config()
|
||||||
|
|
||||||
if args.language:
|
|
||||||
try:
|
|
||||||
if not os.path.exists(constant.NHENTAI_HOME):
|
|
||||||
os.mkdir(constant.NHENTAI_HOME)
|
|
||||||
|
|
||||||
with open(constant.NHENTAI_LANGUAGE, 'w') as f:
|
|
||||||
f.write(args.language)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
logger.info('Default language now is {}.'.format(args.language))
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
# TODO: search without language
|
||||||
|
|
||||||
if os.path.exists(constant.NHENTAI_PROXY):
|
if args.proxy is not None:
|
||||||
with open(constant.NHENTAI_PROXY, 'r') as f:
|
proxy_url = urlparse(args.proxy)
|
||||||
link = f.read()
|
if not args.proxy == '' and proxy_url.scheme not in ('http', 'https'):
|
||||||
constant.PROXY = {'http': link, 'https': link}
|
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
|
||||||
|
exit(0)
|
||||||
if args.proxy:
|
else:
|
||||||
try:
|
constant.CONFIG['proxy'] = {
|
||||||
if not os.path.exists(constant.NHENTAI_HOME):
|
'http': args.proxy,
|
||||||
os.mkdir(constant.NHENTAI_HOME)
|
'https': args.proxy,
|
||||||
|
}
|
||||||
proxy_url = urlparse(args.proxy)
|
logger.info('Proxy now set to \'{0}\'.'.format(args.proxy))
|
||||||
if proxy_url.scheme not in ('http', 'https'):
|
write_config()
|
||||||
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
|
exit(0)
|
||||||
else:
|
# --- end set config ---
|
||||||
with open(constant.NHENTAI_PROXY, 'w') as f:
|
|
||||||
f.write(args.proxy)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
logger.info('Proxy \'{0}\' saved.'.format(args.proxy))
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
if args.favorites:
|
if args.favorites:
|
||||||
if not constant.COOKIE:
|
if not constant.CONFIG['cookie']:
|
||||||
logger.warning('Cookie has not been set, please use `nhentai --cookie \'COOKIE\'` to set it.')
|
logger.warning('Cookie has not been set, please use `nhentai --cookie \'COOKIE\'` to set it.')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python2.7
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
|
import json
|
||||||
|
import os
|
||||||
import signal
|
import signal
|
||||||
import platform
|
import platform
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from nhentai import constant
|
||||||
from nhentai.cmdline import cmd_parser, banner
|
from nhentai.cmdline import cmd_parser, banner
|
||||||
from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser
|
from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser
|
||||||
from nhentai.doujinshi import Doujinshi
|
from nhentai.doujinshi import Doujinshi
|
||||||
from nhentai.downloader import Downloader
|
from nhentai.downloader import Downloader
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
from nhentai.constant import BASE_URL
|
from nhentai.constant import NHENTAI_CONFIG_FILE, BASE_URL
|
||||||
from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, check_cookie, signal_handler, DB
|
from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, \
|
||||||
|
paging, check_cookie, signal_handler, DB
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -19,10 +23,9 @@ def main():
|
|||||||
options = cmd_parser()
|
options = cmd_parser()
|
||||||
logger.info('Using mirror: {0}'.format(BASE_URL))
|
logger.info('Using mirror: {0}'.format(BASE_URL))
|
||||||
|
|
||||||
from nhentai.constant import PROXY
|
# CONFIG['proxy'] will be changed after cmd_parser()
|
||||||
# constant.PROXY will be changed after cmd_parser()
|
if constant.CONFIG['proxy']:
|
||||||
if PROXY:
|
logger.info('Using proxy: {0}'.format(constant.CONFIG['proxy']))
|
||||||
logger.info('Using proxy: {0}'.format(PROXY))
|
|
||||||
|
|
||||||
# check your cookie
|
# check your cookie
|
||||||
check_cookie()
|
check_cookie()
|
||||||
@ -31,18 +34,20 @@ def main():
|
|||||||
doujinshi_ids = []
|
doujinshi_ids = []
|
||||||
doujinshi_list = []
|
doujinshi_list = []
|
||||||
|
|
||||||
|
page_list = paging(options.page)
|
||||||
|
|
||||||
if options.favorites:
|
if options.favorites:
|
||||||
if not options.is_download:
|
if not options.is_download:
|
||||||
logger.warning('You do not specify --download option')
|
logger.warning('You do not specify --download option')
|
||||||
|
|
||||||
doujinshis = favorites_parser(options.page_range)
|
doujinshis = favorites_parser(page=page_list)
|
||||||
|
|
||||||
elif options.keyword:
|
elif options.keyword:
|
||||||
from nhentai.constant import LANGUAGE
|
if constant.CONFIG['language']:
|
||||||
if LANGUAGE:
|
logger.info('Using default language: {0}'.format(constant.CONFIG['language']))
|
||||||
logger.info('Using deafult language: {0}'.format(LANGUAGE))
|
options.keyword += ' language:{}'.format(constant.CONFIG['language'])
|
||||||
options.keyword += ', language:{}'.format(LANGUAGE)
|
doujinshis = search_parser(options.keyword, sorting=options.sorting, page=page_list,
|
||||||
doujinshis = search_parser(options.keyword, sorting=options.sorting, page=options.page)
|
is_page_all=options.page_all)
|
||||||
|
|
||||||
elif not doujinshi_ids:
|
elif not doujinshi_ids:
|
||||||
doujinshi_ids = options.id
|
doujinshi_ids = options.id
|
||||||
|
@ -26,12 +26,12 @@ u = urlparse(BASE_URL)
|
|||||||
IMAGE_URL = '%s://i.%s/galleries' % (u.scheme, u.hostname)
|
IMAGE_URL = '%s://i.%s/galleries' % (u.scheme, u.hostname)
|
||||||
|
|
||||||
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
|
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
|
||||||
NHENTAI_PROXY = os.path.join(NHENTAI_HOME, 'proxy')
|
|
||||||
NHENTAI_COOKIE = os.path.join(NHENTAI_HOME, 'cookie')
|
|
||||||
NHENTAI_LANGUAGE = os.path.join(NHENTAI_HOME, 'language')
|
|
||||||
NHENTAI_HISTORY = os.path.join(NHENTAI_HOME, 'history.sqlite3')
|
NHENTAI_HISTORY = os.path.join(NHENTAI_HOME, 'history.sqlite3')
|
||||||
|
NHENTAI_CONFIG_FILE = os.path.join(NHENTAI_HOME, 'config.json')
|
||||||
|
|
||||||
PROXY = {}
|
CONFIG = {
|
||||||
|
'proxy': {},
|
||||||
|
'cookie': '',
|
||||||
|
'language': '',
|
||||||
|
}
|
||||||
|
|
||||||
COOKIE = ''
|
|
||||||
LANGUAGE = ''
|
|
||||||
|
@ -48,6 +48,7 @@ class Doujinshi(object):
|
|||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
table = [
|
table = [
|
||||||
|
["Parodies", self.info.parodies],
|
||||||
["Doujinshi", self.name],
|
["Doujinshi", self.name],
|
||||||
["Subtitle", self.info.subtitle],
|
["Subtitle", self.info.subtitle],
|
||||||
["Characters", self.info.characters],
|
["Characters", self.info.characters],
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
@ -64,7 +63,7 @@ def _get_title_and_id(response):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def favorites_parser(page_range=''):
|
def favorites_parser(page=None):
|
||||||
result = []
|
result = []
|
||||||
html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser')
|
html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser')
|
||||||
count = html.find('span', attrs={'class': 'count'})
|
count = html.find('span', attrs={'class': 'count'})
|
||||||
@ -78,20 +77,20 @@ def favorites_parser(page_range=''):
|
|||||||
return []
|
return []
|
||||||
pages = int(count / 25)
|
pages = int(count / 25)
|
||||||
|
|
||||||
if pages:
|
if page:
|
||||||
pages += 1 if count % (25 * pages) else 0
|
page_range_list = page
|
||||||
else:
|
else:
|
||||||
pages = 1
|
if pages:
|
||||||
|
pages += 1 if count % (25 * pages) else 0
|
||||||
|
else:
|
||||||
|
pages = 1
|
||||||
|
|
||||||
logger.info('You have %d favorites in %d pages.' % (count, pages))
|
logger.info('You have %d favorites in %d pages.' % (count, pages))
|
||||||
|
|
||||||
if os.getenv('DEBUG'):
|
if os.getenv('DEBUG'):
|
||||||
pages = 1
|
pages = 1
|
||||||
|
|
||||||
page_range_list = range(1, pages + 1)
|
page_range_list = range(1, pages + 1)
|
||||||
if page_range:
|
|
||||||
logger.info('page range is {0}'.format(page_range))
|
|
||||||
page_range_list = page_range_parser(page_range, pages)
|
|
||||||
|
|
||||||
for page in page_range_list:
|
for page in page_range_list:
|
||||||
try:
|
try:
|
||||||
@ -105,32 +104,6 @@ def favorites_parser(page_range=''):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def page_range_parser(page_range, max_page_num):
|
|
||||||
pages = set()
|
|
||||||
ranges = str.split(page_range, ',')
|
|
||||||
for range_str in ranges:
|
|
||||||
idx = range_str.find('-')
|
|
||||||
if idx == -1:
|
|
||||||
try:
|
|
||||||
page = int(range_str)
|
|
||||||
if page <= max_page_num:
|
|
||||||
pages.add(page)
|
|
||||||
except ValueError:
|
|
||||||
logger.error('page range({0}) is not valid'.format(page_range))
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
left = int(range_str[:idx])
|
|
||||||
right = int(range_str[idx + 1:])
|
|
||||||
if right > max_page_num:
|
|
||||||
right = max_page_num
|
|
||||||
for page in range(left, right + 1):
|
|
||||||
pages.add(page)
|
|
||||||
except ValueError:
|
|
||||||
logger.error('page range({0}) is not valid'.format(page_range))
|
|
||||||
|
|
||||||
return list(pages)
|
|
||||||
|
|
||||||
|
|
||||||
def doujinshi_parser(id_):
|
def doujinshi_parser(id_):
|
||||||
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):
|
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):
|
||||||
raise Exception('Doujinshi id({0}) is not valid'.format(id_))
|
raise Exception('Doujinshi id({0}) is not valid'.format(id_))
|
||||||
@ -215,34 +188,47 @@ def print_doujinshi(doujinshi_list):
|
|||||||
return
|
return
|
||||||
doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list]
|
doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list]
|
||||||
headers = ['id', 'doujinshi']
|
headers = ['id', 'doujinshi']
|
||||||
logger.info('Search Result\n' +
|
logger.info('Search Result || Found %i doujinshis \n' % doujinshi_list.__len__() +
|
||||||
tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
||||||
|
|
||||||
|
|
||||||
def search_parser(keyword, sorting, page):
|
def search_parser(keyword, sorting, page, is_page_all=False):
|
||||||
logger.debug('Searching doujinshis using keywords {0}'.format(keyword))
|
|
||||||
# keyword = '+'.join([i.strip().replace(' ', '-').lower() for i in keyword.split(',')])
|
# keyword = '+'.join([i.strip().replace(' ', '-').lower() for i in keyword.split(',')])
|
||||||
result = []
|
result = []
|
||||||
i = 0
|
if not page:
|
||||||
while i < 5:
|
page = [1]
|
||||||
try:
|
|
||||||
url = request('get', url=constant.SEARCH_URL, params={'query': keyword, 'page': page, 'sort': sorting}).url
|
|
||||||
response = request('get', url.replace('%2B', '+')).json()
|
|
||||||
except Exception as e:
|
|
||||||
logger.critical(str(e))
|
|
||||||
|
|
||||||
break
|
if is_page_all:
|
||||||
|
url = request('get', url=constant.SEARCH_URL, params={'query': keyword}).url
|
||||||
|
init_response = request('get', url.replace('%2B', '+')).json()
|
||||||
|
page = range(1, init_response['num_pages']+1)
|
||||||
|
|
||||||
if 'result' not in response:
|
total = '/{0}'.format(page[-1]) if is_page_all else ''
|
||||||
raise Exception('No result in response')
|
for p in page:
|
||||||
|
i = 0
|
||||||
|
|
||||||
for row in response['result']:
|
logger.info('Searching doujinshis using keywords "{0}" on page {1}{2}'.format(keyword, p, total))
|
||||||
title = row['title']['english']
|
while i < 3:
|
||||||
title = title[:85] + '..' if len(title) > 85 else title
|
try:
|
||||||
result.append({'id': row['id'], 'title': title})
|
url = request('get', url=constant.SEARCH_URL, params={'query': keyword,
|
||||||
|
'page': p, 'sort': sorting}).url
|
||||||
|
response = request('get', url.replace('%2B', '+')).json()
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(str(e))
|
||||||
|
|
||||||
if not result:
|
break
|
||||||
logger.warn('No results for keywords {}'.format(keyword))
|
|
||||||
|
if 'result' not in response:
|
||||||
|
logger.warn('No result in response in page {}'.format(p))
|
||||||
|
break
|
||||||
|
|
||||||
|
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:
|
||||||
|
logger.warn('No results for keywords {}'.format(keyword))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ def request(method, url, **kwargs):
|
|||||||
session.headers.update({
|
session.headers.update({
|
||||||
'Referer': constant.LOGIN_URL,
|
'Referer': constant.LOGIN_URL,
|
||||||
'User-Agent': 'nhentai command line client (https://github.com/RicterZ/nhentai)',
|
'User-Agent': 'nhentai command line client (https://github.com/RicterZ/nhentai)',
|
||||||
'Cookie': constant.COOKIE
|
'Cookie': constant.CONFIG['cookie']
|
||||||
})
|
})
|
||||||
return getattr(session, method)(url, proxies=constant.PROXY, verify=False, **kwargs)
|
return getattr(session, method)(url, proxies=constant.CONFIG['proxy'], verify=False, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def check_cookie():
|
def check_cookie():
|
||||||
@ -253,6 +253,26 @@ def signal_handler(signal, frame):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def paging(page_string):
|
||||||
|
# 1,3-5,14 -> [1, 3, 4, 5, 14]
|
||||||
|
if not page_string:
|
||||||
|
return []
|
||||||
|
|
||||||
|
page_list = []
|
||||||
|
for i in page_string.split(','):
|
||||||
|
if '-' in i:
|
||||||
|
start, end = i.split('-')
|
||||||
|
if not (start.isdigit() and end.isdigit()):
|
||||||
|
raise Exception('Invalid page number')
|
||||||
|
page_list.extend(list(range(int(start), int(end)+1)))
|
||||||
|
else:
|
||||||
|
if not i.isdigit():
|
||||||
|
raise Exception('Invalid page number')
|
||||||
|
page_list.append(int(i))
|
||||||
|
|
||||||
|
return page_list
|
||||||
|
|
||||||
|
|
||||||
class DB(object):
|
class DB(object):
|
||||||
conn = None
|
conn = None
|
||||||
cur = None
|
cur = None
|
||||||
|
Reference in New Issue
Block a user