From c75e9efb21f5fb42cce69387fffa4f874bc490b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:52:23 +0000 Subject: [PATCH 1/7] Bump certifi from 2022.12.7 to 2024.7.4 Bumps [certifi](https://github.com/certifi/python-certifi) from 2022.12.7 to 2024.7.4. - [Commits](https://github.com/certifi/python-certifi/compare/2022.12.07...2024.07.04) --- updated-dependencies: - dependency-name: certifi dependency-type: indirect ... Signed-off-by: dependabot[bot] --- poetry.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index 5765e1a..ebea6b9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# 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.8.3 and should not be changed by hand. [[package]] name = "beautifulsoup4" @@ -20,13 +20,13 @@ lxml = ["lxml"] [[package]] name = "certifi" -version = "2022.12.7" +version = "2024.7.4" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2022.12.7-py3-none-any.whl", hash = "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18"}, - {file = "certifi-2022.12.7.tar.gz", hash = "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3"}, + {file = "certifi-2024.7.4-py3-none-any.whl", hash = "sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90"}, + {file = "certifi-2024.7.4.tar.gz", hash = "sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b"}, ] [[package]] From 4162eabe9347b7debf9f31a02f2bb837f65021ee Mon Sep 17 00:00:00 2001 From: PenitentMonke <> Date: Sun, 7 Jul 2024 02:40:33 -0300 Subject: [PATCH 2/7] Adhere to XDG base dir spec on Linux Change how NHENTAI_HOME is set to follow the XDG Base Directory Specification where possible, when running on Linux. ISSUE: 299 --- nhentai/constant.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nhentai/constant.py b/nhentai/constant.py index 3d677ad..9307887 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -3,7 +3,22 @@ import os import tempfile from urllib.parse import urlparse +from platform import system +def get_nhentai_home() -> str: + home = os.getenv('HOME', tempfile.gettempdir()) + + if system() == 'Linux': + xdgdat = os.getenv('XDG_DATA_HOME') + if xdgdat and os.path.exists(os.path.join(xdgdat, 'nhentai')): + return os.path.join(xdgdat, 'nhentai') + if home and os.path.exists(os.path.join(home, '.nhentai')): + return os.path.join(home, '.nhentai') + if xdgdat: + return os.path.join(xdgdat, 'nhentai') + + # Use old default path in other systems + return os.path.join(home, '.nhentai') DEBUG = os.getenv('DEBUG', False) BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net') @@ -21,7 +36,7 @@ FAV_URL = f'{BASE_URL}/favorites/' IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries' -NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai') +NHENTAI_HOME = get_nhentai_home() NHENTAI_HISTORY = os.path.join(NHENTAI_HOME, 'history.sqlite3') NHENTAI_CONFIG_FILE = os.path.join(NHENTAI_HOME, 'config.json') From a248ff98c4adbc2decef6c4739c9853f1bd66abe Mon Sep 17 00:00:00 2001 From: vglint <181528323+vglint@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:56:01 -0700 Subject: [PATCH 3/7] Fix gallery search for folders with underscore Gallery title names replace '_' in the folder name with ' ' (generate_main_html()). To match against these title names when searching, we must also replace '_' with ' ' for each folder name we add to the list of titles to unhide. --- nhentai/viewer/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nhentai/viewer/main.js b/nhentai/viewer/main.js index 5a314fc..e280068 100644 --- a/nhentai/viewer/main.js +++ b/nhentai/viewer/main.js @@ -139,7 +139,7 @@ function filter_searcher(){ break } } - if (verifier){doujinshi_id.push(data[i].Folder);} + if (verifier){doujinshi_id.push(data[i].Folder.replace("_", " "));} } var gallery = document.getElementsByClassName("gallery-favorite"); for (var i = 0; i < gallery.length; i++){ @@ -174,4 +174,4 @@ function tag_maker(data){ document.getElementById("tags").appendChild(node); } } -} \ No newline at end of file +} From 4ed452378260cc2143e1577a9df24df9dcf9d1bf Mon Sep 17 00:00:00 2001 From: ricterz Date: Fri, 20 Sep 2024 23:27:37 +0800 Subject: [PATCH 4/7] fix #341 --- nhentai/constant.py | 5 +++++ nhentai/downloader.py | 12 ++++++++---- nhentai/parser.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/nhentai/constant.py b/nhentai/constant.py index 9307887..585250b 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -35,6 +35,11 @@ FAV_URL = f'{BASE_URL}/favorites/' IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries' +IMAGE_URL_MIRRORS = [ + f'{urlparse(BASE_URL).scheme}://i3.{urlparse(BASE_URL).hostname}' + f'{urlparse(BASE_URL).scheme}://i5.{urlparse(BASE_URL).hostname}' + f'{urlparse(BASE_URL).scheme}://i7.{urlparse(BASE_URL).hostname}' +] NHENTAI_HOME = get_nhentai_home() NHENTAI_HISTORY = os.path.join(NHENTAI_HOME, 'history.sqlite3') diff --git a/nhentai/downloader.py b/nhentai/downloader.py index b852352..227a0f0 100644 --- a/nhentai/downloader.py +++ b/nhentai/downloader.py @@ -67,10 +67,14 @@ class Downloader(Singleton): try: response = request('get', url, stream=True, timeout=self.timeout, proxies=proxy) if response.status_code != 200: - raise NHentaiImageNotExistException - - except NHentaiImageNotExistException as e: - raise e + path = urlparse(url).path + for mirror in constant.IMAGE_URL_MIRRORS: + print(f'{mirror}{path}') + mirror_url = f'{mirror}{path}' + response = request('get', mirror_url, stream=True, + timeout=self.timeout, proxies=proxy) + if response.status_code == 200: + break except Exception as e: i += 1 diff --git a/nhentai/parser.py b/nhentai/parser.py index e1e24ff..65d92cd 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -135,7 +135,7 @@ def doujinshi_parser(id_, counter=0): logger.warning(f'Error: {e}, ignored') return None - print(response) + # print(response) html = BeautifulSoup(response, 'html.parser') doujinshi_info = html.find('div', attrs={'id': 'info'}) From 29aac84d53d9a0d2257552aaf7056b8b9c505bcd Mon Sep 17 00:00:00 2001 From: ricterz Date: Fri, 20 Sep 2024 23:34:26 +0800 Subject: [PATCH 5/7] fix #336 --- nhentai/constant.py | 5 ++++- nhentai/parser.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nhentai/constant.py b/nhentai/constant.py index 585250b..7dadbbd 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -5,6 +5,7 @@ import tempfile from urllib.parse import urlparse from platform import system + def get_nhentai_home() -> str: home = os.getenv('HOME', tempfile.gettempdir()) @@ -20,6 +21,7 @@ def get_nhentai_home() -> str: # Use old default path in other systems return os.path.join(home, '.nhentai') + DEBUG = os.getenv('DEBUG', False) BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net') @@ -52,7 +54,8 @@ CONFIG = { 'cookie': '', 'language': '', 'template': '', - 'useragent': 'nhentai command line client (https://github.com/RicterZ/nhentai)' + 'useragent': 'nhentai command line client (https://github.com/RicterZ/nhentai)', + 'max_filename': 85 } LANGUAGE_ISO = { diff --git a/nhentai/parser.py b/nhentai/parser.py index 65d92cd..5b7f26c 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -327,7 +327,9 @@ def search_parser(keyword, sorting, page, is_page_all=False): for row in response['result']: title = row['title']['english'] - title = title[:85] + '..' if len(title) > 85 else title + title = title[:constant.CONFIG['max_filename']] + '..' if \ + len(title) > constant.CONFIG['max_filename'] else title + result.append({'id': row['id'], 'title': title}) not_exists_persist = False From 35c55503fa27f584c4dc1e5e15ced23b25274eae Mon Sep 17 00:00:00 2001 From: ricterz Date: Fri, 20 Sep 2024 23:39:38 +0800 Subject: [PATCH 6/7] 0.5.6 --- nhentai/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nhentai/__init__.py b/nhentai/__init__.py index e6bc8b4..2ba97b4 100644 --- a/nhentai/__init__.py +++ b/nhentai/__init__.py @@ -1,3 +1,3 @@ -__version__ = '0.5.5' +__version__ = '0.5.6' __author__ = 'RicterZ' __email__ = 'ricterzheng@gmail.com' From 2bd862777b7707faef4ba9e8703c7cd0dd26f489 Mon Sep 17 00:00:00 2001 From: ricterz Date: Fri, 20 Sep 2024 23:53:26 +0800 Subject: [PATCH 7/7] fix #333 --- nhentai/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nhentai/utils.py b/nhentai/utils.py index 434bcb0..a081d57 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -209,9 +209,10 @@ def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, move_t """Write images to a PDF file using img2pdf.""" if doujinshi_obj is not None: doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename) + filename = doujinshi_obj.filename.replace('/', '-') pdf_filename = os.path.join( os.path.join(doujinshi_dir, '..'), - f'{doujinshi_obj.filename}.pdf' + f'{filename}.pdf' ) else: pdf_filename = './doujinshi.pdf'