@@ -84,6 +84,7 @@ def transfer_to(self,
8484
8585class JmJsonResp (JmResp ):
8686
87+ @field_cache ()
8788 def json (self ) -> Dict :
8889 return self .resp .json ()
8990
@@ -128,9 +129,6 @@ class JmAlbumCommentResp(JmJsonResp):
128129 def is_success (self ) -> bool :
129130 return super ().is_success and self .json ()['err' ] is False
130131
131- def json (self ) -> Dict :
132- return self .resp .json ()
133-
134132
135133"""
136134
@@ -151,15 +149,6 @@ def get_photo_detail(self,
151149 ) -> JmPhotoDetail :
152150 raise NotImplementedError
153151
154- def of_api_url (self , api_path , domain ):
155- raise NotImplementedError
156-
157- def set_cache_dict (self , cache_dict : Optional [Dict ]):
158- raise NotImplementedError
159-
160- def get_cache_dict (self ) -> Optional [Dict ]:
161- raise NotImplementedError
162-
163152 def check_photo (self , photo : JmPhotoDetail ):
164153 """
165154 photo来源有两种:
@@ -381,12 +370,78 @@ def search_actor(self,
381370 return self .search (search_query , page , 4 , order_by , time )
382371
383372
373+ class JmCategoryClient :
374+ """
375+ 该接口可以看作是对全体禁漫本子的排行,热门排行的功能也派生于此
376+
377+ 月排行 = 分类【时间=月,排序=观看】
378+ 周排行 = 分类【时间=周,排序=观看】
379+ 日排行 = 分类【时间=周,排序=观看】
380+ """
381+
382+ def categories_filter (self ,
383+ page : int ,
384+ time : str ,
385+ category : str ,
386+ order_by : str ,
387+ ) -> JmCategoryPage :
388+ """
389+ 分类
390+
391+ :param page: 页码
392+ :param time: 时间范围,默认是全部时间
393+ :param category: 类别,默认是最新,即显示最新的禁漫本子
394+ :param order_by: 排序方式,默认是观看数
395+ """
396+ raise NotImplementedError
397+
398+ def month_ranking (self ,
399+ page : int ,
400+ category : str = JmMagicConstants .CATEGORY_ALL ,
401+ ):
402+ """
403+ 月排行 = 分类【时间=月,排序=观看】
404+ """
405+ return self .categories_filter (page ,
406+ JmMagicConstants .TIME_MONTH ,
407+ category ,
408+ JmMagicConstants .ORDER_BY_VIEW ,
409+ )
410+
411+ def week_ranking (self ,
412+ page : int ,
413+ category : str = JmMagicConstants .CATEGORY_ALL ,
414+ ):
415+ """
416+ 周排行 = 分类【时间=周,排序=观看】
417+ """
418+ return self .categories_filter (page ,
419+ JmMagicConstants .TIME_WEEK ,
420+ category ,
421+ JmMagicConstants .ORDER_BY_VIEW ,
422+ )
423+
424+ def day_ranking (self ,
425+ page : int ,
426+ category : str = JmMagicConstants .CATEGORY_ALL ,
427+ ):
428+ """
429+ 日排行 = 分类【时间=日,排序=观看】
430+ """
431+ return self .categories_filter (page ,
432+ JmMagicConstants .TIME_TODAY ,
433+ category ,
434+ JmMagicConstants .ORDER_BY_VIEW ,
435+ )
436+
437+
384438# noinspection PyAbstractClass
385439class JmcomicClient (
386440 JmImageClient ,
387441 JmDetailClient ,
388442 JmUserClient ,
389443 JmSearchAlbumClient ,
444+ JmCategoryClient ,
390445 Postman ,
391446):
392447 client_key : None
@@ -403,6 +458,15 @@ def set_domain_list(self, domain_list: List[str]):
403458 """
404459 raise NotImplementedError
405460
461+ def set_cache_dict (self , cache_dict : Optional [Dict ]):
462+ raise NotImplementedError
463+
464+ def get_cache_dict (self ) -> Optional [Dict ]:
465+ raise NotImplementedError
466+
467+ def of_api_url (self , api_path , domain ):
468+ raise NotImplementedError
469+
406470 def get_html_domain (self , postman = None ):
407471 return JmModuleConfig .get_html_domain (postman or self .get_root_postman ())
408472
@@ -487,3 +551,20 @@ def search_gen(self,
487551 }
488552
489553 yield from self .do_page_iter (params , page , self .search )
554+
555+ def categories_filter_gen (self ,
556+ page : int = 1 ,
557+ time : str = JmMagicConstants .TIME_ALL ,
558+ category : str = JmMagicConstants .CATEGORY_ALL ,
559+ order_by : str = JmMagicConstants .ORDER_BY_LATEST ,
560+ ) -> Generator [JmCategoryPage , Dict , None ]:
561+ """
562+ 见 search_gen
563+ """
564+ params = {
565+ 'time' : time ,
566+ 'category' : category ,
567+ 'order_by' : order_by ,
568+ }
569+
570+ yield from self .do_page_iter (params , page , self .categories_filter )
0 commit comments