This commit is contained in:
RicterZ 2021-01-10 11:40:46 +08:00
parent 472528e464
commit 84749c56bd
3 changed files with 18 additions and 16 deletions

View File

@ -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: あなたも変態。 いいね?

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
@ -113,5 +112,10 @@ def main():
signal.signal(signal.SIGINT, signal_handler)
if __name__ == '__main__':
if sys.version_info < (3, 0, 0):
logger.error('nhentai now only support Python 3.x')
exit(1)
main()

View File

@ -4,7 +4,6 @@ from __future__ import unicode_literals, print_function
import sys
import re
import os
import string
import zipfile
import shutil
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))
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):
"""
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
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:
filename = filename[:100] + '...]'
filename = filename[:100] + u''
# Remove [] from filename
filename = filename.replace('[]', '').strip()