mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-10-31 17:49:34 +01:00 
			
		
		
		
	Merge branch 'master' into dependabot/pip/urllib3-1.26.19
This commit is contained in:
		| @@ -1,3 +1,3 @@ | ||||
| __version__ = '0.5.5' | ||||
| __version__ = '0.5.6' | ||||
| __author__ = 'RicterZ' | ||||
| __email__ = 'ricterzheng@gmail.com' | ||||
|   | ||||
| @@ -3,6 +3,23 @@ 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) | ||||
| @@ -20,8 +37,13 @@ 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 = 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') | ||||
|  | ||||
| @@ -32,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 = { | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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'}) | ||||
|  | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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' | ||||
|   | ||||
| @@ -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); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| } | ||||
|   | ||||
							
								
								
									
										8
									
								
								poetry.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								poetry.lock
									
									
									
										generated
									
									
									
								
							| @@ -1,4 +1,4 @@ | ||||
| # This file is automatically @generated by Poetry 1.8.2 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]] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user