Skip to content

Commit adf9241

Browse files
author
Taois
committed
feat prompt
1 parent 717ca82 commit adf9241

File tree

1 file changed

+71
-211
lines changed

1 file changed

+71
-211
lines changed

drpy-node-mcp/skills.md

Lines changed: 71 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -1,245 +1,105 @@
11
# drpy-node MCP Skills & Prompts
22

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.
3+
## Skill 1: Develop DS Source (Create/Debug)
4+
**Description:** Create, debug, and validate `drpy` JS spiders. Handles new sources, fixes, and advanced logic (encryption/lazy).
355

366
**Prompt Template:**
377
```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-
8+
Task: [Create/Debug/Analyze] DS Source for [URL/File]
639
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.
10+
1. **Analyze/Fetch**: Use `fetch_spider_url` to inspect HTML/Headers or `read_file` to load existing code (auto-decrypted).
11+
2. **Develop/Refine**:
12+
- Use `get_spider_template` for new files.
13+
- Implement `rule` object (see KB below).
14+
- For dynamic content, use `async` parsing or `lazy` loading.
15+
- For novels, `lazy` returns `novel://` + JSON.
16+
3. **Validate**:
17+
- Save via `write_file` to `spider/js/[Name].js`.
18+
- Check syntax (`check_syntax`) and structure (`validate_spider`).
19+
- Test rules (`debug_spider_rule`) against real content.
7420
```
7521

76-
## Skill 4: Advanced Source Logic (Encryption/Decryption)
77-
78-
**Description:** Handle sources with complex encryption, dynamic logic, or `lazy` loading.
22+
## Skill 2: System Maintenance
23+
**Description:** Monitor health, logs, DB, and config.
7924

8025
**Prompt Template:**
8126
```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.
27+
Task: System Health & Config Check
28+
Steps:
29+
1. **Diagnose**: `read_logs` for errors, `get_routes_info` for APIs, `sql_query` for DB stats.
30+
2. **Configure**: `manage_config` (get/set) to adjust settings (e.g., timeout).
31+
3. **Apply**: `restart_service` if config changed.
9432
```
9533

96-
## Knowledge Base & Reference
34+
## Knowledge Base (KB)
9735

9836
### 1. Source Structure (`rule` Object)
99-
A valid DS source must define a `rule` object.
10037
```javascript
10138
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,
39+
title: 'Site', host: 'https://site.com', url: '/cat/fyclass/p/fypage',
40+
searchUrl: '/s?k=**&p=fypage', searchable: 2, quickSearch: 0,
10841
headers: { 'User-Agent': 'MOBILE_UA' },
109-
class_name: 'Movie&TV', // Static Categories
110-
class_url: 'movie&tv',
111-
// Parsing Rules
42+
class_name: 'Mov&TV', class_url: 'mov&tv', // or async class_parse
11243
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
44+
lazy: async function() { return { parse: 1, url: '...' } }, // or return 'url'
45+
一级: '.list li;a&&title;img&&src;.desc&&Text;a&&href', // List: selector;attr...
46+
二级: '*', // Detail: '*' or { title: '...', ... }
47+
搜索: '*', // Search: '*' or async function
11748
}
11849
```
11950

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.
51+
### 2. Selectors (Cheerio-based)
52+
Format: `selector;attr` or `selector;attr1;attr2`
53+
| Func | Returns | Description |
54+
| :--- | :--- | :--- |
55+
| `pdfa` | Array | Parse List. |
56+
| `pdfh` | String | Parse Node. |
57+
| `pd` | String | Parse URL (auto-resolve). |
13658

137-
### 3. Advanced JS Mode (Async Functions)
138-
Keys like `一级`, `二级`, `搜索`, `推荐` can be `async` functions instead of strings.
59+
**Special Attrs**: `Text`, `Html`, `href`, `src`, `style`, `data-*`.
60+
**Syntax**: `&&` (nested), `||` (backup), `:eq(n)` (index), `*` (all).
61+
62+
### 3. Advanced Patterns
63+
**Async Parsing (`一级`/`二级`/`搜索`)**:
13964
```javascript
14065
一级: async function() {
14166
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
67+
return pdfa(input, '.list li').map(it => ({
68+
title: pdfh(it, 'a&&title'), url: pd(it, 'a&&href')
69+
}));
15470
}
15571
```
15672

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-
```
73+
**Batch Requests (`batchFetch`)**:
74+
```javascript
75+
let res = await batchFetch([{url:'...', options:{}}, ...]);
76+
```
21277

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-
```
78+
**Pre-processing (`预处理`)**:
79+
```javascript
80+
预处理: async function() { rule.classes = (await request('...')).classes; }
81+
```
22182

222-
### 7. Content Type Specifics
83+
**Novel Content**:
84+
```javascript
85+
lazy: async function() { return { parse: 0, url: 'novel://' + JSON.stringify({title:'', content:''}) }; }
86+
```
22387

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-
```
88+
### 4. Global Helpers
89+
| Helper | Description |
90+
| :--- | :--- |
91+
| `request(url, opt)` / `post` | Async HTTP GET/POST. |
92+
| `log(msg)` | Console log (view in `read_logs`). |
93+
| `setItem(k, v)` / `getItem(k)` | Persistent storage. |
94+
| `urljoin(base, path)` | URL resolution. |
23395

23496
## 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 |
97+
| Tool | Usage |
98+
| :--- | :--- |
99+
| `fetch_spider_url` | Test connectivity/headers. |
100+
| `debug_spider_rule` | Test CSS/Regex selectors. |
101+
| `validate_spider` | Check `rule` structure. |
102+
| `check_syntax` | Validate JS syntax. |
103+
| `read_file` | Read & **Auto-Decrypt**. |
104+
| `get_spider_template` | Standard template. |
105+
| `manage_config` | Edit env.json. |

0 commit comments

Comments
 (0)