Skip to content

Commit c588e5d

Browse files
author
Taois
committed
feat: 完善skill
1 parent 8df6004 commit c588e5d

File tree

1 file changed

+245
-0
lines changed

1 file changed

+245
-0
lines changed

drpy-node-mcp/skills.md

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# drpy-node MCP Skills & Prompts
2+
3+
This document contains specialized prompts and workflows designed to leverage the `drpy-node-mcp` tools effectively. It also serves as a knowledge base for "DS Source" development.
4+
5+
## Skill 1: Create a New DS Source (Spider)
6+
7+
**Description:** Analyze a target website and create a compatible `drpy` JavaScript source file.
8+
9+
**Prompt Template:**
10+
```markdown
11+
I need you to create a new drpy JS spider for the website: [Target URL]
12+
13+
Please follow these steps:
14+
1. **Analyze the Target:**
15+
- Use `fetch_spider_url` to inspect the website's HTML structure and response headers. Check for anti-crawling measures (e.g., specific User-Agent requirements).
16+
- Identify the list page selectors, detail page selectors, and search logic.
17+
2. **Prepare the Template:**
18+
- Use `get_spider_template` to get the standard JS structure.
19+
- Refer to the **Knowledge Base** below for selector syntax (`pdfa`, `pdfh`) and `rule` object structure.
20+
3. **Develop the Source:**
21+
- Write the JS code including `rule` object with `title`, `host`, `url`, `searchUrl`.
22+
- Implement parsing logic for `一级` (List), `二级` (Detail), and `搜索` (Search).
23+
- **Selector Format**: `selector;attribute` (e.g., `.list li;a&&title;a&&href;img&&src;.desc&&Text`).
24+
- Use `class_name` and `class_url` for static categories, or implement `class_parse` for dynamic ones.
25+
4. **Validation:**
26+
- Save the file to `spider/js/[Name].js` using `write_file`.
27+
- Use `check_syntax` to ensure the JavaScript is valid.
28+
- Use `validate_spider` to confirm the drpy structure is correct.
29+
- Use `debug_spider_rule` to test specific rules (e.g., `pdfa` for lists) against fetched HTML.
30+
```
31+
32+
## Skill 2: Debug and Verify an Existing Source
33+
34+
**Description:** troubleshoot a malfunctioning source or verify a newly added one.
35+
36+
**Prompt Template:**
37+
```markdown
38+
Please debug and verify the spider source file: [File Path, e.g., spider/js/example.js]
39+
40+
Please follow these steps:
41+
1. **Read and Decode:**
42+
- Use `read_file` to load the source code. Note that `read_file` automatically decrypts DS sources.
43+
2. **Static Analysis:**
44+
- Use `check_syntax` to catch any syntax errors.
45+
- Use `validate_spider` to ensure the `rule` object and required fields are present.
46+
3. **Dynamic Testing:**
47+
- Use `fetch_spider_url` to request the source's `host` or a specific category URL.
48+
- **Header Check**: If the source uses custom `headers` (e.g., `User-Agent`, `Cookie`), ensure they are used in the fetch.
49+
- Use `debug_spider_rule` to test the parsing rules (e.g., `rule.一级` or `rule.searchUrl`) against the real response content.
50+
4. **Fix and Update:**
51+
- If errors are found (e.g., selector mismatch), propose a fix.
52+
- Use `write_file` to apply the corrected code.
53+
```
54+
55+
## Skill 3: System Health Check & Configuration
56+
57+
**Description:** Monitor the drpy-node service status, logs, and update configurations.
58+
59+
**Prompt Template:**
60+
```markdown
61+
Perform a health check on the drpy-node service and update configuration if needed.
62+
63+
Steps:
64+
1. **Check Logs:**
65+
- Use `read_logs` to inspect the latest application logs for errors.
66+
2. **Verify Routes:**
67+
- Use `get_routes_info` to confirm API routes are registered.
68+
3. **Check Database:**
69+
- Use `sql_query` to check the status of the database (e.g., `SELECT count(*) FROM iptv_sources`).
70+
4. **Configuration Management:**
71+
- Use `manage_config` with `action: 'get'` to review current settings.
72+
- Use `manage_config` with `action: 'set'` to update settings (e.g., `api.timeout`).
73+
- If config is changed, use `restart_service` to apply changes.
74+
```
75+
76+
## Skill 4: Advanced Source Logic (Encryption/Decryption)
77+
78+
**Description:** Handle sources with complex encryption, dynamic logic, or `lazy` loading.
79+
80+
**Prompt Template:**
81+
```markdown
82+
I need help with a source that requires custom decryption or dynamic logic: [File Path or URL]
83+
84+
Guidance:
85+
1. **Analyze Logic:**
86+
- Read the source code. Look for `proxyRule`, `unzip`, or custom `eval` usage.
87+
- **Global Libs**: Recall that `CryptoJS` is available globally.
88+
2. **Test Advanced Functions:**
89+
- **Lazy Loading**: If the source uses `lazy` (dynamic video URL), inspect the function. Use `fetch_spider_url` to simulate the internal requests.
90+
- **Proxy**: If `proxyRule` is used, ensure the proxy logic is valid.
91+
3. **Refine Code:**
92+
- Optimize `eval` usage.
93+
- Ensure `hostJs` or `预处理` (preprocessing) functions are correctly implemented for dynamic headers/tokens.
94+
```
95+
96+
## Knowledge Base & Reference
97+
98+
### 1. Source Structure (`rule` Object)
99+
A valid DS source must define a `rule` object.
100+
```javascript
101+
var rule = {
102+
title: 'Site Name',
103+
host: 'https://example.com',
104+
url: '/category/fyclass/page/fypage', // fyclass=category_id, fypage=page_num
105+
searchUrl: '/search?k=**&p=fypage', // **=keyword
106+
searchable: 2, // 1: search, 2: search+list
107+
quickSearch: 0,
108+
headers: { 'User-Agent': 'MOBILE_UA' },
109+
class_name: 'Movie&TV', // Static Categories
110+
class_url: 'movie&tv',
111+
// Parsing Rules
112+
play_parse: true,
113+
lazy: async function() { ... }, // Async video resolution
114+
一级: '.list li;a&&title;img&&src;.desc&&Text;a&&href', // List Parser
115+
二级: '*', // Detail Parser (can be '*' or specific rules)
116+
搜索: '*', // Search Parser
117+
}
118+
```
119+
120+
### 2. Selector Syntax (Cheerio-based)
121+
- **Format**: `selector;attribute` or `selector;attr1;attr2...`
122+
- **Functions**:
123+
- `pdfa(html, rule)`: Parse List (Returns Array).
124+
- `pdfh(html, rule)`: Parse Node (Returns String).
125+
- `pd(html, rule)`: Parse URL (Returns String, auto-resolves relative URLs).
126+
- **Special Attributes**:
127+
- `Text`: Element text.
128+
- `Html`: Element inner HTML.
129+
- `href` / `src`: Auto-resolves relative URLs to absolute.
130+
- `style`, `data-*`: Get attribute value.
131+
- **Special Syntax**:
132+
- `&&`: Separator for nested selectors (e.g., `.list&&li` -> find `.list` then `li`).
133+
- `||`: Backup selector (e.g., `img&&data-src||img&&src`).
134+
- `:eq(n)`: Select n-th element.
135+
- `*`: Select all or use default logic.
136+
137+
### 3. Advanced JS Mode (Async Functions)
138+
Keys like `一级`, `二级`, `搜索`, `推荐` can be `async` functions instead of strings.
139+
```javascript
140+
一级: async function() {
141+
let { input, pdfa, pdfh, pd } = this;
142+
// input is the HTML or Response
143+
let list = pdfa(input, '.list li');
144+
let d = [];
145+
list.forEach(it => {
146+
d.push({
147+
title: pdfh(it, 'a&&title'),
148+
desc: pdfh(it, '.desc&&Text'),
149+
pic: pd(it, 'img&&src'),
150+
url: pd(it, 'a&&href')
151+
});
152+
});
153+
return d; // Return array of objects
154+
}
155+
```
156+
157+
### 4. Global Helper Functions
158+
- `request(url, options)`: Async HTTP request.
159+
- `post(url, options)`: Async HTTP POST.
160+
- `log(msg)`: Print logs to console (visible in `read_logs`).
161+
- `setItem(key, value)` / `getItem(key)`: Persistent storage.
162+
- `urljoin(base, path)`: Join URLs.
163+
164+
### 5. Common Patterns
165+
- **Lazy Loading (`lazy`)**: Used when the video URL needs to be fetched dynamically (e.g., from an iframe or API).
166+
```javascript
167+
lazy: async function() {
168+
let { input } = this; // input is the video page URL
169+
let html = await request(input);
170+
let videoUrl = pdfh(html, 'video&&src');
171+
return videoUrl; // Return the real video URL
172+
}
173+
```
174+
- **Dynamic Categories (`class_parse`)**:
175+
```javascript
176+
class_parse: '.menu li;a&&Text;a&&href;.*/(.*?)/' // Selector;Title;Url;RegexForID
177+
```
178+
179+
### 6. Advanced Features & Best Practices
180+
181+
- **Batch Requests (`batchFetch`)**: Execute multiple HTTP requests in parallel (if supported).
182+
```javascript
183+
if (typeof(batchFetch) === 'function') {
184+
let urls = [
185+
{ url: 'http://site1.com/api', options: { headers: {} } },
186+
{ url: 'http://site2.com/api', options: {} }
187+
];
188+
let responses = await batchFetch(urls); // Returns array of response strings
189+
}
190+
```
191+
192+
- **Pre-processing (`预处理`)**: Run logic before the main parsing starts. Useful for dynamic configuration or fetching initial tokens.
193+
```javascript
194+
预处理: async function() {
195+
// Modify rule object dynamically
196+
let config = JSON.parse(await request('http://config.url'));
197+
rule.classes = config.classes; // Set categories dynamically
198+
}
199+
```
200+
201+
- **Lazy Parsing Options (`lazy`)**: Return an object for more control.
202+
```javascript
203+
lazy: async function() {
204+
return {
205+
parse: 1, // 1=Sniffing/Parsing enabled (0=Direct URL)
206+
jx: 1, // 1=Use app's built-in VIP parser (if available)
207+
url: 'http://video.url',
208+
header: { 'User-Agent': '...' }
209+
}
210+
}
211+
```
212+
213+
- **State Management (`setItem`, `getItem`)**: Persist data across function calls (e.g., sessions, tokens).
214+
```javascript
215+
let token = getItem('my_token', '');
216+
if (!token) {
217+
token = await fetchToken();
218+
setItem('my_token', token);
219+
}
220+
```
221+
222+
### 7. Content Type Specifics
223+
224+
- **Novels (`类型: '小说'`)**:
225+
- `lazy` should return `novel://` followed by a JSON string of `{ title, content }`.
226+
```javascript
227+
lazy: async function() {
228+
let content = '...'; // Decrypted text
229+
let ret = JSON.stringify({ title: 'Chapter 1', content: content });
230+
return { parse: 0, url: 'novel://' + ret };
231+
}
232+
```
233+
234+
## Tool Reference
235+
236+
| Tool Name | Description | Key Usage |
237+
| :--- | :--- | :--- |
238+
| `fetch_spider_url` | Fetch URL with custom options | Test connectivity, get HTML for debugging |
239+
| `debug_spider_rule` | Test parsing rules | Verify CSS/Regex selectors against HTML |
240+
| `validate_spider` | Validate spider structure | Check for `rule` object and required fields |
241+
| `check_syntax` | Check JS syntax | Catch syntax errors before running |
242+
| `read_file` | Read file content | **Automatically decodes DS sources** |
243+
| `get_spider_template` | Get source template | Start new sources with best practices |
244+
| `get_drpy_libs_info` | Get available libs | Check available global functions (pdfa, req, etc.) |
245+
| `manage_config` | Read/Write config | Adjust system settings safely |

0 commit comments

Comments
 (0)