Compare commits

...

36 Commits

Author SHA1 Message Date
9513141ccf 0.4.12 2021-01-17 11:51:22 +08:00
bdc9fa113e fix #197 set proxy to null 2021-01-17 11:50:22 +08:00
36946111db fix #198 add notice 2021-01-17 11:42:06 +08:00
8b8b5f193e 0.4.11 2021-01-11 11:15:21 +08:00
fc99d91ac1 fix #193 2021-01-11 11:14:35 +08:00
ba141efba7 remove repeated spaces 2021-01-11 11:04:29 +08:00
f78d8750f3 remove __future__ 2021-01-11 11:03:45 +08:00
af379c825c Merge branch 'master' into dev 2021-01-10 14:40:09 +08:00
2f9386f22c fix #188 2021-01-10 11:44:04 +08:00
3667bc34b7 0.4.10 2021-01-10 11:41:38 +08:00
84749c56bd fix #191 2021-01-10 11:40:46 +08:00
24f79e0945 Merge pull request #190 from RicterZ/dev
fix bugs
2021-01-07 20:42:26 +08:00
edc46a9531 Merge pull request #189 from mobrine1/mobrine1-patch-1
Fixing loop when id not found, issue #188
2021-01-07 20:39:44 +08:00
72035a14e6 Fixing loop when id not found, issue #188 2021-01-07 07:32:29 -05:00
472528e464 Merge pull request #187 from atsushi-hirako/patch-1
fix issue #186
2021-01-02 02:16:50 +08:00
3f5915fd2a fix issue #186
change to blacklist approach (allow 2-bytes character)
2021-01-01 20:11:09 +09:00
0cd2576dab 0.4.9 2020-12-02 07:45:31 +08:00
445a8c052e Merge pull request #180 from RicterZ/dev
0.4.8
2020-12-01 21:01:00 +08:00
7a75afef0a 0.4.8 2020-12-01 20:58:28 +08:00
a5813e19b1 fix bug on first start 2020-12-01 20:56:27 +08:00
8462d2f2aa use dict.update to update config values 2020-11-26 17:52:10 +08:00
51074ee948 support multi viewers 2020-11-26 17:22:23 +08:00
9c7354be32 0.4.6 2020-11-07 12:04:42 +08:00
7f48b3edd1 Merge pull request #175 from RicterZ/dev
add default value of output dir
2020-10-15 02:10:06 +08:00
d84b827241 add default value of output dir 2020-10-15 02:09:09 +08:00
4ac161a38c Merge pull request #174 from Nontre12/fix-gen-main
Fix change directory output_dir option on gen-main
2020-10-15 01:47:51 +08:00
648b6f87bf Added logo.png to the installation 2020-10-14 12:09:39 +02:00
2ec1283ba8 Fix change directory output_dir option on gen-main 2020-10-14 12:02:57 +02:00
a9bd46b426 Merge pull request #173 from Nontre12/db-ignored
Fix db ignored
2020-10-14 02:44:03 +08:00
c52bc271fc Fix db ignored 2020-10-13 13:39:24 +02:00
f2d22f8e7d Merge pull request #169 from Nontre12/master
Fix running without parameters
2020-10-11 03:48:39 +08:00
ea6089ff31 Fix 2020-10-10 21:15:20 +02:00
670d14c3f3 Merge pull request #4 from RicterZ/master
Update master branch
2020-10-10 20:50:01 +02:00
b46106a5bc Merge pull request #167 from RicterZ/0.4.5
0.4.5
2020-10-11 02:00:02 +08:00
4aa34c668a Merge pull request #3 from RicterZ/master
Update master branch from origin
2020-10-10 19:11:56 +02:00
8ad60d9838 Merge pull request #1 from RicterZ/master
Merge pull request #162 from Nontre12/master
2020-10-10 18:31:47 +02:00
13 changed files with 75 additions and 59 deletions

View File

@ -1,8 +1,4 @@
include README.md
include requirements.txt
include nhentai/viewer/index.html
include nhentai/viewer/styles.css
include nhentai/viewer/scripts.js
include nhentai/viewer/main.html
include nhentai/viewer/main.css
include nhentai/viewer/main.js
include nhentai/viewer/*
include nhentai/viewer/default/*

View File

@ -1,3 +1,3 @@
__version__ = '0.4.5'
__version__ = '0.4.12'
__author__ = 'RicterZ'
__email__ = 'ricterzheng@gmail.com'

View File

@ -1,5 +1,5 @@
# coding: utf-8
from __future__ import print_function
import os
import sys
import json
@ -15,17 +15,6 @@ from nhentai import __version__
from nhentai.utils import urlparse, generate_html, generate_main_html, DB
from nhentai.logger import logger
try:
if sys.version_info < (3, 0, 0):
import codecs
import locale
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr)
except NameError:
# python3
pass
def banner():
logger.info(u'''nHentai ver %s: あなたも変態。 いいね?
@ -43,7 +32,7 @@ def load_config():
try:
with open(constant.NHENTAI_CONFIG_FILE, 'r') as f:
constant.CONFIG = json.load(f)
constant.CONFIG.update(json.load(f))
except json.JSONDecodeError:
logger.error('Failed to load config file.')
write_config()
@ -87,7 +76,7 @@ def cmd_parser():
choices=['recent', 'popular', 'popular-today', 'popular-week'])
# download options
parser.add_option('--output', '-o', type='string', dest='output_dir', action='store', default='',
parser.add_option('--output', '-o', type='string', dest='output_dir', action='store', default='./',
help='output dir')
parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
help='thread count for downloading doujinshi')
@ -126,10 +115,11 @@ def cmd_parser():
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',
help='clean download history')
parser.add_option('--template', dest='viewer_template', action='store',
help='set viewer template', default='')
try:
sys.argv = [unicode(i.decode(sys.stdin.encoding)) for i in sys.argv]
print()
except (NameError, TypeError):
pass
except UnicodeDecodeError:
@ -179,6 +169,19 @@ def cmd_parser():
logger.info('Proxy now set to \'{0}\'.'.format(args.proxy))
write_config()
exit(0)
if args.viewer_template is not None:
if not args.viewer_template:
args.viewer_template = 'default'
if not os.path.exists(os.path.join(os.path.dirname(__file__),
'viewer/{}/index.html'.format(args.viewer_template))):
logger.error('Template \'{}\' does not exists'.format(args.viewer_template))
exit(1)
else:
constant.CONFIG['template'] = args.viewer_template
write_config()
# --- end set config ---
if args.favorites:

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python2.7
# coding: utf-8
from __future__ import unicode_literals, print_function
import json
import os
import sys
import signal
import platform
import time
@ -13,19 +12,29 @@ from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, fav
from nhentai.doujinshi import Doujinshi
from nhentai.downloader import Downloader
from nhentai.logger import logger
from nhentai.constant import NHENTAI_CONFIG_FILE, BASE_URL
from nhentai.constant import BASE_URL
from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, \
paging, check_cookie, signal_handler, DB
def main():
banner()
if sys.version_info < (3, 0, 0):
logger.error('nhentai now only support Python 3.x')
exit(1)
options = cmd_parser()
logger.info('Using mirror: {0}'.format(BASE_URL))
# CONFIG['proxy'] will be changed after cmd_parser()
if constant.CONFIG['proxy']:
logger.info('Using proxy: {0}'.format(constant.CONFIG['proxy']))
if constant.CONFIG['proxy']['http']:
logger.info('Using proxy: {0}'.format(constant.CONFIG['proxy']['http']))
if not constant.CONFIG['template']:
constant.CONFIG['template'] = 'default'
logger.info('Using viewer template "{}"'.format(constant.CONFIG['template']))
# check your cookie
check_cookie()
@ -58,9 +67,9 @@ def main():
if options.is_save_download_history:
with DB() as db:
data = set(db.get_all())
data = map(int, db.get_all())
doujinshi_ids = list(set(doujinshi_ids) - data)
doujinshi_ids = list(set(doujinshi_ids) - set(data))
if doujinshi_ids:
for i, id_ in enumerate(doujinshi_ids):
@ -88,7 +97,7 @@ def main():
db.add_one(doujinshi.id)
if not options.is_nohtml and not options.is_cbz and not options.is_pdf:
generate_html(options.output_dir, doujinshi)
generate_html(options.output_dir, doujinshi, template=constant.CONFIG['template'])
elif options.is_cbz:
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
elif options.is_pdf:
@ -108,5 +117,6 @@ def main():
signal.signal(signal.SIGINT, signal_handler)
if __name__ == '__main__':
main()

View File

@ -1,5 +1,5 @@
# coding: utf-8
from __future__ import unicode_literals, print_function
import os
import tempfile
@ -29,9 +29,10 @@ NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai'
NHENTAI_HISTORY = os.path.join(NHENTAI_HOME, 'history.sqlite3')
NHENTAI_CONFIG_FILE = os.path.join(NHENTAI_HOME, 'config.json')
CONFIG = {
'proxy': {},
'proxy': {'http': '', 'https': ''},
'cookie': '',
'language': '',
'template': '',
}

View File

@ -1,7 +1,6 @@
# coding: utf-8
from __future__ import print_function, unicode_literals
from tabulate import tabulate
from future.builtins import range
from nhentai.constant import DETAIL_URL, IMAGE_URL
from nhentai.logger import logger

View File

@ -1,5 +1,4 @@
# coding: utf-
from __future__ import unicode_literals, print_function
import multiprocessing
import signal

View File

@ -1,7 +1,6 @@
#
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
#
from __future__ import print_function, unicode_literals
import logging
import re
import platform

View File

@ -1,5 +1,4 @@
# coding: utf-8
from __future__ import unicode_literals, print_function
import os
import re
@ -116,8 +115,11 @@ def doujinshi_parser(id_):
try:
response = request('get', url)
if response.status_code in (200,):
if response.status_code in (200, ):
response = response.content
elif response.status_code in (404,):
logger.error("Doujinshi with id {0} cannot be found".format(id_))
return []
else:
logger.debug('Slow down and retry ({}) ...'.format(id_))
time.sleep(1)

View File

@ -1,10 +1,8 @@
# coding: utf-8
from __future__ import unicode_literals, print_function
import sys
import re
import os
import string
import zipfile
import shutil
import requests
@ -64,7 +62,7 @@ def readfile(path):
return file.read()
def generate_html(output_dir='.', doujinshi_obj=None):
def generate_html(output_dir='.', doujinshi_obj=None, template='default'):
image_html = ''
if doujinshi_obj is not None:
@ -81,9 +79,9 @@ def generate_html(output_dir='.', doujinshi_obj=None):
image_html += '<img src="{0}" class="image-item"/>\n'\
.format(image)
html = readfile('viewer/index.html')
css = readfile('viewer/styles.css')
js = readfile('viewer/scripts.js')
html = readfile('viewer/{}/index.html'.format(template))
css = readfile('viewer/{}/styles.css'.format(template))
js = readfile('viewer/{}/scripts.js'.format(template))
if doujinshi_obj is not None:
serialize_json(doujinshi_obj, doujinshi_dir)
@ -226,22 +224,31 @@ def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
logger.log(15, 'PDF file has been written to \'{0}\''.format(doujinshi_dir))
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
"""
encoded = s.encode(encoding)[:length]
return encoded.decode(encoding, 'ignore')
def format_filename(s):
"""Take a string and return a valid filename constructed from the string.
Uses a whitelist approach: any characters not present in valid_chars are
removed. Also spaces are replaced with underscores.
Note: this method may produce invalid filenames such as ``, `.` or `..`
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
and append a file extension like '.txt', so I avoid the potential of using
an invalid filename.
"""
"""
It used to be a whitelist approach allowed only alphabet and a part of symbols.
but most doujinshi's names include Japanese 2-byte characters and these was rejected.
so it is using blacklist approach now.
if filename include forbidden characters (\'/:,;*?"<>|) ,it replace space character(' ').
"""
# maybe you can use `--format` to select a suitable filename
valid_chars = "-_.()[] %s%s" % (string.ascii_letters, string.digits)
filename = ''.join(c for c in s if c in valid_chars)
ban_chars = '\\\'/:,;*?"<>|\t'
filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars))).strip()
filename = ' '.join(filename.split())
print(repr(filename))
while filename.endswith('.'):
filename = filename[:-1]
if len(filename) > 100:
filename = filename[:100] + '...]'
filename = filename[:100] + u''
# Remove [] from filename
filename = filename.replace('[]', '').strip()