jmcomic 2.7.5__tar.gz → 2.7.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {jmcomic-2.7.5/src/jmcomic.egg-info → jmcomic-2.7.7}/PKG-INFO +10 -5
  2. {jmcomic-2.7.5 → jmcomic-2.7.7}/README.md +1 -4
  3. {jmcomic-2.7.5 → jmcomic-2.7.7}/pyproject.toml +11 -0
  4. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/__init__.py +1 -1
  5. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_async_client.py +103 -13
  6. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_client_impl.py +213 -18
  7. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_client_interface.py +143 -5
  8. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_config.py +7 -1
  9. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_entity.py +4 -0
  10. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_option.py +37 -1
  11. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_plugin.py +330 -20
  12. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_toolkit.py +33 -2
  13. {jmcomic-2.7.5 → jmcomic-2.7.7/src/jmcomic.egg-info}/PKG-INFO +10 -5
  14. jmcomic-2.7.7/src/jmcomic.egg-info/requires.txt +14 -0
  15. jmcomic-2.7.5/src/jmcomic.egg-info/requires.txt +0 -5
  16. {jmcomic-2.7.5 → jmcomic-2.7.7}/LICENSE +0 -0
  17. {jmcomic-2.7.5 → jmcomic-2.7.7}/setup.cfg +0 -0
  18. {jmcomic-2.7.5 → jmcomic-2.7.7}/setup.py +0 -0
  19. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/api.py +0 -0
  20. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/cli.py +0 -0
  21. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_async_downloader.py +0 -0
  22. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_downloader.py +0 -0
  23. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_exception.py +0 -0
  24. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_feature.py +0 -0
  25. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic/jm_task_context.py +0 -0
  26. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic.egg-info/SOURCES.txt +0 -0
  27. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic.egg-info/dependency_links.txt +0 -0
  28. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic.egg-info/entry_points.txt +0 -0
  29. {jmcomic-2.7.5 → jmcomic-2.7.7}/src/jmcomic.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jmcomic
3
- Version: 2.7.5
3
+ Version: 2.7.7
4
4
  Summary: Python API For JMComic (禁漫天堂)
5
5
  Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
6
6
  Author: hect0x7
@@ -50,6 +50,14 @@ Requires-Dist: curl-cffi
50
50
  Requires-Dist: pillow
51
51
  Requires-Dist: pycryptodome
52
52
  Requires-Dist: pyyaml
53
+ Provides-Extra: plugins
54
+ Requires-Dist: img2pdf; extra == "plugins"
55
+ Requires-Dist: pikepdf; extra == "plugins"
56
+ Requires-Dist: psutil; extra == "plugins"
57
+ Requires-Dist: py7zr; extra == "plugins"
58
+ Requires-Dist: pyzipper; extra == "plugins"
59
+ Requires-Dist: rich; extra == "plugins"
60
+ Requires-Dist: browser_cookie3; extra == "plugins"
53
61
  Dynamic: author
54
62
  Dynamic: home-page
55
63
  Dynamic: license-file
@@ -305,10 +313,7 @@ jmv 350234 -y
305
313
  - 支持自定义本子/章节/图片下载前后事件的回调函数
306
314
  - 支持自定义类:`Downloader(负责调度)` `Option(负责配置)` `Client(负责请求)` `实体类`等
307
315
  - 支持自定义日志、异常监听器
308
- - **支持Plugin插件,可以方便地扩展功能,以及使用别人的插件,目前核心内置插件有**:
309
- - `登录插件`、`只下载新章插件`、`导出收藏夹为csv文件插件`
310
- - `合并所有图片为pdf文件插件`、`合并所有图片为长图png插件`
311
- - `压缩文件插件`、`自动获取浏览器cookies插件`、`订阅更新插件`等
316
+ - **支持 Plugin 扩展,目前内置 21 个实用插件,包括**:`美观下载进度条`、`图片合并 PDF`、`一图流长图拼接`、`生成zip/7z压缩包`、`浏览器 Cookie 获取`、`订阅更新`、`收藏夹导出`、`封面下载`等。
312
317
 
313
318
  ## 使用小说明
314
319
 
@@ -248,10 +248,7 @@ jmv 350234 -y
248
248
  - 支持自定义本子/章节/图片下载前后事件的回调函数
249
249
  - 支持自定义类:`Downloader(负责调度)` `Option(负责配置)` `Client(负责请求)` `实体类`等
250
250
  - 支持自定义日志、异常监听器
251
- - **支持Plugin插件,可以方便地扩展功能,以及使用别人的插件,目前核心内置插件有**:
252
- - `登录插件`、`只下载新章插件`、`导出收藏夹为csv文件插件`
253
- - `合并所有图片为pdf文件插件`、`合并所有图片为长图png插件`
254
- - `压缩文件插件`、`自动获取浏览器cookies插件`、`订阅更新插件`等
251
+ - **支持 Plugin 扩展,目前内置 21 个实用插件,包括**:`美观下载进度条`、`图片合并 PDF`、`一图流长图拼接`、`生成zip/7z压缩包`、`浏览器 Cookie 获取`、`订阅更新`、`收藏夹导出`、`封面下载`等。
255
252
 
256
253
  ## 使用小说明
257
254
 
@@ -32,6 +32,17 @@ dependencies = [
32
32
  ]
33
33
  dynamic = ["version"]
34
34
 
35
+ [project.optional-dependencies]
36
+ plugins = [
37
+ "img2pdf",
38
+ "pikepdf",
39
+ "psutil",
40
+ "py7zr",
41
+ "pyzipper",
42
+ "rich",
43
+ "browser_cookie3",
44
+ ]
45
+
35
46
  [project.urls]
36
47
  Homepage = "https://github.com/hect0x7/JMComic-Crawler-Python"
37
48
  Documentation = "https://jmcomic.readthedocs.io"
@@ -2,7 +2,7 @@
2
2
  # 被依赖方 <--- 使用方
3
3
  # config <--- entity <--- toolkit <--- client <--- option <--- downloader
4
4
 
5
- __version__ = '2.7.5'
5
+ __version__ = '2.7.7'
6
6
 
7
7
  from .jm_task_context import *
8
8
  from .api import *
@@ -14,7 +14,7 @@ from urllib.parse import urlencode
14
14
  from curl_cffi.requests import AsyncSession
15
15
 
16
16
  from .jm_client_interface import (
17
- JmApiResp, JmImageResp, JmAlbumCommentResp,
17
+ JmApiResp, JmImageResp, JmAlbumCommentResp, JmDailyCheckinResp,
18
18
  AsyncJmcomicClient,
19
19
  )
20
20
  from .jm_entity import (
@@ -35,7 +35,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
35
35
  禁漫移动端异步 API 客户端。
36
36
 
37
37
  继承 AsyncJmcomicClient 接口,提供全面的异步网络通信能力,
38
- 涵盖图集、章节、搜索、登录与收藏夹等功能模块。
38
+ 涵盖本子、章节、搜索、登录与收藏夹等功能模块。
39
39
  通过异步会话管理与并发请求调度,显著提升网络 I/O 的处理性能与吞吐量。
40
40
  """
41
41
 
@@ -49,6 +49,8 @@ class AsyncJmApiClient(AsyncJmcomicClient):
49
49
  API_SCRAMBLE = '/chapter_view_template'
50
50
  API_FAVORITE = '/favorite'
51
51
  API_FORUM = '/forum'
52
+ API_DAILY = '/daily'
53
+ API_DAILY_CHK = '/daily_chk'
52
54
 
53
55
  # 缓存未命中标记
54
56
  _SENTINEL = object()
@@ -81,6 +83,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
81
83
  # 缓存默认关闭,由外部配置决定是否启用。
82
84
  self._cache: dict | None = None
83
85
  self._username: str | None = None
86
+ self._user_id: str | None = None
84
87
 
85
88
  # 接收并保存额外的会话级元数据参数
86
89
  self._meta_kwargs = kwargs
@@ -417,7 +420,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
417
420
  return result
418
421
 
419
422
  async def get_album_detail(self, album_id) -> JmAlbumDetail:
420
- """获取图集详情信息"""
423
+ """获取本子详情信息"""
421
424
  return await self._fetch_detail_entity(album_id, JmModuleConfig.album_class())
422
425
 
423
426
  async def get_photo_detail(self,
@@ -434,7 +437,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
434
437
  async def _fetch_photo_additional_field(self, photo: JmPhotoDetail,
435
438
  fetch_album: bool,
436
439
  fetch_scramble_id: bool):
437
- """并发获取图片从属的图集信息与 scramble_id 加解密参数。"""
440
+ """并发获取图片从属的本子信息与 scramble_id 加解密参数。"""
438
441
  tasks = {}
439
442
  if fetch_album:
440
443
  tasks['album'] = self.get_album_detail(photo.album_id)
@@ -592,7 +595,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
592
595
  sub_category: str | None = None,
593
596
  ) -> JmCategoryPage:
594
597
  """
595
- 获取指定分类下的图集列表数据。
598
+ 获取指定分类下的本子列表数据。
596
599
  注意:移动端不支持 sub_category。
597
600
  """
598
601
  o = f'{order_by}_{time}' if time != JmMagicConstants.TIME_ALL else order_by
@@ -618,22 +621,24 @@ class AsyncJmApiClient(AsyncJmcomicClient):
618
621
  'username': username,
619
622
  'password': password,
620
623
  })
624
+ res_data = resp.res_data
621
625
  cookies = dict(resp.resp.cookies)
622
- cookies.update({'AVS': resp.res_data['s']})
626
+ cookies.update({'AVS': res_data['s']})
623
627
  # noinspection PyUnresolvedReferences,PyTypeChecker
624
628
  self._session.cookies.update(cookies)
625
629
  # 同步到 Option 配置,确保 cookies 持久化
626
630
  self.option.update_cookies(cookies)
627
631
  self._username = username
632
+ self._user_id = str(res_data['uid']) if 'uid' in res_data else None
628
633
  return resp
629
634
 
630
635
  async def favorite_folder(self,
631
636
  page=1,
632
- order_by=JmMagicConstants.ORDER_BY_LATEST,
637
+ order_by=JmMagicConstants.ORDER_FF_FAVORITE_TIME,
633
638
  folder_id='0',
634
639
  username='',
635
640
  ) -> JmFavoritePage:
636
- """获取收藏夹内特定目录的图集数据分页。"""
641
+ """获取收藏夹内特定目录的本子数据分页。"""
637
642
  resp = await self.req_api(
638
643
  self.API_FAVORITE,
639
644
  params={
@@ -676,18 +681,103 @@ class AsyncJmApiClient(AsyncJmcomicClient):
676
681
  )
677
682
  return JmPageTool.parse_api_to_album_comment_page(resp.model_data, page)
678
683
 
679
- async def add_favorite_album(self, album_id, folder_id='0'):
684
+ async def toggle_favorite_album(self,
685
+ album_id,
686
+ folder_id='0',
687
+ expected_type: Optional[str] = None,
688
+ ):
680
689
  """
681
- 将指定图集加入用户的收藏夹。
682
- 注意:移动端没有提供 folder_id 参数。
690
+ 切换本子的收藏状态(移动端接口底层为 Toggle 逻辑)。
691
+ :param album_id: 本子ID
692
+ :param folder_id: 移动端没有提供 folder_id 参数,保留参数兼容
693
+ :param expected_type: 期望的操作类型 ('add' | 'remove'),如果不匹配则抛异常
683
694
  """
684
- # 服务端实现上使用带 body 的 GET 请求方式
685
- resp = await self.req_api('/favorite', data={'aid': album_id})
695
+ resp = await self.req_api(
696
+ self.API_FAVORITE,
697
+ get=False,
698
+ data={'aid': album_id},
699
+ )
686
700
  data = resp.model_data
687
701
  if data.status != 'ok':
688
702
  ExceptionTool.raises_resp(data.msg, resp)
703
+
704
+ if expected_type is not None:
705
+ actual_type = data.type
706
+ if actual_type != expected_type:
707
+ ExceptionTool.raises_resp(
708
+ f'收藏操作不符合预期,期望 [{expected_type}],实际为 [{actual_type}]: {data.msg}',
709
+ resp
710
+ )
711
+
689
712
  return resp
690
713
 
714
+ async def add_favorite_album(self, album_id, folder_id='0'):
715
+ """
716
+ 将指定本子加入用户的收藏夹。
717
+ 如果当前已收藏,将抛出异常以保证收藏语义明确。
718
+ """
719
+ return await self.toggle_favorite_album(album_id, folder_id, expected_type='add')
720
+
721
+ async def delete_favorite_album(self, album_id, folder_id='0'):
722
+ """
723
+ 将指定本子移出用户的收藏夹。
724
+ 如果当前未收藏,将抛出异常以保证取消收藏语义明确。
725
+ """
726
+ return await self.toggle_favorite_album(album_id, folder_id, expected_type='remove')
727
+
728
+ async def get_daily(self, user_id: str | None = None) -> JmApiResp:
729
+ """
730
+ 获取每日签到信息与日历打卡记录
731
+ :param user_id: 用户ID,默认读取当前登录用户的uid
732
+ """
733
+ if user_id is None:
734
+ ExceptionTool.require_true(self._user_id is not None, '签到需要传入 user_id 参数,或者先调用 login 方法')
735
+ user_id = self._user_id
736
+
737
+ return await self.req_api(self.API_DAILY, params={'user_id': user_id})
738
+
739
+ async def daily_checkin(self, daily_id: str | None = None, user_id: str | None = None) -> JmDailyCheckinResp:
740
+ """
741
+ 执行每日打卡签到(异步)。
742
+ 返回 JmDailyCheckinResp 对象:
743
+ - code=0 (或 status=0): 签到成功
744
+ - code=1 (或 status=1): 重复签到(今日已完成打卡)
745
+ - 其余失败情况直接抛出异常
746
+ :param daily_id: 打卡任务ID,未提供时会自动请求 get_daily 获取
747
+ :param user_id: 用户ID,默认读取当前登录用户的uid
748
+ :return: JmDailyCheckinResp
749
+ """
750
+ if user_id is None:
751
+ ExceptionTool.require_true(self._user_id is not None, '签到需要传入 user_id 参数,或者先调用 login 方法')
752
+ user_id = self._user_id
753
+
754
+ if daily_id is None:
755
+ daily_resp = await self.get_daily(user_id)
756
+ if 'daily_id' not in daily_resp.res_data:
757
+ ExceptionTool.raises_resp('签到失败:签到信息缺少 daily_id', daily_resp)
758
+ daily_id = daily_resp.res_data['daily_id']
759
+
760
+ resp: JmApiResp = await self.req_api(
761
+ self.API_DAILY_CHK,
762
+ get=False,
763
+ data={
764
+ 'user_id': user_id,
765
+ 'daily_id': daily_id,
766
+ },
767
+ )
768
+
769
+ res_data = resp.res_data
770
+ msg = str(res_data.get('msg', ''))
771
+
772
+ if any(kw in msg for kw in ('今天已經簽到過了', '已簽到', '簽到過', '已完成', '已签到')):
773
+ code = JmDailyCheckinResp.CODE_ALREADY_CHECKED_IN
774
+ elif 'Jcoin' in msg or 'EXP' in msg or res_data.get('status') == 'ok' or '成功' in msg:
775
+ code = JmDailyCheckinResp.CODE_SUCCESS
776
+ else:
777
+ ExceptionTool.raises_resp(f'签到失败:{msg or res_data}', resp)
778
+
779
+ return JmDailyCheckinResp(resp.resp, code, msg, res_data)
780
+
691
781
  async def album_comment(self,
692
782
  video_id,
693
783
  comment,
@@ -2,7 +2,6 @@ from copy import deepcopy
2
2
  from threading import Lock
3
3
 
4
4
  from .jm_task_context import bind_jm_task_context
5
-
6
5
  from .jm_client_interface import *
7
6
 
8
7
 
@@ -33,6 +32,7 @@ class AbstractJmClient(
33
32
  self.domain_retry_strategy = domain_retry_strategy
34
33
  self.CLIENT_CACHE = None
35
34
  self._username = None # help for favorite_folder method
35
+ self._user_id = None # help for check_in / get_daily method
36
36
  if domain_retry_strategy:
37
37
  domain_retry_strategy(self)
38
38
  self.enable_cache()
@@ -267,14 +267,12 @@ class JmHtmlClient(AbstractJmClient):
267
267
  album_id,
268
268
  folder_id='0',
269
269
  ):
270
- data = {
271
- 'album_id': album_id,
272
- 'fid': folder_id,
273
- }
274
-
275
- resp = self.get_jm_html(
270
+ resp = self.post(
276
271
  '/ajax/favorite_album',
277
- data=data,
272
+ data={
273
+ 'album_id': str(album_id),
274
+ 'fid': str(folder_id),
275
+ },
278
276
  )
279
277
 
280
278
  res = resp.json()
@@ -291,6 +289,30 @@ class JmHtmlClient(AbstractJmClient):
291
289
 
292
290
  return resp
293
291
 
292
+ def delete_favorite_album(self,
293
+ album_id,
294
+ folder_id='0',
295
+ ):
296
+ resp = self.post(
297
+ '/ajax/delete_favorite_album',
298
+ data={
299
+ 'album_id': str(album_id),
300
+ },
301
+ )
302
+
303
+ res = resp.json()
304
+
305
+ if res['status'] != 1:
306
+ msg = parse_unicode_escape_text(res['msg'])
307
+ error_msg = PatternTool.match_or_default(msg, JmcomicText.pattern_ajax_favorite_msg, msg)
308
+
309
+ self.raise_request_error(
310
+ resp,
311
+ error_msg
312
+ )
313
+
314
+ return resp
315
+
294
316
  def get_album_detail(self, album_id) -> JmAlbumDetail:
295
317
  return self.fetch_detail_entity(album_id, 'album')
296
318
 
@@ -425,7 +447,12 @@ class JmHtmlClient(AbstractJmClient):
425
447
  )
426
448
 
427
449
  if resp.status_code != 200:
428
- ExceptionTool.raises_resp(f'登录失败,状态码为{resp.status_code}', resp)
450
+ self.raise_request_error(resp, f'登录失败,状态码为{resp.status_code}')
451
+
452
+ res = resp.json()
453
+ if res.get('status') != 1:
454
+ errors = res.get('errors') or [res.get('msg', '登录失败')]
455
+ self.raise_request_error(resp, f'登录失败:{errors[0]}')
429
456
 
430
457
  orig_cookies = self.get_meta_data('cookies') or {}
431
458
  new_cookies = dict(resp.cookies)
@@ -440,7 +467,7 @@ class JmHtmlClient(AbstractJmClient):
440
467
 
441
468
  def favorite_folder(self,
442
469
  page=1,
443
- order_by=JmMagicConstants.ORDER_BY_LATEST,
470
+ order_by=JmMagicConstants.ORDER_FF_FAVORITE_TIME,
444
471
  folder_id='0',
445
472
  username='',
446
473
  ) -> JmFavoritePage:
@@ -467,6 +494,73 @@ class JmHtmlClient(AbstractJmClient):
467
494
  # 解析cookies,可能需要用到 phpserialize,比较麻烦,暂不实现
468
495
  pass
469
496
 
497
+ def get_or_fetch_daily_id(self, daily_id: str | None = None) -> str:
498
+ if daily_id is None:
499
+ resp_home = self.get_jm_html('/')
500
+ daily_id = JmcomicText.parse_daily_id(resp_home.text)
501
+ ExceptionTool.require_true(bool(daily_id), '未能从首页获取到 daily_id,请手动传入 daily_id 参数')
502
+ return str(daily_id)
503
+
504
+ def get_daily(self,
505
+ user_id: str | None = None,
506
+ daily_id: str | None = None
507
+ ) -> JmJsonResp:
508
+ """
509
+ 网页端获取每日签到信息与日历打卡记录。
510
+ 返回值格式参考 JmUserClient.get_daily 文档。
511
+ :param user_id: 兼容参数,网页端不需要
512
+ :param daily_id: 如果外界提前获取了,可直接传递参数,使得本方法内部少一次网络请求查询。
513
+ :return: JmJsonResp
514
+ """
515
+ daily_id = self.get_or_fetch_daily_id(daily_id)
516
+ resp = self.get(
517
+ '/ajax/user_daily_event',
518
+ params={'daily_id': daily_id},
519
+ )
520
+ ret = JmJsonResp(resp)
521
+ ret.require_success()
522
+ return ret
523
+
524
+ def daily_checkin(self,
525
+ daily_id: str | None = None,
526
+ user_id: str | None = None,
527
+ old_step: int = 1
528
+ ) -> JmDailyCheckinResp:
529
+ """
530
+ 网页端每日签到。
531
+ 返回 JmDailyCheckinResp 对象:
532
+ - code=0 (或 status=0): 签到成功
533
+ - code=1 (或 status=1): 重复签到(今日已完成打卡)
534
+ - 其余失败情况直接抛出异常
535
+ :param daily_id: 打卡任务ID,未提供时会自动从首页提取
536
+ :param user_id: 兼容参数,网页端不需要
537
+ :param old_step: 连续签到天数阶段,默认为 1
538
+ :return: JmDailyCheckinResp
539
+ """
540
+ daily_id = self.get_or_fetch_daily_id(daily_id)
541
+ resp = self.post(
542
+ '/ajax/user_daily_sign',
543
+ data={
544
+ 'daily_id': daily_id,
545
+ 'oldStep': str(old_step),
546
+ },
547
+ )
548
+ if resp.status_code != 200:
549
+ self.raise_request_error(resp, f'签到请求失败,HTTP状态码: {resp.status_code}')
550
+
551
+ res = resp.json()
552
+ status = res.get('status')
553
+ msg = str(res.get('msg', ''))
554
+
555
+ if status == 1:
556
+ code = JmDailyCheckinResp.CODE_SUCCESS
557
+ elif status == 0 and any(kw in msg for kw in ('已完成打卡', '今天已经签到', '今日已完成', '已签到', '已打卡')):
558
+ code = JmDailyCheckinResp.CODE_ALREADY_CHECKED_IN
559
+ else:
560
+ self.raise_request_error(resp, f'签到失败:{msg or status}')
561
+
562
+ return JmDailyCheckinResp(resp, code, msg, res)
563
+
470
564
  def get_jm_html(self, url, require_200=True, **kwargs):
471
565
  """
472
566
  请求禁漫网页的入口
@@ -673,6 +767,8 @@ class JmApiClient(AbstractJmClient):
673
767
  API_SCRAMBLE = '/chapter_view_template'
674
768
  API_FAVORITE = '/favorite'
675
769
  API_FORUM = '/forum'
770
+ API_DAILY = '/daily'
771
+ API_DAILY_CHK = '/daily_chk'
676
772
 
677
773
  def search(self,
678
774
  search_query: str,
@@ -896,15 +992,18 @@ class JmApiClient(AbstractJmClient):
896
992
  'password': password,
897
993
  })
898
994
 
995
+ res_data = resp.res_data
899
996
  cookies = dict(resp.resp.cookies)
900
- cookies.update({'AVS': resp.res_data['s']})
997
+ cookies.update({'AVS': res_data['s']})
901
998
  self['cookies'] = cookies
999
+ self._username = username
1000
+ self._user_id = str(res_data['uid']) if 'uid' in res_data else None
902
1001
 
903
1002
  return resp
904
1003
 
905
1004
  def favorite_folder(self,
906
1005
  page=1,
907
- order_by=JmMagicConstants.ORDER_BY_LATEST,
1006
+ order_by=JmMagicConstants.ORDER_FF_FAVORITE_TIME,
908
1007
  folder_id='0',
909
1008
  username='',
910
1009
  ) -> JmFavoritePage:
@@ -959,15 +1058,20 @@ class JmApiClient(AbstractJmClient):
959
1058
  )
960
1059
  return JmPageTool.parse_api_to_album_comment_page(resp.model_data, page)
961
1060
 
962
- def add_favorite_album(self,
963
- album_id,
964
- folder_id='0',
965
- ):
1061
+ def toggle_favorite_album(self,
1062
+ album_id,
1063
+ folder_id='0',
1064
+ expected_type: Optional[str] = None,
1065
+ ):
966
1066
  """
967
- 移动端没有提供folder_id参数
1067
+ 切换本子的收藏状态(移动端接口底层为 Toggle 逻辑)。
1068
+ :param album_id: 本子ID
1069
+ :param folder_id: 移动端没有提供 folder_id 参数,保留参数兼容
1070
+ :param expected_type: 期望的操作类型 ('add' | 'remove'),如果不匹配则抛异常
968
1071
  """
969
1072
  resp = self.req_api(
970
- '/favorite',
1073
+ self.API_FAVORITE,
1074
+ get=False,
971
1075
  data={
972
1076
  'aid': album_id,
973
1077
  },
@@ -975,8 +1079,96 @@ class JmApiClient(AbstractJmClient):
975
1079
 
976
1080
  self.require_resp_status_ok(resp)
977
1081
 
1082
+ if expected_type is not None:
1083
+ actual_type = resp.model_data.type
1084
+ if actual_type != expected_type:
1085
+ ExceptionTool.raises_resp(
1086
+ f'收藏操作不符合预期,期望 [{expected_type}],实际为 [{actual_type}]: {resp.model_data.msg}',
1087
+ resp
1088
+ )
1089
+
978
1090
  return resp
979
1091
 
1092
+ def add_favorite_album(self,
1093
+ album_id,
1094
+ folder_id='0',
1095
+ ):
1096
+ """
1097
+ 把本子加入收藏夹。
1098
+ 如果当前已收藏,将抛出异常以保证收藏语义明确。
1099
+ """
1100
+ return self.toggle_favorite_album(album_id, folder_id, expected_type='add')
1101
+
1102
+ def delete_favorite_album(self,
1103
+ album_id,
1104
+ folder_id='0',
1105
+ ):
1106
+ """
1107
+ 从收藏夹移除本子。
1108
+ 如果当前未收藏,将抛出异常以保证取消收藏语义明确。
1109
+ """
1110
+ return self.toggle_favorite_album(album_id, folder_id, expected_type='remove')
1111
+
1112
+ def get_daily(self,
1113
+ user_id: str | None = None,
1114
+ ) -> JmApiResp:
1115
+ """
1116
+ 移动端获取每日签到信息与日历打卡记录。
1117
+ 返回值格式参考 JmUserClient.get_daily 文档。
1118
+ :param user_id: 用户ID,默认读取当前登录用户的uid
1119
+ :return: JmApiResp
1120
+ """
1121
+ if user_id is None:
1122
+ ExceptionTool.require_true(self._user_id is not None, '签到需要传入 user_id 参数,或者先调用 login 方法')
1123
+ user_id = self._user_id
1124
+
1125
+ return self.req_api(self.API_DAILY, params={'user_id': user_id})
1126
+
1127
+ def daily_checkin(self,
1128
+ daily_id: str | None = None,
1129
+ user_id: str | None = None,
1130
+ ) -> JmDailyCheckinResp:
1131
+ """
1132
+ 执行每日打卡签到。
1133
+ 返回 JmDailyCheckinResp 对象:
1134
+ - code=0 (或 status=0): 签到成功
1135
+ - code=1 (或 status=1): 重复签到(今日已完成打卡)
1136
+ - 其余失败情况直接抛出异常
1137
+ :param daily_id: 打卡任务ID,未提供时会自动请求 get_daily 获取
1138
+ :param user_id: 用户ID,默认读取当前登录用户的uid
1139
+ :return: JmDailyCheckinResp
1140
+ """
1141
+ if user_id is None:
1142
+ ExceptionTool.require_true(self._user_id is not None, '签到需要传入 user_id 参数,或者先调用 login 方法')
1143
+ user_id = self._user_id
1144
+
1145
+ if daily_id is None:
1146
+ daily_resp = self.get_daily(user_id)
1147
+ if 'daily_id' not in daily_resp.res_data:
1148
+ ExceptionTool.raises_resp('签到失败:签到信息缺少 daily_id', daily_resp)
1149
+ daily_id = daily_resp.res_data['daily_id']
1150
+
1151
+ resp: JmApiResp = self.req_api(
1152
+ self.API_DAILY_CHK,
1153
+ get=False,
1154
+ data={
1155
+ 'user_id': user_id,
1156
+ 'daily_id': daily_id,
1157
+ },
1158
+ )
1159
+
1160
+ res_data = resp.res_data
1161
+ msg = str(res_data.get('msg', ''))
1162
+
1163
+ if any(kw in msg for kw in ('今天已經簽到過了', '已簽到', '簽到過', '已完成', '已签到')):
1164
+ code = JmDailyCheckinResp.CODE_ALREADY_CHECKED_IN
1165
+ elif 'Jcoin' in msg or 'EXP' in msg or res_data.get('status') == 'ok' or '成功' in msg:
1166
+ code = JmDailyCheckinResp.CODE_SUCCESS
1167
+ else:
1168
+ ExceptionTool.raises_resp(f'签到失败:{msg or res_data}', resp)
1169
+
1170
+ return JmDailyCheckinResp(resp.resp, code, msg, res_data)
1171
+
980
1172
  # noinspection PyMethodMayBeStatic
981
1173
  def require_resp_status_ok(self, resp: JmApiResp):
982
1174
  """
@@ -1321,3 +1513,6 @@ class PhotoConcurrentFetcherProxy(JmcomicClient):
1321
1513
  photo.scramble_id = scramble_id
1322
1514
 
1323
1515
  return photo
1516
+
1517
+ def __getattr__(self, item):
1518
+ return getattr(self.client, item)