@@ -398,6 +398,16 @@ def check_special_http_code(cls, resp):
398398class JmApiClient (AbstractJmClient ):
399399 client_key = 'api'
400400 API_SEARCH = '/search'
401+ API_ALBUM = '/album'
402+ API_CHAPTER = '/chapter'
403+
404+ def __init__ (self ,
405+ postman : Postman ,
406+ retry_times : int ,
407+ domain = None ,
408+ fallback_domain_list = None ,
409+ ):
410+ super ().__init__ (postman , retry_times , domain , fallback_domain_list )
401411
402412 def search (self ,
403413 search_query : str ,
@@ -431,6 +441,30 @@ def search(self,
431441
432442 return JmcomicSearchTool .parse_api_resp_to_page (data )
433443
444+ def get_album_detail (self , album_id ) -> JmAlbumDetail :
445+ return self .fetch_detail_entity (album_id ,
446+ JmModuleConfig .album_class (),
447+ )
448+
449+ def get_photo_detail (self , photo_id , fetch_album = True ) -> JmPhotoDetail :
450+ return self .fetch_detail_entity (photo_id ,
451+ JmModuleConfig .photo_class (),
452+ )
453+
454+ def fetch_detail_entity (self , apid , clazz , ** kwargs ):
455+ url = self .API_ALBUM if issubclass (clazz , JmAlbumDetail ) else self .API_CHAPTER
456+ resp = self .get (
457+ url ,
458+ params = {
459+ 'id' : JmcomicText .parse_to_album_id (apid ),
460+ ** kwargs ,
461+ }
462+ )
463+
464+ self .require_resp_success (resp )
465+
466+ return JmApiAdaptTool .parse_entity (resp .res_data , clazz )
467+
434468 def get (self , url , ** kwargs ) -> JmApiResp :
435469 # set headers
436470 headers , key_ts = self .headers_key_ts
@@ -454,6 +488,10 @@ def headers_key_ts(self):
454488 def debug_topic_request (self ):
455489 return 'api'
456490
491+ # noinspection PyMethodMayBeStatic
492+ def require_resp_success (self , resp : JmApiResp ):
493+ resp .require_success ()
494+
457495
458496JmModuleConfig .register_client (JmHtmlClient )
459497JmModuleConfig .register_client (JmApiClient )
0 commit comments