From 4ed452378260cc2143e1577a9df24df9dcf9d1bf Mon Sep 17 00:00:00 2001
From: ricterz <ricterzheng@gmail.com>
Date: Fri, 20 Sep 2024 23:27:37 +0800
Subject: [PATCH] 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'})