From bf03881ed6839d0b785cb1fccfe0dd06086c0f4d Mon Sep 17 00:00:00 2001 From: ODtian Date: Tue, 23 Jun 2020 20:39:41 +0800 Subject: [PATCH 1/3] Fix fatal error and keep index of id which from file --- nhentai/cmdline.py | 6 ++++-- nhentai/parser.py | 18 +++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 9decc88..90ea59d 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -186,8 +186,10 @@ def cmd_parser(): if args.file: with open(args.file, 'r') as f: - _ = [i.strip() for i in f.readlines()] - args.id = set(int(i) for i in _ if i.isdigit()) + _ = [int(i.strip()) for i in f.readlines() if i.strip().isdigit()] + # args.id = list(set(int(i) for i in _ if i.isdigit())) + args.id = list(set(_)) + args.id.sort(key=_.index) 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 \ diff --git a/nhentai/parser.py b/nhentai/parser.py index 97ea354..a95e03e 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -178,21 +178,21 @@ def doujinshi_parser(id_): doujinshi['img_id'] = img_id.group(1) doujinshi['ext'] = ext - pages = 0 - for _ in doujinshi_info.find_all('div', class_=''): - pages = re.search('([\d]+) pages', _.text) - if pages: - pages = pages.group(1) - break - doujinshi['pages'] = int(pages) - + # pages = 0 + # for _ in doujinshi_info.find_all('div', class_=''): + # pages = re.search('([\d]+) pages', _.text) + # if pages: + # pages = pages.group(1) + # break + # doujinshi['pages'] = int(pages) + doujinshi['pages'] = len(ext) # gain information of the doujinshi information_fields = doujinshi_info.find_all('div', attrs={'class': 'field-name'}) 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: - data = [sub_field.contents[0].strip() for sub_field in + data = [sub_field.contents[0].text.strip() for sub_field in field.find_all('a', attrs={'class': 'tag'})] doujinshi[field_name.lower()] = ', '.join(data) From 84cad0d475af1b828775b35ce9c15fd7681a54ab Mon Sep 17 00:00:00 2001 From: ODtian Date: Wed, 24 Jun 2020 12:00:17 +0800 Subject: [PATCH 2/3] Update cmdline.py --- nhentai/cmdline.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 90ea59d..6e6c8d6 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -206,8 +206,8 @@ def cmd_parser(): if args.threads <= 0: args.threads = 1 - elif args.threads > 15: - logger.critical('Maximum number of used threads is 15') - exit(1) + # elif args.threads > 15: + # logger.critical('Maximum number of used threads is 15') + # exit(1) return args From 4c85cebb78a600dc9dc8c1f5fc3b841964669dc7 Mon Sep 17 00:00:00 2001 From: Ricter Zheng Date: Fri, 26 Jun 2020 12:47:10 +0800 Subject: [PATCH 3/3] Revert "Fix fatal error and keep index of id which from file" --- nhentai/cmdline.py | 12 +++++------- nhentai/parser.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 6e6c8d6..9decc88 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -186,10 +186,8 @@ def cmd_parser(): if args.file: with open(args.file, 'r') as f: - _ = [int(i.strip()) for i in f.readlines() if i.strip().isdigit()] - # args.id = list(set(int(i) for i in _ if i.isdigit())) - args.id = list(set(_)) - args.id.sort(key=_.index) + _ = [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.tag and not args.artist and not args.character and \ @@ -206,8 +204,8 @@ def cmd_parser(): if args.threads <= 0: args.threads = 1 - # elif args.threads > 15: - # logger.critical('Maximum number of used threads is 15') - # exit(1) + elif args.threads > 15: + logger.critical('Maximum number of used threads is 15') + exit(1) return args diff --git a/nhentai/parser.py b/nhentai/parser.py index a95e03e..97ea354 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -178,21 +178,21 @@ def doujinshi_parser(id_): doujinshi['img_id'] = img_id.group(1) doujinshi['ext'] = ext - # pages = 0 - # for _ in doujinshi_info.find_all('div', class_=''): - # pages = re.search('([\d]+) pages', _.text) - # if pages: - # pages = pages.group(1) - # break - # doujinshi['pages'] = int(pages) - doujinshi['pages'] = len(ext) + pages = 0 + for _ in doujinshi_info.find_all('div', class_=''): + pages = re.search('([\d]+) pages', _.text) + if pages: + pages = pages.group(1) + break + doujinshi['pages'] = int(pages) + # gain information of the doujinshi information_fields = doujinshi_info.find_all('div', attrs={'class': 'field-name'}) 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: - data = [sub_field.contents[0].text.strip() for sub_field in + data = [sub_field.contents[0].strip() for sub_field in field.find_all('a', attrs={'class': 'tag'})] doujinshi[field_name.lower()] = ', '.join(data)