mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-07-01 16:09:28 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0f6e3f857 | |||
413657e076 | |||
4ecffaff55 | |||
457f12d40d | |||
0b80458c6f | |||
499081a9cd | |||
53aa04af1e |
@ -11,8 +11,6 @@ nhentai
|
||||
|
||||
nhentai is a CLI tool for downloading doujinshi from `nhentai.net <https://nhentai.net>`_
|
||||
|
||||
GUI version: `https://github.com/edgar1016/nhentai-GUI <https://github.com/edgar1016/nhentai-GUI>`_
|
||||
|
||||
===================
|
||||
Manual Installation
|
||||
===================
|
||||
@ -143,9 +141,7 @@ Supported doujinshi folder formatter:
|
||||
- %t: Doujinshi name
|
||||
- %s: Doujinshi subtitle (translated name)
|
||||
- %a: Doujinshi authors' name
|
||||
- %g: Doujinshi groups name
|
||||
- %p: Doujinshi pretty name
|
||||
- %ag: Doujinshi authors name or groups name
|
||||
|
||||
|
||||
Other options:
|
||||
@ -202,8 +198,6 @@ Other options:
|
||||
-P, --pdf generate PDF file
|
||||
--rm-origin-dir remove downloaded doujinshi dir when generated CBZ or
|
||||
PDF file
|
||||
--move-to-folder remove files in doujinshi dir then move new file to folder
|
||||
when generated CBZ or PDF file
|
||||
--meta generate a metadata file in doujinshi format
|
||||
--regenerate-cbz regenerate the cbz file if exists
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
__version__ = '0.5.4'
|
||||
__version__ = '0.5.3'
|
||||
__author__ = 'RicterZ'
|
||||
__email__ = 'ricterzheng@gmail.com'
|
||||
|
@ -73,15 +73,17 @@ def cmd_parser():
|
||||
help='search doujinshi by keyword')
|
||||
parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
|
||||
help='list or download your favorites')
|
||||
parser.add_option('--artist', '-a', action='store', dest='artist',
|
||||
help='list doujinshi by artist name')
|
||||
|
||||
# page options
|
||||
parser.add_option('--page-all', dest='page_all', action='store_true', default=False,
|
||||
help='all search results')
|
||||
parser.add_option('--page', '--page-range', type='string', dest='page', action='store', default='1',
|
||||
help='page number of search results. e.g. 1,2-5,14')
|
||||
parser.add_option('--sorting', '--sort', dest='sorting', action='store', default='popular',
|
||||
help='sorting of doujinshi (recent / popular / popular-[today|week])',
|
||||
choices=['recent', 'popular', 'popular-today', 'popular-week', 'date'])
|
||||
parser.add_option('--sorting', '--sort', dest='sorting', action='store', default='popular-all',
|
||||
help='sorting of doujinshi (recent / popular-all / popular-[today|week])',
|
||||
choices=['recent', 'popular-all', 'popular-today', 'popular-week', 'date'])
|
||||
|
||||
# download options
|
||||
parser.add_option('--output', '-o', type='string', dest='output_dir', action='store', default='./',
|
||||
@ -211,12 +213,12 @@ def cmd_parser():
|
||||
_ = [i.strip() for i in f.readlines()]
|
||||
args.id = set(int(i) for i in _ if i.isdigit())
|
||||
|
||||
if (args.is_download or args.is_show) and not args.id and not args.keyword and not args.favorites:
|
||||
if (args.is_download or args.is_show) and not args.id and not args.keyword and not args.favorites and not args.artist:
|
||||
logger.critical('Doujinshi id(s) are required for downloading')
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
if not args.keyword and not args.id and not args.favorites:
|
||||
if not args.keyword and not args.id and not args.favorites and not args.artist:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -46,7 +46,7 @@ def main():
|
||||
if not options.is_download:
|
||||
logger.warning('You do not specify --download option')
|
||||
|
||||
doujinshis = favorites_parser() if options.page_all else favorites_parser(page=page_list)
|
||||
doujinshis = favorites_parser(page=page_list)
|
||||
|
||||
elif options.keyword:
|
||||
if constant.CONFIG['language']:
|
||||
@ -96,9 +96,9 @@ def main():
|
||||
if not options.is_nohtml and not options.is_cbz and not options.is_pdf:
|
||||
generate_html(options.output_dir, doujinshi, template=constant.CONFIG['template'])
|
||||
elif options.is_cbz:
|
||||
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir, True, options.move_to_folder)
|
||||
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
|
||||
elif options.is_pdf:
|
||||
generate_pdf(options.output_dir, doujinshi, options.rm_origin_dir, options.move_to_folder)
|
||||
generate_pdf(options.output_dir, doujinshi, options.rm_origin_dir)
|
||||
|
||||
if options.main_viewer:
|
||||
generate_main_html(options.output_dir)
|
||||
|
@ -20,10 +20,9 @@ class DoujinshiInfo(dict):
|
||||
|
||||
def __getattr__(self, item):
|
||||
try:
|
||||
ret = dict.__getitem__(self, item)
|
||||
return ret if ret else 'Unknown'
|
||||
return dict.__getitem__(self, item)
|
||||
except KeyError:
|
||||
return 'Unknown'
|
||||
return ''
|
||||
|
||||
|
||||
class Doujinshi(object):
|
||||
@ -39,12 +38,8 @@ class Doujinshi(object):
|
||||
self.url = f'{DETAIL_URL}/{self.id}'
|
||||
self.info = DoujinshiInfo(**kwargs)
|
||||
|
||||
ag_value = self.info.groups if self.info.artists == 'Unknown' else self.info.artists
|
||||
name_format = name_format.replace('%ag', format_filename(ag_value))
|
||||
|
||||
name_format = name_format.replace('%i', format_filename(str(self.id)))
|
||||
name_format = name_format.replace('%a', format_filename(self.info.artists))
|
||||
name_format = name_format.replace('%g', format_filename(self.info.groups))
|
||||
|
||||
name_format = name_format.replace('%t', format_filename(self.name))
|
||||
name_format = name_format.replace('%p', format_filename(self.pretty_name))
|
||||
@ -52,16 +47,15 @@ class Doujinshi(object):
|
||||
self.filename = format_filename(name_format, 255, True)
|
||||
|
||||
self.table = [
|
||||
['Parodies', self.info.parodies],
|
||||
['Doujinshi', self.name],
|
||||
['Subtitle', self.info.subtitle],
|
||||
['Characters', self.info.characters],
|
||||
['Authors', self.info.artists],
|
||||
['Groups', self.info.groups],
|
||||
['Languages', self.info.languages],
|
||||
['Tags', self.info.tags],
|
||||
['URL', self.url],
|
||||
['Pages', self.pages],
|
||||
["Parodies", self.info.parodies],
|
||||
["Doujinshi", self.name],
|
||||
["Subtitle", self.info.subtitle],
|
||||
["Characters", self.info.characters],
|
||||
["Authors", self.info.artists],
|
||||
["Languages", self.info.languages],
|
||||
["Tags", self.info.tags],
|
||||
["URL", self.url],
|
||||
["Pages", self.pages],
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -123,7 +123,6 @@ class Downloader(Singleton):
|
||||
logger.warning(f'CBZ file "{folder}.cbz" exists, ignored download request')
|
||||
return
|
||||
|
||||
logger.info(f'Doujinshi will be saved at "{folder}"')
|
||||
if not os.path.exists(folder):
|
||||
try:
|
||||
os.makedirs(folder)
|
||||
|
@ -163,9 +163,12 @@ def generate_main_html(output_dir='./'):
|
||||
logger.warning(f'Writing Main Viewer failed ({e})')
|
||||
|
||||
|
||||
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=True, move_to_folder=False):
|
||||
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=True):
|
||||
if doujinshi_obj is not None:
|
||||
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||
if os.path.exists(doujinshi_dir+".cbz"):
|
||||
logger.warning(f'Comic Book CBZ file exists, skip "{doujinshi_dir}"')
|
||||
return
|
||||
if write_comic_info:
|
||||
serialize_comic_xml(doujinshi_obj, doujinshi_dir)
|
||||
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), f'{doujinshi_obj.filename}.cbz')
|
||||
@ -185,21 +188,10 @@ def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_
|
||||
if rm_origin_dir:
|
||||
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
||||
|
||||
if move_to_folder:
|
||||
for filename in os.listdir(doujinshi_dir):
|
||||
file_path = os.path.join(doujinshi_dir, filename)
|
||||
if os.path.isfile(file_path):
|
||||
try:
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
print(f"Error deleting file: {e}")
|
||||
|
||||
shutil.move(cbz_filename, doujinshi_dir)
|
||||
|
||||
logger.log(16, f'Comic Book CBZ file has been written to "{doujinshi_dir}"')
|
||||
|
||||
|
||||
def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, move_to_folder=False):
|
||||
def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
||||
try:
|
||||
import img2pdf
|
||||
|
||||
@ -227,17 +219,6 @@ def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, move_t
|
||||
if rm_origin_dir:
|
||||
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
||||
|
||||
if move_to_folder:
|
||||
for filename in os.listdir(doujinshi_dir):
|
||||
file_path = os.path.join(doujinshi_dir, filename)
|
||||
if os.path.isfile(file_path):
|
||||
try:
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
print(f"Error deleting file: {e}")
|
||||
|
||||
shutil.move(pdf_filename, doujinshi_dir)
|
||||
|
||||
logger.log(16, f'PDF file has been written to "{doujinshi_dir}"')
|
||||
|
||||
except ImportError:
|
||||
@ -254,7 +235,7 @@ def format_filename(s, length=MAX_FIELD_LENGTH, _truncate_only=False):
|
||||
# maybe you can use `--format` to select a suitable filename
|
||||
|
||||
if not _truncate_only:
|
||||
ban_chars = '\\\'/:,;*?"<>|\t\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b'
|
||||
ban_chars = '\\\'/:,;*?"<>|\t'
|
||||
filename = s.translate(str.maketrans(ban_chars, ' ' * len(ban_chars))).strip()
|
||||
filename = ' '.join(filename.split())
|
||||
|
||||
@ -309,11 +290,11 @@ def generate_metadata_file(output_dir, table, doujinshi_obj=None):
|
||||
|
||||
f = open(os.path.join(doujinshi_dir, 'info.txt'), 'w', encoding='utf-8')
|
||||
|
||||
fields = ['TITLE', 'ORIGINAL TITLE', 'AUTHOR', 'ARTIST', 'GROUPS', 'CIRCLE', 'SCANLATOR',
|
||||
fields = ['TITLE', 'ORIGINAL TITLE', 'AUTHOR', 'ARTIST', 'CIRCLE', 'SCANLATOR',
|
||||
'TRANSLATOR', 'PUBLISHER', 'DESCRIPTION', 'STATUS', 'CHAPTERS', 'PAGES',
|
||||
'TAGS', 'TYPE', 'LANGUAGE', 'RELEASED', 'READING DIRECTION', 'CHARACTERS',
|
||||
'SERIES', 'PARODY', 'URL']
|
||||
special_fields = ['PARODY', 'TITLE', 'ORIGINAL TITLE', 'CHARACTERS', 'AUTHOR', 'GROUPS',
|
||||
special_fields = ['PARODY', 'TITLE', 'ORIGINAL TITLE', 'CHARACTERS', 'AUTHOR',
|
||||
'LANGUAGE', 'TAGS', 'URL', 'PAGES']
|
||||
|
||||
for i in range(len(fields)):
|
||||
|
29
poetry.lock
generated
29
poetry.lock
generated
@ -1,9 +1,10 @@
|
||||
# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand.
|
||||
# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "beautifulsoup4"
|
||||
version = "4.11.2"
|
||||
description = "Screen-scraping library"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6.0"
|
||||
files = [
|
||||
@ -22,6 +23,7 @@ lxml = ["lxml"]
|
||||
name = "certifi"
|
||||
version = "2022.12.7"
|
||||
description = "Python package for providing Mozilla's CA Bundle."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
files = [
|
||||
@ -33,6 +35,7 @@ files = [
|
||||
name = "charset-normalizer"
|
||||
version = "3.0.1"
|
||||
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
@ -130,6 +133,7 @@ files = [
|
||||
name = "idna"
|
||||
version = "3.4"
|
||||
description = "Internationalized Domain Names in Applications (IDNA)"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.5"
|
||||
files = [
|
||||
@ -141,6 +145,7 @@ files = [
|
||||
name = "iso8601"
|
||||
version = "1.1.0"
|
||||
description = "Simple module to parse ISO 8601 dates"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6.2,<4.0"
|
||||
files = [
|
||||
@ -150,20 +155,21 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.31.0"
|
||||
version = "2.28.2"
|
||||
description = "Python HTTP for Humans."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
python-versions = ">=3.7, <4"
|
||||
files = [
|
||||
{file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"},
|
||||
{file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"},
|
||||
{file = "requests-2.28.2-py3-none-any.whl", hash = "sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa"},
|
||||
{file = "requests-2.28.2.tar.gz", hash = "sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
certifi = ">=2017.4.17"
|
||||
charset-normalizer = ">=2,<4"
|
||||
idna = ">=2.5,<4"
|
||||
urllib3 = ">=1.21.1,<3"
|
||||
urllib3 = ">=1.21.1,<1.27"
|
||||
|
||||
[package.extras]
|
||||
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
||||
@ -173,6 +179,7 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
||||
name = "soupsieve"
|
||||
version = "2.4"
|
||||
description = "A modern CSS selector implementation for Beautiful Soup."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
@ -184,6 +191,7 @@ files = [
|
||||
name = "tabulate"
|
||||
version = "0.9.0"
|
||||
description = "Pretty-print tabular data"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
@ -196,17 +204,18 @@ widechars = ["wcwidth"]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "1.26.18"
|
||||
version = "1.26.14"
|
||||
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
|
||||
files = [
|
||||
{file = "urllib3-1.26.18-py2.py3-none-any.whl", hash = "sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07"},
|
||||
{file = "urllib3-1.26.18.tar.gz", hash = "sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0"},
|
||||
{file = "urllib3-1.26.14-py2.py3-none-any.whl", hash = "sha256:75edcdc2f7d85b137124a6c3c9fc3933cdeaa12ecb9a6a959f22797a0feca7e1"},
|
||||
{file = "urllib3-1.26.14.tar.gz", hash = "sha256:076907bf8fd355cde77728471316625a4d2f7e713c125f51953bb5b3eecf4f72"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
brotli = ["brotli (==1.0.9)", "brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"]
|
||||
brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"]
|
||||
secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"]
|
||||
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "nhentai"
|
||||
version = "0.5.3"
|
||||
version = "0.5.2"
|
||||
description = "nhentai doujinshi downloader"
|
||||
authors = ["Ricter Z <ricterzheng@gmail.com>"]
|
||||
license = "MIT"
|
||||
|
Reference in New Issue
Block a user