750f981c7e
资源中心——从多渠道获取资源链接,转存到夸克网盘并整理归档。 - sources/tencent-doc: 腾讯文档读取 - sources/search: 网盘搜索 - storage/quark: 夸克网盘操作 - ref/: 来源 skill 参考归档 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
149 lines
4.3 KiB
Markdown
149 lines
4.3 KiB
Markdown
# 工作流:腾讯文档 → 夸克网盘
|
||
|
||
从腾讯文档(如 Tacit0924 的资源分享文档)中搜索关键词找到分享链接,转存到夸克网盘。
|
||
|
||
## 步骤
|
||
|
||
### Step 1: 读取腾讯文档内容
|
||
|
||
从 URL 中提取 `file_id`(`/doc/<file_id>` 部分):
|
||
|
||
```bash
|
||
# 获取文档结构
|
||
mcporter call tencent-docs doc.resolve_document_structure file_id=<FILE_ID> > doc_raw.json
|
||
|
||
# 提取文本内容到本地文件
|
||
python -X utf8 -c "
|
||
import json
|
||
with open('doc_raw.json','r',encoding='utf-8') as f:
|
||
data=json.load(f)
|
||
texts=[]
|
||
for n in data.get('nodes',[]):
|
||
p=n.get('text_preview','')
|
||
hl=n.get('heading_level',0)
|
||
if p:
|
||
texts.append(('#'*hl+' '+p) if hl>0 else p)
|
||
with open('doc_content.txt','w',encoding='utf-8') as f:
|
||
f.write('\n'.join(texts))
|
||
print(f'{len(texts)} paragraphs extracted')
|
||
"
|
||
|
||
# 清理中间文件(可选)
|
||
rm doc_raw.json
|
||
```
|
||
|
||
> **注意**:文档是 tencentdoc 类型用以上方法,smartcanvas 类型用 `smartcanvas.read`。
|
||
|
||
### Step 2: 搜索关键词匹配链接
|
||
|
||
```bash
|
||
# 在提取的文本中搜索关键词,找到分享链接
|
||
grep -n "关键词" doc_content.txt
|
||
# 或
|
||
python -X utf8 -c "
|
||
with open('doc_content.txt','r',encoding='utf-8') as f:
|
||
lines=f.readlines()
|
||
kw='关键词'
|
||
for i,line in enumerate(lines):
|
||
if kw in line:
|
||
# 打印上下文:前后3行
|
||
start=max(0,i-3)
|
||
end=min(len(lines),i+4)
|
||
print(f'--- Line {i+1} ---')
|
||
for j in range(start,end):
|
||
marker='>' if j==i else ' '
|
||
print(f'{marker} {lines[j].strip()[:150]}')
|
||
"
|
||
```
|
||
|
||
夸克链接格式:`https://pan.quark.cn/s/<id>`
|
||
|
||
### Step 3: 查看分享链接内容
|
||
|
||
```bash
|
||
mcporter call 'netdisk.view(share_link: "https://pan.quark.cn/s/xxx")'
|
||
```
|
||
|
||
可选:用 `file_pattern` 过滤特定格式:
|
||
```bash
|
||
mcporter call 'netdisk.view(share_link: "https://pan.quark.cn/s/xxx", file_pattern: "*.mp4")'
|
||
```
|
||
|
||
### Step 4: 确定/创建目标目录
|
||
|
||
先看看夸克网盘上是否已有该资源的目录:
|
||
|
||
```bash
|
||
mcporter call 'netdisk.list(cloud: "quark", path: "/动漫")'
|
||
```
|
||
|
||
如果已存在则复用,否则创建新目录:
|
||
|
||
```bash
|
||
# 创建目录需要父文件夹 FID,先获取
|
||
# 方式1:从 netdisk.list 输出中提取 (ID: xxx)
|
||
# 方式2:直接调用 API
|
||
|
||
# 创建子目录
|
||
COOKIE="你的夸克Cookie"
|
||
curl -s -X POST "https://drive-h.quark.cn/1/clouddrive/file?pr=ucpro&fr=pc" \
|
||
-H "cookie: $COOKIE" \
|
||
-H "content-type: application/json" \
|
||
-H "origin: https://pan.quark.cn" \
|
||
-H "referer: https://pan.quark.cn/" \
|
||
-d '{"pdir_fid":"<父FID>","file_name":"<新目录名>","file_type":0,"dir_init":true}'
|
||
```
|
||
|
||
> API 详情见 `references/quark-api.md`
|
||
|
||
### Step 5: 转存
|
||
|
||
```bash
|
||
mcporter call 'netdisk.transfer(share_link: "https://pan.quark.cn/s/xxx", source_pattern: "/*", target_path: "/目标路径")'
|
||
```
|
||
|
||
> **注意**:`source_pattern` 的 glob 跨所有文件夹匹配,转存后需要验证并清理。
|
||
|
||
### Step 6: 验证并清理
|
||
|
||
```bash
|
||
# 列出目标目录
|
||
mcporter call 'netdisk.list(cloud: "quark", path: "/目标路径")'
|
||
|
||
# 如果有混入的不相关文件,用 Quark API 删除
|
||
curl -s -X POST "https://drive-h.quark.cn/1/clouddrive/file/delete?pr=ucpro&fr=pc" \
|
||
-H "cookie: $COOKIE" \
|
||
-H "content-type: application/json" \
|
||
-H "origin: https://pan.quark.cn" \
|
||
-H "referer: https://pan.quark.cn/" \
|
||
-d '{"action_type":2,"filelist":["<杂文件FID1>","<杂文件FID2>"]}'
|
||
```
|
||
|
||
### Step 7: 输出结果摘要
|
||
|
||
列出最终目录结构,让用户确认。
|
||
|
||
## 完整示例(遮天动画版)
|
||
|
||
参见 `resource-pipeline/SKILL.md` 的实际对话记录,关键节点:
|
||
|
||
```
|
||
输入: 腾讯文档 URL DR2xUcFdrSVhJTkZu + 关键词 "遮天"
|
||
|
||
1. doc.resolve_document_structure → 提取全文(853231字/28449段)
|
||
2. grep "遮天" → 找到链接 https://pan.quark.cn/s/0762b0d500f3
|
||
3. netdisk.view → 205文件/191GB,含1-162集4K
|
||
4. 发现已有目录 /动漫/国漫2024/遮.天(2023)
|
||
→ 创建子目录 151-162
|
||
5. netdisk.transfer × 2 → 转存151-162集
|
||
6. Quark API delete → 清理混入的杂文件(Z 4K 15/16等)
|
||
结果: 遮.天(2023)/151-162/ 含11集新内容
|
||
```
|
||
|
||
## 注意事项
|
||
|
||
- **get_content 大文档超时**:改用 `doc.resolve_document_structure`
|
||
- **目录必须存在**:转存前先用 API 创建不存在的目录
|
||
- **glob 跨文件夹**:验证后再清理杂文件
|
||
- **Windows 编码**:用 `python -X utf8` 处理 emoji
|