From 97857b8dc6baa7c4252676e5e2ca3965e304d074 Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 28 Jul 2019 11:40:19 +0800 Subject: [PATCH 01/22] "" :) --- .travis.yml | 2 +- README.rst | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6b5330a..b99c73e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: script: - echo 268642 > /tmp/test.txt - - NHENTAI=https://nhentai.net nhentai --cookie '__cfduid=da09f237ceb0f51c75980b0b3fda3ce571558179357; _ga=GA1.2.2000087053.1558179358; _gid=GA1.2.782652201.1560348447; csrftoken=E2O8wfriFkcXUgN1AC41DoLqfRaBbggIUdvy46yC45PKCRCmCHQHQ7YRUy0d7FXZ; sessionid=0rapzxkt6yl1wjhdxm9whtfdc7gvw0iu' + - NHENTAI=https://nhentai.net nhentai --cookie "__cfduid=da09f237ceb0f51c75980b0b3fda3ce571558179357; _ga=GA1.2.2000087053.1558179358; _gid=GA1.2.782652201.1560348447; csrftoken=E2O8wfriFkcXUgN1AC41DoLqfRaBbggIUdvy46yC45PKCRCmCHQHQ7YRUy0d7FXZ; sessionid=0rapzxkt6yl1wjhdxm9whtfdc7gvw0iu" - NHENTAI=https://nhentai.net nhentai --search umaru - NHENTAI=https://nhentai.net nhentai --id=152503,146134 -t 10 --output=/tmp/ --cbz - NHENTAI=https://nhentai.net nhentai --tag lolicon diff --git a/README.rst b/README.rst index 5369190..235fd0b 100644 --- a/README.rst +++ b/README.rst @@ -48,7 +48,8 @@ Set your nhentai cookie against captcha: .. code-block:: bash - nhentai --cookie 'YOUR COOKIE FROM nhentai.net' + # + nhentai --cookie "YOUR COOKIE FROM nhentai.net" Download specified doujinshi: From 4ca582c1048a9958e15969129e687d83e38dc9b3 Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 28 Jul 2019 11:46:06 +0800 Subject: [PATCH 02/22] fix #74 --- README.rst | 2 +- nhentai/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 235fd0b..c783158 100644 --- a/README.rst +++ b/README.rst @@ -48,7 +48,7 @@ Set your nhentai cookie against captcha: .. code-block:: bash - # + # nhentai --cookie "YOUR COOKIE FROM nhentai.net" Download specified doujinshi: diff --git a/nhentai/utils.py b/nhentai/utils.py index 3bdf278..6a0d00b 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -168,7 +168,7 @@ def generate_main_html(output_dir='./'): def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False): if doujinshi_obj is not None: doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename) - cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '%s.cbz' % doujinshi_obj.id) + cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '{}.cbz'.format(doujinshi_obj.filename)) else: cbz_filename = './doujinshi.cbz' doujinshi_dir = '.' From 44178a8cfb02dcb62bb722d8e6fdd187c77864a7 Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 28 Jul 2019 11:46:48 +0800 Subject: [PATCH 03/22] remove comment --- README.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/README.rst b/README.rst index c783158..9c767e0 100644 --- a/README.rst +++ b/README.rst @@ -48,7 +48,6 @@ Set your nhentai cookie against captcha: .. code-block:: bash - # nhentai --cookie "YOUR COOKIE FROM nhentai.net" Download specified doujinshi: From 6e2a25cf55839996a5ccd383c0487362ffcd1f6f Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 28 Jul 2019 11:48:47 +0800 Subject: [PATCH 04/22] fix bug in tag parser #70 --- nhentai/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nhentai/parser.py b/nhentai/parser.py index b96e707..cb53cc8 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -201,9 +201,9 @@ def tag_parser(tag_name, max_page=1): for p in range(1, max_page + 1): logger.debug('Fetching page {0} for doujinshi with tag \'{1}\''.format(p, tag_name)) - response = request('get', url='%s/%s?page=%d' % (constant.TAG_URL, tag_name, p)).content + response = request('get', url='%s/%s/?page=%d' % (constant.TAG_URL, tag_name, p)).content - result = _get_title_and_id(response) + result += _get_title_and_id(response) if not result: logger.error('Cannot find doujinshi id of tag \'{0}\''.format(tag_name)) return From 62e3552c847af7cd840d79c99acf6a47c6d85107 Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 28 Jul 2019 11:55:12 +0800 Subject: [PATCH 05/22] update cookiewq --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index b99c73e..cdb9d4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,10 @@ install: script: - echo 268642 > /tmp/test.txt - - NHENTAI=https://nhentai.net nhentai --cookie "__cfduid=da09f237ceb0f51c75980b0b3fda3ce571558179357; _ga=GA1.2.2000087053.1558179358; _gid=GA1.2.782652201.1560348447; csrftoken=E2O8wfriFkcXUgN1AC41DoLqfRaBbggIUdvy46yC45PKCRCmCHQHQ7YRUy0d7FXZ; sessionid=0rapzxkt6yl1wjhdxm9whtfdc7gvw0iu" - - NHENTAI=https://nhentai.net nhentai --search umaru - - NHENTAI=https://nhentai.net nhentai --id=152503,146134 -t 10 --output=/tmp/ --cbz - - NHENTAI=https://nhentai.net nhentai --tag lolicon - - NHENTAI=https://nhentai.net nhentai -F - - NHENTAI=https://nhentai.net nhentai --file /tmp/test.txt + - nhentai --cookie "csrftoken=3c4Mzn4f6NAI1awFqfIh495G3pv5Wade9n63Kx03mkSac8c2QR5vRR4jCwVzb3OR; sessionid=m034e2dyyxgbl9s07hbzgfhvadbap2tk" + - nhentai --search umaru + - nhentai --id=152503,146134 -t 10 --output=/tmp/ --cbz + - nhentai --tag lolicon + - nhentai -F + - nhentai --file /tmp/test.txt - nhentai --id=152503,146134 --gen-main --output=/tmp/ From d045adfd6adbe2f3afd96af523bca3467c14ef01 Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 28 Jul 2019 11:58:00 +0800 Subject: [PATCH 06/22] 0.3.6 --- nhentai/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nhentai/__init__.py b/nhentai/__init__.py index 8efd062..2bc558a 100644 --- a/nhentai/__init__.py +++ b/nhentai/__init__.py @@ -1,3 +1,3 @@ -__version__ = '0.3.5' +__version__ = '0.3.6' __author__ = 'RicterZ' __email__ = 'ricterzheng@gmail.com' From 88c0c1e0216d988bd21a8586e92df325ef0eeae3 Mon Sep 17 00:00:00 2001 From: Alocks Date: Sun, 1 Dec 2019 21:23:41 -0300 Subject: [PATCH 07/22] Added language option and metadata serializer --- README.rst | 6 ++++++ nhentai/cmdline.py | 7 ++++--- nhentai/command.py | 6 ++++++ nhentai/parser.py | 7 +++++-- nhentai/serializer.py | 24 ++++++++++++++++++++++++ nhentai/utils.py | 13 +++++++++---- 6 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 nhentai/serializer.py diff --git a/README.rst b/README.rst index 4c040e7..add2b63 100644 --- a/README.rst +++ b/README.rst @@ -74,6 +74,12 @@ Download by tag name: nhentai --tag lolicon --download --page=2 +Download by language: + +.. code-block:: bash + + nhentai --language english --download --page=2 + Download by artist name: .. code-block:: bash diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 10f5ecd..bbdab63 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -55,6 +55,7 @@ def cmd_parser(): parser.add_option('--character', type='string', dest='character', action='store', help='download doujinshi by character') parser.add_option('--parody', type='string', dest='parody', action='store', help='download doujinshi by parody') parser.add_option('--group', type='string', dest='group', action='store', help='download doujinshi by group') + parser.add_option('--language', type='string', dest='language', action='store', help='download doujinshi by language') parser.add_option('--favorites', '-F', action='store_true', dest='favorites', help='list or download your favorites.') @@ -113,7 +114,7 @@ def cmd_parser(): if args.main_viewer and not args.id and not args.keyword and \ not args.tag and not args.artist and not args.character and \ - not args.parody and not args.group and not args.favorites: + not args.parody and not args.group and not args.language and not args.favorites: generate_main_html() exit(0) @@ -174,13 +175,13 @@ def cmd_parser(): if (args.is_download or args.is_show) and not args.id and not args.keyword and \ not args.tag and not args.artist and not args.character and \ - not args.parody and not args.group and not args.favorites: + not args.parody and not args.group and not args.language and not args.favorites: logger.critical('Doujinshi id(s) are required for downloading') parser.print_help() exit(1) if not args.keyword and not args.id and not args.tag and not args.artist and \ - not args.character and not args.parody and not args.group and not args.favorites: + not args.character and not args.parody and not args.group and not args.language and not args.favorites: parser.print_help() exit(1) diff --git a/nhentai/command.py b/nhentai/command.py index 8009351..2dad43f 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -70,6 +70,12 @@ def main(): if options.is_download and doujinshis: doujinshi_ids = [i['id'] for i in doujinshis] + elif options.language: + doujinshis = tag_parser(options.group, max_page=options.max_page, index=5) + print_doujinshi(doujinshis) + if options.is_download and doujinshis: + doujinshi_ids = [i['id'] for i in doujinshis] + elif options.keyword: doujinshis = search_parser(options.keyword, sorting=options.sorting, page=options.page) print_doujinshi(doujinshis) diff --git a/nhentai/parser.py b/nhentai/parser.py index 57e94bf..081e85a 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -158,7 +158,7 @@ def doujinshi_parser(id_): # gain information of the doujinshi information_fields = doujinshi_info.find_all('div', attrs={'class': 'field-name'}) - needed_fields = ['Characters', 'Artists', 'Languages', 'Tags'] + needed_fields = ['Characters', 'Artists', 'Languages', 'Tags', 'Parodies', 'Groups', 'Categories'] for field in information_fields: field_name = field.contents[0].strip().strip(':') if field_name in needed_fields: @@ -166,6 +166,9 @@ def doujinshi_parser(id_): field.find_all('a', attrs={'class': 'tag'})] doujinshi[field_name.lower()] = ', '.join(data) + time_field = doujinshi_info.find('time') + if time_field.has_attr('datetime'): + doujinshi['date'] = time_field['datetime'] return doujinshi @@ -302,7 +305,7 @@ def __api_suspended_doujinshi_parser(id_): doujinshi['pages'] = len(response['images']['pages']) # gain information of the doujinshi - needed_fields = ['character', 'artist', 'language', 'tag'] + needed_fields = ['character', 'artist', 'language', 'tag', 'parody', 'group', 'category'] for tag in response['tags']: tag_type = tag['type'] if tag_type in needed_fields: diff --git a/nhentai/serializer.py b/nhentai/serializer.py new file mode 100644 index 0000000..5b5675c --- /dev/null +++ b/nhentai/serializer.py @@ -0,0 +1,24 @@ +# coding: utf-8 + + +def serialize(doujinshi): + metadata = {'Title' : doujinshi.name, + 'Subtitle' : doujinshi.info.subtitle} + if doujinshi.info.date: + metadata['Upload_Date'] = doujinshi.info.date + if doujinshi.info.parodies: + metadata['Parodies'] = [i.strip() for i in doujinshi.info.parodies.split(',')] + if doujinshi.info.characters: + metadata['Characters'] = [i.strip() for i in doujinshi.info.characters.split(',')] + if doujinshi.info.tags: + metadata['Tags'] = [i.strip() for i in doujinshi.info.tags.split(',')] + if doujinshi.info.artists: + metadata['Artists'] = [i.strip() for i in doujinshi.info.artists.split(',')] + if doujinshi.info.groups: + metadata['Groups'] = [i.strip() for i in doujinshi.info.groups.split(',')] + if doujinshi.info.languages: + metadata['Languages'] = [i.strip() for i in doujinshi.info.languages.split(',')] + metadata['Categories'] = doujinshi.info.categories + metadata['URL'] = doujinshi.url + metadata['Pages'] = doujinshi.pages + return metadata diff --git a/nhentai/utils.py b/nhentai/utils.py index 815c690..4af629d 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals, print_function import sys import re import os +import json import string import zipfile import shutil @@ -11,6 +12,7 @@ import requests from nhentai import constant from nhentai.logger import logger +from nhentai.serializer import serialize def request(method, url, **kwargs): @@ -85,13 +87,16 @@ def generate_html(output_dir='.', doujinshi_obj=None): js = readfile('viewer/scripts.js') if doujinshi_obj is not None: - title = doujinshi_obj.name + metadata = serialize(doujinshi_obj) if sys.version_info < (3, 0): - title = title.encode('utf-8') + metadata['Title'] = doujinshi_obj.name.encode('utf-8') + metadata['Subtitle'] = doujinshi_obj.info.subtitle.encode('utf-8') + with open(os.path.join(doujinshi_dir, 'metadata.json'), 'w') as f: + json.dump(metadata, f, separators=','':') else: - title = 'nHentai HTML Viewer' + metadata= {'Title': 'nHentai HTML Viewer'} - data = html.format(TITLE=title, IMAGES=image_html, SCRIPTS=js, STYLES=css) + data = html.format(TITLE=metadata['Title'], IMAGES=image_html, SCRIPTS=js, STYLES=css) try: if sys.version_info < (3, 0): with open(os.path.join(doujinshi_dir, 'index.html'), 'w') as f: From 0abcb048b410dec41fd1b213dec01a03ebe7ddea Mon Sep 17 00:00:00 2001 From: Alocks Date: Mon, 2 Dec 2019 16:46:22 -0300 Subject: [PATCH 08/22] filter for main page(1/2) --- nhentai/utils.py | 18 +++++++++++++----- nhentai/viewer/main.css | 37 +++++++++++++++++++++++++++++++++---- nhentai/viewer/main.html | 9 +++++---- nhentai/viewer/main.js | 0 4 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 nhentai/viewer/main.js diff --git a/nhentai/utils.py b/nhentai/utils.py index 4af629d..ce7033c 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -94,7 +94,7 @@ def generate_html(output_dir='.', doujinshi_obj=None): with open(os.path.join(doujinshi_dir, 'metadata.json'), 'w') as f: json.dump(metadata, f, separators=','':') else: - metadata= {'Title': 'nHentai HTML Viewer'} + metadata = {'Title': 'nHentai HTML Viewer'} data = html.format(TITLE=metadata['Title'], IMAGES=image_html, SCRIPTS=js, STYLES=css) try: @@ -117,10 +117,11 @@ def generate_main_html(output_dir='./'): Default output folder will be the CLI path. """ - count = 0 image_html = '' main = readfile('viewer/main.html') css = readfile('viewer/main.css') + js = readfile('viewer/main.js') + element = '\n\