Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.4.1: 实现获取收藏夹内容,优化类和函数的命名 #164

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $ jmcomic 422866
- **支持Plugin插件,可以方便地扩展功能,以及使用别人的插件**
- 目前内置支持的插件有:`登录插件` `硬件占用监控插件` `只下载新章插件` `压缩文件插件` `下载特定后缀图片插件` `发送QQ邮件插件` `日志主题过滤插件` `自动使用浏览器cookies插件`
- 支持自定义本子/章节/图片下载前后的回调函数
- 支持自定义debug/logging
- 支持自定义日志
- 支持自定义类:`Downloader(负责调度)` `Option(负责配置)` `Client(负责请求)` `实体类`等

## 进阶使用
Expand Down
3 changes: 2 additions & 1 deletion assets/docs/sources/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

| 版本范围 | 更新内容 |
|:--------:|:--------------------------------------:|
| v2.3.* | 实现移动端API的基础功能,统一HTML和API的实现 |
| v2.4.* | 项目实现基本稳定,进入维护期,按需增加功能。 |
| v2.3.* | 实现移动端API的基础功能,统一HTML和API的实现。 |
| v2.2.* | 新的插件体系,新的命令行调用,完善搜索功能。 |
| v2.1.* | 拆分Downloader抽象调度,优化可扩展性、代码复用性、模块级别自定义。 |
| v2.0.* | 重新设计合理的抽象层次,实现请求重试切换域名机制,新的option配置设计。 |
Expand Down
36 changes: 20 additions & 16 deletions assets/docs/sources/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,34 @@ Python API for JMComic(禁漫天堂)
- Bypasses Cloudflare anti-bot measures.
- Multiple usage ways:

- GitHub Actions: Requires only a GitHub account. (See
tutorial → [Tutorial - Download Album via GitHub Actions](./tutorial/1_github_actions.md))
- Command line: No need to write Python code, simple and easy to use. (See tutorial → [Tutorial - Download Album via Command Line](./tutorial/2_command_line.md))
- Python code: The most flexible and powerful way, requires some basic knowledge of Python programming.
- GitHub Actions: Requires only a GitHub account. (See
tutorial → [Tutorial - Download Album via GitHub Actions](./tutorial/1_github_actions.md))
- Command line: No need to write Python code, simple and easy to use. (See
tutorial → [Tutorial - Download Album via Command Line](./tutorial/2_command_line.md))
- Python code: The most flexible and powerful way, requires some basic knowledge of Python programming.

- Supports two client implementations: web-based and mobile-based. Switchable through configuration (mobile-based has
better IP compatibility, web-based has higher efficiency).
- Supports automatic request retry and domain switching mechanism.
- Multi-threaded downloading (can be fine-tuned to one thread per image, highly efficient).
- Highly configurable:

- Can be used without configuration, very convenient.
- Configuration can be generated from a configuration file, supports multiple file formats.
- Configuration options
include: `request domain`, `client implementation`, `number of chapters/images downloaded simultaneously`, `image format conversion`, `download path rules`, `request metadata (headers, cookies, proxies)`,
and more.
- Can be used without configuration, very convenient.
- Configuration can be generated from a configuration file, supports multiple file formats.
- Configuration options
include: `request domain`, `client implementation`, `number of chapters/images downloaded simultaneously`, `image format conversion`, `download path rules`, `request metadata (headers, cookies, proxies)`,
and more.

- Highly extensible:

- Supports Plugin plugins for easy functionality extension and use of other plugins.
- Currently built-in plugins: `login plugin`, `hardware usage monitoring plugin`, `only download new chapters plugin`, `zip compression plugin`, `image suffix filter plugin` `send qq email plugin` `debug logging topic filter plugin` `auto set browser cookies plugin`.
- Supports custom callback functions before and after downloading album/chapter/images.
- Supports custom debug logging.
- Supports custom core
classes: `Downloader (responsible for scheduling)`, `Option (responsible for configuration)`, `Client (responsible for requests)`, `entity classes`,
and more.
- Supports Plugin for easy functionality extension and use of other plugins.
- Currently built-in
plugins: `login plugin`, `hardware usage monitoring plugin`, `only download new chapters plugin`, `zip compression plugin`, `image suffix filter plugin` `send qq email plugin` `logging topic filter plugin` `auto set browser cookies plugin`.
- Supports custom callback functions before and after downloading album/chapter/images.
- Supports custom logging.
- Supports custom core
classes: `Downloader (responsible for scheduling)`, `Option (responsible for configuration)`, `Client (responsible for requests)`, `entity classes`,
and more.

## Install

Expand Down
26 changes: 13 additions & 13 deletions assets/docs/sources/tutorial/4_module_custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,27 @@ def custom_album_photo_image_detail_class():



## 自定义debug
## 自定义log

```python
def custom_jm_debug():
def custom_jm_log():
"""
该函数演示自定义debug
该函数演示自定义log
"""

# jmcomic模块在运行过程中会使用 jm_debug() 这个函数进行打印信息
# jm_debug() 这个函数 最后会调用 JmModuleConfig.debug_executor 函数
# 你可以写一个自己的函数,替换 JmModuleConfig.debug_executor,实现自定义debug
# jmcomic模块在运行过程中会使用 jm_log() 这个函数进行打印信息
# jm_log() 这个函数 最后会调用 JmModuleConfig.log_executor 函数
# 你可以写一个自己的函数,替换 JmModuleConfig.log_executor,实现自定义log

# 1. 自定义debug函数
def my_debug(topic: str, msg: str):
# 1. 自定义log函数
def my_log(topic: str, msg: str):
"""
这个debug函数的参数列表必须包含两个参数,topic和msg
@param topic: debug主题,例如 'album.before', 'req.error', 'plugin.error'
@param msg: 具体debug的信息
这个log函数的参数列表必须包含两个参数,topic和msg
@param topic: log主题,例如 'album.before', 'req.error', 'plugin.error'
@param msg: 具体log的信息
"""
pass

# 2. 让my_debug生效
JmModuleConfig.debug_executor = my_debug
# 2. 让my_log生效
JmModuleConfig.log_executor = my_log
Comment on lines +143 to +165
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code snippet demonstrates how to customize the logging function within the jmcomic module. The renaming from custom_jm_debug to custom_jm_log and my_debug to my_log is consistent with the overall shift from "debug" to "log" terminology. The comments and docstrings have been updated accordingly to reflect this change. This is a good practice as it maintains consistency and clarity in the codebase.

However, the custom log function my_log provided in the example is empty and does not contain any implementation. It is important to either provide a sample implementation or a comment indicating that users should add their own logging logic inside the function.

def my_log(topic: str, msg: str):
    """
    This is a custom log function. You should implement your logging logic here.
    For example, you could print the log messages to the console or write them to a file.
    @param topic: log topic, such as 'album.before', 'req.error', 'plugin.error'
    @param msg: the actual log message
    """
    # Example implementation:
    # print(f"{topic}: {msg}")
    pass

```
2 changes: 1 addition & 1 deletion assets/docs/sources/tutorial/8_pick_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ meta_data = {
# 'proxies': ProxyBuilder.clash_proxy()
}

disable_jm_debug()
disable_jm_log()


def get_domain_ls():
Expand Down
2 changes: 1 addition & 1 deletion src/jmcomic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 被依赖方 <--- 使用方
# config <--- entity <--- toolkit <--- client <--- option <--- downloader

__version__ = '2.3.17'
__version__ = '2.4.1'

from .api import *
from .jm_plugin import *
Expand Down
14 changes: 7 additions & 7 deletions src/jmcomic/cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def parse(text):

def main(self):
self.parse_arg()
from .api import jm_debug
jm_debug('command_line',
f'start downloading...\n'
f'- using option: [{self.option_path or "default"}]\n'
f'to be downloaded: \n'
f'- album: {self.album_id_list}\n'
f'- photo: {self.photo_id_list}')
from .api import jm_log
jm_log('command_line',
f'start downloading...\n'
f'- using option: [{self.option_path or "default"}]\n'
f'to be downloaded: \n'
f'- album: {self.album_id_list}\n'
f'- photo: {self.photo_id_list}')

from .api import create_option, JmOption
if self.option_path is not None:
Expand Down
Loading