Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,41 @@ b. 配置环境变量 `JM_OPTION_PATH` 为option文件路径(推荐)
jmcomic 123
```

### 4. 查看本子详情(jmv 命令)

> `jmv` 命令用于快速查看本子详情,无需下载。
>
> 支持从任意文本中提取数字作为车号,方便直接粘贴各种格式的车号。

示例:

```sh
# 直接输入车号
jmv 350234

# 从混合文本中提取数字(提取出 350234)
jmv 350谁还没看过234

# 指定option文件
jmv 350234 --option="D:/a.yml"
```

输出效果:
```
──────────────────────────────────────────────────
📖 标题: xxx
🆔 ID: JM350234
🔗 链接: https://18comic.vip/album/350234/
✍️ 作者: Author1, Author2
──────────────────────────────────────────────────
📅 发布日期: 2022-06-15
📅 更新日期: 2023-01-01
📄 总页数: 50
👀 观看: 2M
...
──────────────────────────────────────────────────
```



## 进阶使用
Expand Down
65 changes: 61 additions & 4 deletions assets/docs/sources/tutorial/2_command_line.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
# 命令行教程

## 1. 基本用法
## 1. jmcomic - 下载本子

### 1.1 基本用法

```
# 下载album 123 456,下载photo 333。彼此之间使用空格间隔
jmcomic 123 456 p333
```

## 2. 自定义option
### 1.2 自定义option

### 2.1. 通过命令行
#### 通过命令行参数
使用 --option 参数指定option配置文件路径

```sh
jmcomic 123 --option="D:/a.yml"
```

### 2.2. 使用环境变量
#### 使用环境变量
配置环境变量 `JM_OPTION_PATH` 为option配置文件路径

> 请自行google配置环境变量的方式,或使用powershell命令: `setx JM_OPTION_PATH "D:/a.yml"` 重启后生效

```sh
jmcomic 123
```

## 2. jmv - 查看本子详情

`jmv` 命令用于快速查看本子详情,无需下载。支持从任意文本中提取数字作为车号。

### 2.1 基本用法

```sh
# 直接输入车号
jmv 350234

# 从混合文本中提取数字(提取出 350234)
jmv 350谁还没看过234

# JM前缀也可以
jmv JM350234
```

### 2.2 自定义option

与 `jmcomic` 命令类似,支持 `--option` 参数和 `JM_OPTION_PATH` 环境变量:

```sh
jmv 350234 --option="D:/a.yml"
```

### 2.3 输出示例

```
🔍 正在查询 禁漫车号 - [350234] 的详情...

──────────────────────────────────────────────────
📖 标题: xxx
🆔 ID: JM350234
🔗 链接: https://18comic.vip/album/350234/
✍️ 作者: Author1, Author2
──────────────────────────────────────────────────
📅 发布日期: 2022-06-15
📅 更新日期: 2023-01-01
📄 总页数: 50
👀 观看: 2M
❤️ 点赞: 77K
💬 评论: 9801
──────────────────────────────────────────────────
🏷️ 标签: 标签1, 标签2, ...
🎭 人物: 角色A, 角色B, ...
📚 作品: 作品1, 作品2, ...
──────────────────────────────────────────────────
📑 章节 (2):
第1話 上 (id: 350234)
第2話 下 (id: 350235)
──────────────────────────────────────────────────
```

> **说明**: 当作者、标签、人物、作品超过10个时,会自动截断并显示总数(如 `...等25个`)。
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
],
entry_points={
'console_scripts': [
'jmcomic = jmcomic.cl:main'
'jmcomic = jmcomic.cl:main',
'jmv = jmcomic.cl:view_main',
]
}
)
124 changes: 122 additions & 2 deletions src/jmcomic/cl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""
command-line usage

for example, download album 123 456, photo 333:
1. jmcomic - download album/photo:

$ jmcomic 123 456 p333 --option="D:/option.yml"
$ jmcomic 123 456 p333 --option="D:/option.yml"

2. jmv - view album detail (extract digits from text as album id):

$ jmv 350234
$ jmv 350谁还没看过234
$ jmv abc123141 --option="D:/option.yml"

"""
import os.path
Expand Down Expand Up @@ -119,3 +124,118 @@ def run(self, option):

def main():
JmcomicUI().main()


class JmViewUI:

def __init__(self) -> None:
self.raw_text: str = ''

# noinspection PyAttributeOutsideInit
def parse_arg(self):
import argparse
parser = argparse.ArgumentParser(
prog='jmv',
description='JMComic Album Viewer - 从文本中提取数字作为album ID,查看本子详情',
)
parser.add_argument(
'text',
help='包含数字的禁漫车号,例如 "350谁还没看过234",会提取出 "350234" 作为 album ID',
)
parser.add_argument(
'--option',
help='option 文件路径,也可通过环境变量 JM_OPTION_PATH 指定',
type=str,
default=get_env('JM_OPTION_PATH', ''),
)

args = parser.parse_args()
self.raw_text = args.text

option_str = args.option
if len(option_str) == 0 or option_str == "''":
self.option_path = None
else:
self.option_path = os.path.abspath(option_str)

def extract_album_id(self) -> str:
import re
numbers = re.findall(r'\d+', self.raw_text)
if not numbers:
from .api import jm_log
jm_log('jmv', f'❌❌❌ 解析失败: 无法从 "{self.raw_text}" 中提取到任何数字 ❌❌❌')
exit(1)
album_id = ''.join(numbers)
return album_id

@staticmethod
def _truncate_list(items, limit=10):
if len(items) <= limit:
return ', '.join(items)
return ', '.join(items[:limit]) + f' ...等{len(items)}个'

def print_album_detail(self, album):
from jmcomic import JmcomicText

sep = '─' * 50

print(f'\n{sep}')
print(f' 📖 标题: {album.name}')
print(f' 🆔 ID: JM{album.album_id}')
print(f' 🔗 链接: {JmcomicText.format_album_url(album.album_id)}')
print(f' 🎨 封面: {JmcomicText.get_album_cover_url(album.album_id)}')
print(f' ✍️ 作者: {self._truncate_list(album.authors) if album.authors else "未知"}')
print(sep)

print(f' 📅 发布日期: {album.pub_date}')
print(f' 📅 更新日期: {album.update_date}')
print(f' 📄 总页数: {album.page_count}')
print(f' 👀 观看: {album.views}')
print(f' ❤️ 点赞: {album.likes}')
print(f' 💬 评论: {album.comment_count}')
print(sep)

if album.tags:
print(f' 🏷️ 标签: {self._truncate_list(album.tags)}')
if album.actors:
print(f' 🎭 人物: {self._truncate_list(album.actors)}')
if album.works:
print(f' 📚 作品: {self._truncate_list(album.works)}')

if album.description:
print(f' 📝 简介: {album.description}')

print(sep)
episode_count = len(album.episode_list)
print(f' 📑 章节 ({episode_count}):')
for pid, pindex, pname in album.episode_list:
pname = pname.strip()
print(f' 第{pindex}話 {pname} (id: {pid})')

print(f'{sep}\n')

def main(self):
self.parse_arg()
album_id = self.extract_album_id()

from .api import jm_log
jm_log('jmv', f'🔍 正在查询 禁漫车号 - [{album_id}] 的详情...')

from .api import create_option, JmOption
if self.option_path is not None:
option = create_option(self.option_path)
else:
option = JmOption.default()

client = option.new_jm_client()
try:
album = client.get_album_detail(album_id)
except Exception as e:
jm_log('jmv', f'❌❌❌ 获取失败: album {album_id} 详情请求出错, 原因: {e}', e)
exit(1)

self.print_album_detail(album)


def view_main():
JmViewUI().main()
1 change: 1 addition & 0 deletions src/jmcomic/jm_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def compare_versions(cls, v1: str, v2: str) -> int:
else:
return 0 # 相等


# 支持dsl: #{???} -> os.getenv(???)
JmcomicText.dsl_replacer.add_dsl_and_replacer(r'\$\{(.*?)\}', JmcomicText.match_os_env)

Expand Down
Loading
Loading