@@ -75,23 +75,32 @@ def before_retry(self, e, kwargs, retry_count, url):
7575
7676 def enable_cache (self , debug = False ):
7777 def wrap_func_cache (func_name , cache_dict_name ):
78+ import common
79+ if common .VERSION > '0.4.8' :
80+ cache = common .cache
81+ cache_dict = {}
82+ cache_hit_msg = (f'【缓存命中】{ cache_dict_name } ' + '→ [{}]' ) if debug is True else None
83+ cache_miss_msg = (f'【缓存缺失】{ cache_dict_name } ' + '← [{}]' ) if debug is True else None
84+ cache = cache (
85+ cache_dict = cache_dict ,
86+ cache_hit_msg = cache_hit_msg ,
87+ cache_miss_msg = cache_miss_msg ,
88+ )
89+ setattr (self , cache_dict_name , cache_dict )
90+ else :
91+ if sys .version_info < (3 , 9 ):
92+ raise NotImplementedError ('不支持启用JmcomicClient缓存。\n '
93+ '请更新python版本到3.9以上,'
94+ '或更新commonX: `pip install commonX --upgrade`' )
95+ import functools
96+ cache = functools .cache
97+
7898 if hasattr (self , cache_dict_name ):
7999 return
80100
81- cache_dict = {}
82- setattr (self , cache_dict_name , cache_dict )
83-
84101 # 重载本对象的方法
85102 func = getattr (self , func_name )
86-
87- cache_hit_msg = f'【缓存命中】{ cache_dict_name } ' + '→ [{}]' if debug is True else None
88- cache_miss_msg = f'【缓存缺失】{ cache_dict_name } ' + '← [{}]' if debug is True else None
89-
90- wrap_func = enable_cache (
91- cache_dict = cache_dict ,
92- cache_hit_msg = cache_hit_msg ,
93- cache_miss_msg = cache_miss_msg ,
94- )(func )
103+ wrap_func = cache (func )
95104
96105 setattr (self , func_name , wrap_func )
97106
@@ -149,18 +158,20 @@ def ensure_photo_can_use(self, photo_detail: JmPhotoDetail):
149158 new .from_album = photo_detail .from_album
150159 photo_detail .__dict__ .update (new .__dict__ )
151160
152- def search_album (self , search_query , main_tag = 0 ) :
161+ def search_album (self , search_query , main_tag = 0 , page = 1 ) -> JmSearchPage :
153162 params = {
154163 'main_tag' : main_tag ,
155164 'search_query' : search_query ,
165+ 'page' : page ,
156166 }
157167
158168 resp = self .get_jm_html ('/search/photos' , params = params , allow_redirects = True )
159169
160170 # 检查是否发生了重定向
161171 # 因为如果搜索的是禁漫车号,会直接跳转到本子详情页面
162172 if resp .redirect_count != 0 and '/album/' in resp .url :
163- return JmcomicText .analyse_jm_album_html (resp .text )
173+ album = JmcomicText .analyse_jm_album_html (resp .text )
174+ return JmSearchPage .wrap_single_album (album )
164175 else :
165176 return JmSearchSupport .analyse_jm_search_html (resp .text )
166177
@@ -284,7 +295,7 @@ def check_special_http_code(cls, resp):
284295class JmApiClient (AbstractJmClient ):
285296 API_SEARCH = '/search'
286297
287- def search_album (self , search_query : str , main_tag = 0 ) -> JmApiResp :
298+ def search_album (self , search_query , main_tag = 0 , page = 1 ) -> JmApiResp :
288299 """
289300 model_data: {
290301 "search_query": "MANA",
@@ -312,6 +323,8 @@ def search_album(self, search_query: str, main_tag=0) -> JmApiResp:
312323 self .API_SEARCH ,
313324 params = {
314325 'search_query' : search_query ,
326+ 'main_tag' : main_tag ,
327+ 'page' : page ,
315328 }
316329 )
317330
0 commit comments