---
name: freshrss-subscription-management
description: FreshRSS 订阅源管理 - 批量添加、删除、清理订阅源和分类的完整流程
category: mlops
---

# FreshRSS 订阅源管理技能

用于批量管理 FreshRSS 订阅源，包括添加新订阅、删除问题源、清理空分类、去重等操作。

## 适用场景

- 批量添加新的 RSS 订阅源
- 清理无法访问的订阅源
- 删除空分类
- 删除重复订阅源
- 优化订阅结构

## 前置条件

1. **FreshRSS 访问信息**
   - URL: `https://rss.your-domain.com`
   - 用户名/密码
   - (可选) Fever API Key

2. **认证方式优先级**
   - 方式 1: Cookie 认证 (最可靠)
   - 方式 2: Fever API (需确认 endpoint)
   - 方式 3: Google Reader API (需正确认证)

## 操作流程

### 1. 登录获取 Cookie

```bash
FRESHRSS_URL="https://rss.liupeizhi.top"
FRESHRSS_USER="admin"
FRESHRSS_PASSWORD="YourPassword"

# 登录并保存 cookie
curl -s -c /tmp/fr_cookies.txt -b /tmp/fr_cookies.txt \
  -L "$FRESHRSS_URL/i/?c=auth&a=login" \
  -d "username=$FRESHRSS_USER&password=$FRESHRSS_PASSWORD&rememberMe=1" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

### 2. 删除空分类

```bash
# 获取分类列表 (在订阅管理页面查看)
# 分类 ID 可在页面源码或网络请求中找到

# 删除空分类 (POST 请求)
curl -s -b /tmp/fr_cookies.txt \
  -X POST "$FRESHRSS_URL/i/?c=category&a=delete&id=分类 ID" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

**常见空分类示例:**
- B 站、东南亚、中国、台湾、国内 等

### 3. 删除问题订阅源

```bash
# 删除无法访问的订阅源
curl -s -b /tmp/fr_cookies.txt \
  -X POST "$FRESHRSS_URL/i/?c=subscription&a=delete&id=订阅源 ID" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

**问题源识别:**
- 页面显示 "⚠ 此源遇到一些问题"
- 长期无更新
- 无法访问/404

### 4. 删除重复订阅源

```bash
# 先查找重复源 (在订阅管理页面)
# 保留一个，删除其他重复的

curl -s -b /tmp/fr_cookies.txt \
  -X POST "$FRESHRSS_URL/i/?c=subscription&a=delete&id=重复源 ID" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

### 5. 批量添加新订阅源

```python
from hermes_tools import terminal

FRESHRSS_URL = "https://rss.liupeizhi.top"

# 定义要添加的订阅源列表
# 格式：(名称，RSS URL, 分类 ID)
new_feeds = [
    ("OpenAI Blog", "https://openai.com/blog/rss.xml", 39),  # 科技媒体
    ("Hugging Face Blog", "https://huggingface.co/blog/feed.xml", 39),
    ("Kubernetes Blog", "https://kubernetes.io/feed.xml", 2),  # 技术博客
    ("安全客", "https://www.anquanke.com/rss", 2),
    ("晚点 LatePost", "https://www.postlate.cn/feed", 41),  # 财经商业
]

for feed_name, feed_url, cat_id in new_feeds:
    add_cmd = f'''curl -s -b /tmp/fr_cookies.txt \\
      -X POST "{FRESHRSS_URL}/i/?c=subscription&a=add" \\
      -d "url={feed_url}&category={cat_id}&name={feed_name}" \\
      -H "Content-Type: application/x-www-form-urlencoded"'''
    result = terminal(add_cmd, timeout=30)
    # 检查是否成功
```

**常用分类 ID 参考:**
- 技术博客: 2
- 科技媒体: 39
- 财经商业: 41
- 文化阅读: 7
- 软件应用: 42
- 新闻资讯: 未分类

### 6. 验证操作结果

```bash
# 访问订阅管理页面确认
curl -s -b /tmp/fr_cookies.txt \
  "$FRESHRSS_URL/i/?c=subscription"
```

或在浏览器中登录查看。

## API 尝试 (备选方案)

### Fever API

```bash
FEVER_API_KEY="your_api_key"

curl -s -X POST "$FRESHRSS_URL/fever.php?api_key=$FEVER_API_KEY" \
  -d "api_key=$FEVER_API_KEY&feeds" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

**注意:** FreshRSS 的 Fever API endpoint 可能因版本而异，常见路径:
- `/fever.php?api_key=`
- `/api/fever.php?api_key=`
- `/fever/`

### Google Reader API

```bash
# 1. 获取认证 token
curl -s -c /tmp/fr_cookies.txt -b /tmp/fr_cookies.txt \
  "$FRESHRSS_URL/api/greader.php/accounts/ClientLogin" \
  -d "Email=username&Passwd=password"

# 2. 获取订阅列表
curl -s -b /tmp/fr_cookies.txt \
  "$FRESHRSS_URL/api/greader.php/reader/api/0/subscription/list?output=json"
```

**注意:** Google Reader API 需要正确的认证流程，Cookie 认证更可靠。

## 常见问题

### Q: API 返回 "Unauthorized!"
**A:** FreshRSS API 认证较复杂，建议使用 Cookie 认证方式。

### Q: Fever API 返回 404?
**A:** FreshRSS 的 Fever API endpoint 可能未启用或路径不同。实测 Cookie + POST 方式最可靠。

### Q: Google Reader API 无法认证?
**A:** 实测 FreshRSS 的 Google Reader API 认证流程复杂，直接使用 Cookie 认证跳过此步骤。

## 实测有效的 API Endpoint

**删除订阅源:**
```
POST /i/?c=subscription&a=delete&id={feed_id}
```

**添加订阅源:**
```
POST /i/?c=subscription&a=add
Data: url={rss_url}&category={cat_id}&name={feed_name}
```

**删除分类:**
```
POST /i/?c=category&a=delete&id={cat_id}
```

**实测分类 ID (FreshRSS 默认):**
- 技术博客: 2
- 科技媒体: 39
- 财经商业: 41
- 文化阅读: 7
- 软件应用: 42
- 微信公众号: 10

### Q: 如何获取分类 ID 和订阅源 ID?
**A:** 
1. 在订阅管理页面，点击分类/订阅源的 ⚙️ 按钮
2. URL 中会显示 `id=XXX` 参数
3. 或查看页面源码中的 `data-` 属性

### Q: 删除分类后页面仍显示?
**A:** FreshRSS 可能需要刷新缓存，或需要手动在页面确认删除。

### Q: 批量添加失败?
**A:** 
- 检查 RSS URL 是否有效
- 确认分类 ID 存在
- 增加 timeout 时间 (某些源响应慢)

## 最佳实践

1. **操作前备份**: 导出 OPML 备份当前订阅
2. **分批操作**: 每次操作 5-10 个订阅源，避免超时
3. **验证结果**: 操作后在页面确认变更
4. **记录 ID**: 保存分类和订阅源 ID 映射，便于后续操作
5. **Cookie 有效期**: Cookie 约 90 天有效，过期需重新登录

## 推荐订阅源

### AI/LLM
- OpenAI Blog: `https://openai.com/blog/rss.xml`
- Hugging Face: `https://huggingface.co/blog/feed.xml`
- Anthropic: `https://www.anthropic.com/rss.xml`

### 云原生
- Kubernetes: `https://kubernetes.io/feed.xml`
- CNCF: `https://www.cncf.io/blog/feed/`

### 网络安全
- 安全客：`https://www.anquanke.com/rss`
- FreeBuf: `https://www.freebuf.com/feed`

### 财经深度
- 晚点：`https://www.postlate.cn/feed`
- 远川：`https://www.yuanchuan.cn/feed`

## 相关文件

- OPML 导出：`/path/to/freshrss/data/`
- Cookie 临时文件：`/tmp/fr_cookies.txt`
