mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 02:50:55 +01:00 
			
		
		
		
	@@ -1,3 +1,3 @@
 | 
				
			|||||||
__version__ = '0.4.9'
 | 
					__version__ = '0.4.10'
 | 
				
			||||||
__author__ = 'RicterZ'
 | 
					__author__ = 'RicterZ'
 | 
				
			||||||
__email__ = 'ricterzheng@gmail.com'
 | 
					__email__ = 'ricterzheng@gmail.com'
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,17 +15,6 @@ from nhentai import __version__
 | 
				
			|||||||
from nhentai.utils import urlparse, generate_html, generate_main_html, DB
 | 
					from nhentai.utils import urlparse, generate_html, generate_main_html, DB
 | 
				
			||||||
from nhentai.logger import logger
 | 
					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():
 | 
					def banner():
 | 
				
			||||||
    logger.info(u'''nHentai ver %s: あなたも変態。 いいね?
 | 
					    logger.info(u'''nHentai ver %s: あなたも変態。 いいね?
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,7 @@
 | 
				
			|||||||
#!/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 sys
 | 
				
			||||||
import os
 | 
					 | 
				
			||||||
import signal
 | 
					import signal
 | 
				
			||||||
import platform
 | 
					import platform
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
@@ -113,5 +112,10 @@ def main():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
signal.signal(signal.SIGINT, signal_handler)
 | 
					signal.signal(signal.SIGINT, signal_handler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					    if sys.version_info < (3, 0, 0):
 | 
				
			||||||
 | 
					        logger.error('nhentai now only support Python 3.x')
 | 
				
			||||||
 | 
					        exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    main()
 | 
					    main()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -116,7 +116,7 @@ def doujinshi_parser(id_):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        response = request('get', url)
 | 
					        response = request('get', url)
 | 
				
			||||||
        if response.status_code in (200,):
 | 
					        if response.status_code in (200, ):
 | 
				
			||||||
            response = response.content
 | 
					            response = response.content
 | 
				
			||||||
        elif response.status_code in (404,):
 | 
					        elif response.status_code in (404,):
 | 
				
			||||||
            logger.error("Doujinshi with id {0} cannot be found".format(id_))
 | 
					            logger.error("Doujinshi with id {0} cannot be found".format(id_))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,6 @@ from __future__ import unicode_literals, print_function
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import string
 | 
					 | 
				
			||||||
import zipfile
 | 
					import zipfile
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
@@ -226,6 +225,13 @@ 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))
 | 
					    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):
 | 
					def format_filename(s):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    It used to be a whitelist approach allowed only alphabet and a part of symbols.
 | 
					    It used to be a whitelist approach allowed only alphabet and a part of symbols.
 | 
				
			||||||
@@ -235,9 +241,12 @@ def format_filename(s):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    # maybe you can use `--format` to select a suitable filename
 | 
					    # maybe you can use `--format` to select a suitable filename
 | 
				
			||||||
    ban_chars = '\\\'/:,;*?"<>|'
 | 
					    ban_chars = '\\\'/:,;*?"<>|'
 | 
				
			||||||
    filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars)))
 | 
					    filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars))).strip()
 | 
				
			||||||
 | 
					    while filename.endswith('.'):
 | 
				
			||||||
 | 
					        filename = filename[:-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if len(filename) > 100:
 | 
					    if len(filename) > 100:
 | 
				
			||||||
        filename = filename[:100] + '...]'
 | 
					        filename = filename[:100] + u'…'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Remove [] from filename
 | 
					    # Remove [] from filename
 | 
				
			||||||
    filename = filename.replace('[]', '').strip()
 | 
					    filename = filename.replace('[]', '').strip()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user