feat: 命令行模式支持传递多个作品链接

Closes #280
This commit is contained in:
Quan
2025-08-02 19:05:37 +08:00
parent 20cdd13eee
commit 9e6b819eb5
5 changed files with 30 additions and 14 deletions

View File

@@ -117,6 +117,7 @@
</ol> </ol>
<h1>🛠 命令行模式</h1> <h1>🛠 命令行模式</h1>
<p>项目支持命令行运行模式,若想要下载图文作品的部分图片,可以使用此模式设置需要下载的图片序号!</p> <p>项目支持命令行运行模式,若想要下载图文作品的部分图片,可以使用此模式设置需要下载的图片序号!</p>
<p><strong>注意:</strong>未设置 <code>--index</code> 参数时,支持传入多个作品链接,全部链接需要使用引号包围,链接之间使用空格分隔;已设置 <code>--index</code> 参数时,不支持传入多个作品链接,即使传入多个作品链接,程序仅处理首个作品链接!</p>
<p>可以使用命令行 <b>从浏览器读取 Cookie 并写入配置文件!</b></p> <p>可以使用命令行 <b>从浏览器读取 Cookie 并写入配置文件!</b></p>
<p>命令示例:<code>python .\main.py --browser_cookie Chrome --update_settings</code></p> <p>命令示例:<code>python .\main.py --browser_cookie Chrome --update_settings</code></p>
<p><code>bool</code> 类型参数支持使用 <code>true</code><code>false</code><code>1</code><code>0</code><code>yes</code><code>no</code><code>on</code><code>off</code>(不区分大小写)来设置。</p> <p><code>bool</code> 类型参数支持使用 <code>true</code><code>false</code><code>1</code><code>0</code><code>yes</code><code>no</code><code>on</code><code>off</code>(不区分大小写)来设置。</p>

View File

@@ -117,7 +117,8 @@
<li>Run <code>main.py</code> to use</li> <li>Run <code>main.py</code> to use</li>
</ol> </ol>
<h1>🛠 Command Line Mode</h1> <h1>🛠 Command Line Mode</h1>
<p>The project supports command line mode. If you want to download specific images from a text and image work, you can use this mode to set the image sequence number you want to download!</p> <p>The project supports command line mode. If you want to download specific images from a text and image works, you can use this mode to set the image sequence number you want to download!</p>
<p><strong>Note:</strong> When the <code>--index</code> parameter is not set, multiple works links can be passed in. All links must be enclosed in quotation marks and separated by spaces. When the <code>--index</code> parameter is set, multiple works links are not supported. Even if multiple links are passed in, the program will only process the first link!</p>
<p>You can use the command line to <b>read cookies from the browser and write to the configuration file!</b></p> <p>You can use the command line to <b>read cookies from the browser and write to the configuration file!</b></p>
<p>Command example: <code>python .\main.py --browser_cookie Chrome --update_settings</code></p> <p>Command example: <code>python .\main.py --browser_cookie Chrome --update_settings</code></p>
<p>The <code>bool</code> type parameters support setting with <code>true</code>, <code>false</code>, <code>1</code>, <code>0</code>, <code>yes</code>, <code>no</code>, <code>on</code> or <code>off</code> (case insensitive).</p> <p>The <code>bool</code> type parameters support setting with <code>true</code>, <code>false</code>, <code>1</code>, <code>0</code>, <code>yes</code>, <code>no</code>, <code>on</code> or <code>off</code> (case insensitive).</p>

View File

@@ -121,19 +121,19 @@ class CLI:
) )
options = ( options = (
("--url", "-u", "str", _("小红书作品链接")), ("--url", "-u", "str", _("小红书作品链接,多个链接使用空格分隔")),
( (
"--index", "--index",
"-i", "-i",
"str", "str",
fill( fill(
_( _(
'下载指定序号的图片文件,仅对图文作品生效;多个序号输入示例:"1 3 5 7"' '下载指定序号的图片文件,仅对图文/图集作品生效;多个序号输入示例:"1 3 5 7"'
), ),
width=55, width=55,
), ),
), ),
("--work_path", "-wp", "str", _("作品数据 / 文件保存根路径")), ("--work_path", "-wp", "str", _("作品数据/文件保存根路径")),
("--folder_name", "-fn", "str", _("作品文件储存文件夹名称")), ("--folder_name", "-fn", "str", _("作品文件储存文件夹名称")),
("--name_format", "-nf", "str", _("作品文件名称格式")), ("--name_format", "-nf", "str", _("作品文件名称格式")),
("--user_agent", "-ua", "str", "User-Agent"), ("--user_agent", "-ua", "str", "User-Agent"),

View File

@@ -253,7 +253,8 @@ class XHS:
url = await self.extract_links(url, log) url = await self.extract_links(url, log)
if not url: if not url:
logging(log, _("提取小红书作品链接失败"), WARNING) logging(log, _("提取小红书作品链接失败"), WARNING)
else: return
if index:
await self.__deal_extract( await self.__deal_extract(
url[0], url[0],
download, download,
@@ -262,6 +263,18 @@ class XHS:
bar, bar,
data, data,
) )
else:
[
await self.__deal_extract(
u,
download,
index,
log,
bar,
data,
)
for u in url
]
async def extract_links(self, url: str, log) -> list: async def extract_links(self, url: str, log) -> list:
urls = [] urls = []

View File

@@ -3,15 +3,16 @@
1. 修复作品类型判断失败时异常退出的问题 1. 修复作品类型判断失败时异常退出的问题
2. 修改服务器模式请求路径为 `/xhs/detail` 2. 修改服务器模式请求路径为 `/xhs/detail`
3. 修改服务器模式默认端口为 `5556` 3. 修改服务器模式默认端口为 `5556`
4. 新增 `folder_name` 参数检查 4. 命令行模式支持传递多个作品链接
5. 服务器模式新增 MCP 模式 5. 新增 `folder_name` 参数检查
6. 配置与文件归集到单文件夹 6. 服务器模式新增 MCP 模式
7. 优化配置文件参数容错机制 7. 配置文件归集到单文件夹
8. 优化提取链接的正则表达式 8. 优化配置文件参数容错机制
9. 修改服务器模式启动命令 9. 优化提取链接的正则表达式
10. 支持更多作品链接格式 10. 修改服务器模式启动命令
11. 支持音乐图集作品下载 11. 支持更多作品链接格式
12. 其他细节优化 12. 支持音乐图集作品下载
13. 其他细节优化
***** *****