mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-07-01 16:09:28 +02:00
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
8cd4b948e7 | |||
f884384eb3 | |||
87afab46c4 | |||
c7b1d7e6a8 | |||
ad02371158 | |||
7c9d55e0ee | |||
00aad774ae | |||
373086b459 | |||
3a83f99771 | |||
00627ab36a | |||
592e163891 | |||
84523475b0 | |||
5f5461c902 | |||
05e6ceb3cd | |||
db59426503 | |||
74197f8f90 | |||
6d91a39533 | |||
e181e0b9dd | |||
6fed1f94cb | |||
9cfb23c8ec | |||
fc347cdadf | |||
1cdebaab61 | |||
ce8ae54536 | |||
7aedb905d6 | |||
08bb8ffda4 |
@ -67,6 +67,15 @@ Set your nhentai cookie against captcha:
|
|||||||
|
|
||||||
**NOTE**: The format of the cookie is `"csrftoken=TOKEN; sessionid=ID"`
|
**NOTE**: The format of the cookie is `"csrftoken=TOKEN; sessionid=ID"`
|
||||||
|
|
||||||
|
| To get csrftoken and sessionid, first login to your nhentai account in web browser, then:
|
||||||
|
| (Chrome) |ve| |ld| More tools |ld| Developer tools |ld| Application |ld| Storage |ld| Cookies |ld| https://nhentai.net
|
||||||
|
| (Firefox) |hv| |ld| Web Developer |ld| Web Developer Tools |ld| Storage |ld| Cookies |ld| https://nhentai.net
|
||||||
|
|
|
||||||
|
|
||||||
|
.. |hv| unicode:: U+2630 .. https://www.compart.com/en/unicode/U+2630
|
||||||
|
.. |ve| unicode:: U+22EE .. https://www.compart.com/en/unicode/U+22EE
|
||||||
|
.. |ld| unicode:: U+2014 .. https://www.compart.com/en/unicode/U+2014
|
||||||
|
|
||||||
Download specified doujinshi:
|
Download specified doujinshi:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
__version__ = '0.4.12'
|
__version__ = '0.4.15'
|
||||||
__author__ = 'RicterZ'
|
__author__ = 'RicterZ'
|
||||||
__email__ = 'ricterzheng@gmail.com'
|
__email__ = 'ricterzheng@gmail.com'
|
||||||
|
@ -84,7 +84,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', type='string', dest='proxy', action='store', default='',
|
parser.add_option('--proxy', type='string', dest='proxy', action='store',
|
||||||
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',
|
||||||
|
@ -65,11 +65,11 @@ def main():
|
|||||||
if options.is_download and doujinshis:
|
if options.is_download and doujinshis:
|
||||||
doujinshi_ids = [i['id'] for i in doujinshis]
|
doujinshi_ids = [i['id'] for i in doujinshis]
|
||||||
|
|
||||||
if options.is_save_download_history:
|
if options.is_save_download_history:
|
||||||
with DB() as db:
|
with DB() as db:
|
||||||
data = map(int, db.get_all())
|
data = map(int, db.get_all())
|
||||||
|
|
||||||
doujinshi_ids = list(set(doujinshi_ids) - set(data))
|
doujinshi_ids = list(set(map(int, doujinshi_ids)) - set(data))
|
||||||
|
|
||||||
if doujinshi_ids:
|
if doujinshi_ids:
|
||||||
for i, id_ in enumerate(doujinshi_ids):
|
for i, id_ in enumerate(doujinshi_ids):
|
||||||
|
@ -36,3 +36,10 @@ CONFIG = {
|
|||||||
'language': '',
|
'language': '',
|
||||||
'template': '',
|
'template': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LANGUAGEISO ={
|
||||||
|
'english' : 'en',
|
||||||
|
'chinese' : 'zh',
|
||||||
|
'japanese' : 'ja',
|
||||||
|
'translated' : 'translated'
|
||||||
|
}
|
||||||
|
@ -119,14 +119,14 @@ class Downloader(Singleton):
|
|||||||
folder = os.path.join(self.path, folder)
|
folder = os.path.join(self.path, folder)
|
||||||
|
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
logger.warn('Path \'{0}\' does not exist, creating.'.format(folder))
|
logger.warning('Path \'{0}\' does not exist, creating.'.format(folder))
|
||||||
try:
|
try:
|
||||||
os.makedirs(folder)
|
os.makedirs(folder)
|
||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
logger.critical('{0}'.format(str(e)))
|
logger.critical('{0}'.format(str(e)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.warn('Path \'{0}\' already exist.'.format(folder))
|
logger.warning('Path \'{0}\' already exist.'.format(folder))
|
||||||
|
|
||||||
queue = [(self, url, folder) for url in queue]
|
queue = [(self, url, folder) for url in queue]
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ logger.setLevel(logging.DEBUG)
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger.log(15, 'nhentai')
|
logger.log(15, 'nhentai')
|
||||||
logger.info('info')
|
logger.info('info')
|
||||||
logger.warn('warn')
|
logger.warning('warning')
|
||||||
logger.debug('debug')
|
logger.debug('debug')
|
||||||
logger.error('error')
|
logger.error('error')
|
||||||
logger.critical('critical')
|
logger.critical('critical')
|
||||||
|
@ -126,7 +126,7 @@ def doujinshi_parser(id_):
|
|||||||
return doujinshi_parser(str(id_))
|
return doujinshi_parser(str(id_))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn('Error: {}, ignored'.format(str(e)))
|
logger.warning('Error: {}, ignored'.format(str(e)))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
html = BeautifulSoup(response, 'html.parser')
|
html = BeautifulSoup(response, 'html.parser')
|
||||||
@ -180,7 +180,7 @@ def old_search_parser(keyword, sorting='date', page=1):
|
|||||||
|
|
||||||
result = _get_title_and_id(response)
|
result = _get_title_and_id(response)
|
||||||
if not result:
|
if not result:
|
||||||
logger.warn('Not found anything of keyword {}'.format(keyword))
|
logger.warning('Not found anything of keyword {}'.format(keyword))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ def search_parser(keyword, sorting, page, is_page_all=False):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if 'result' not in response:
|
if 'result' not in response:
|
||||||
logger.warn('No result in response in page {}'.format(p))
|
logger.warning('No result in response in page {}'.format(p))
|
||||||
break
|
break
|
||||||
|
|
||||||
for row in response['result']:
|
for row in response['result']:
|
||||||
@ -230,7 +230,7 @@ def search_parser(keyword, sorting, page, is_page_all=False):
|
|||||||
result.append({'id': row['id'], 'title': title})
|
result.append({'id': row['id'], 'title': title})
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
logger.warn('No results for keywords {}'.format(keyword))
|
logger.warning('No results for keywords {}'.format(keyword))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from xml.sax.saxutils import escape
|
from xml.sax.saxutils import escape
|
||||||
|
from nhentai.constant import LANGUAGEISO
|
||||||
|
|
||||||
def serialize_json(doujinshi, dir):
|
def serialize_json(doujinshi, dir):
|
||||||
metadata = {'title': doujinshi.name,
|
metadata = {'title': doujinshi.name,
|
||||||
@ -65,7 +65,8 @@ def serialize_comicxml(doujinshi, dir):
|
|||||||
if doujinshi.info.languages:
|
if doujinshi.info.languages:
|
||||||
languages = [i.strip() for i in doujinshi.info.languages.split(',')]
|
languages = [i.strip() for i in doujinshi.info.languages.split(',')]
|
||||||
xml_write_simple_tag(f, 'Translated', 'Yes' if 'translated' in languages else 'No')
|
xml_write_simple_tag(f, 'Translated', 'Yes' if 'translated' in languages else 'No')
|
||||||
[xml_write_simple_tag(f, 'Language', i) for i in languages if i != 'translated']
|
[xml_write_simple_tag(f, 'LanguageISO', LANGUAGEISO[i]) for i in languages \
|
||||||
|
if (i != 'translated' and i in LANGUAGEISO)]
|
||||||
|
|
||||||
f.write('</ComicInfo>')
|
f.write('</ComicInfo>')
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ def generate_main_html(output_dir='./'):
|
|||||||
logger.warning('Writing Main Viewer failed ({})'.format(str(e)))
|
logger.warning('Writing Main Viewer failed ({})'.format(str(e)))
|
||||||
|
|
||||||
|
|
||||||
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=False):
|
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=True):
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
if write_comic_info:
|
if write_comic_info:
|
||||||
@ -194,36 +194,36 @@ def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_
|
|||||||
def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
||||||
try:
|
try:
|
||||||
import img2pdf
|
import img2pdf
|
||||||
|
|
||||||
|
"""Write images to a PDF file using img2pdf."""
|
||||||
|
if doujinshi_obj is not None:
|
||||||
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
|
pdf_filename = os.path.join(
|
||||||
|
os.path.join(doujinshi_dir, '..'),
|
||||||
|
'{}.pdf'.format(doujinshi_obj.filename)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
pdf_filename = './doujinshi.pdf'
|
||||||
|
doujinshi_dir = '.'
|
||||||
|
|
||||||
|
file_list = os.listdir(doujinshi_dir)
|
||||||
|
file_list.sort()
|
||||||
|
|
||||||
|
logger.info('Writing PDF file to path: {}'.format(pdf_filename))
|
||||||
|
with open(pdf_filename, 'wb') as pdf_f:
|
||||||
|
full_path_list = (
|
||||||
|
[os.path.join(doujinshi_dir, image) for image in file_list]
|
||||||
|
)
|
||||||
|
pdf_f.write(img2pdf.convert(full_path_list))
|
||||||
|
|
||||||
|
if rm_origin_dir:
|
||||||
|
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
logger.log(15, 'PDF file has been written to \'{0}\''.format(doujinshi_dir))
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.error("Please install img2pdf package by using pip.")
|
logger.error("Please install img2pdf package by using pip.")
|
||||||
|
|
||||||
"""Write images to a PDF file using img2pdf."""
|
|
||||||
if doujinshi_obj is not None:
|
|
||||||
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
|
||||||
pdf_filename = os.path.join(
|
|
||||||
os.path.join(doujinshi_dir, '..'),
|
|
||||||
'{}.pdf'.format(doujinshi_obj.filename)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
pdf_filename = './doujinshi.pdf'
|
|
||||||
doujinshi_dir = '.'
|
|
||||||
|
|
||||||
file_list = os.listdir(doujinshi_dir)
|
|
||||||
file_list.sort()
|
|
||||||
|
|
||||||
logger.info('Writing PDF file to path: {}'.format(pdf_filename))
|
|
||||||
with open(pdf_filename, 'wb') as pdf_f:
|
|
||||||
full_path_list = (
|
|
||||||
[os.path.join(doujinshi_dir, image) for image in file_list]
|
|
||||||
)
|
|
||||||
pdf_f.write(img2pdf.convert(full_path_list))
|
|
||||||
|
|
||||||
if rm_origin_dir:
|
|
||||||
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
|
||||||
|
|
||||||
logger.log(15, 'PDF file has been written to \'{0}\''.format(doujinshi_dir))
|
|
||||||
|
|
||||||
|
|
||||||
def unicode_truncate(s, length, encoding='utf-8'):
|
def unicode_truncate(s, length, encoding='utf-8'):
|
||||||
"""https://stackoverflow.com/questions/1809531/truncating-unicode-so-it-fits-a-maximum-size-when-encoded-for-wire-transfer
|
"""https://stackoverflow.com/questions/1809531/truncating-unicode-so-it-fits-a-maximum-size-when-encoded-for-wire-transfer
|
||||||
"""
|
"""
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
requests>=2.5.0
|
requests>=2.5.0
|
||||||
soupsieve<2.0
|
soupsieve
|
||||||
BeautifulSoup4>=4.0.0
|
BeautifulSoup4>=4.0.0
|
||||||
threadpool>=1.2.7
|
|
||||||
tabulate>=0.7.5
|
tabulate>=0.7.5
|
||||||
future>=0.15.2
|
future>=0.15.2
|
||||||
iso8601 >= 0.1
|
iso8601 >= 0.1
|
||||||
|
Reference in New Issue
Block a user