@jackwener/opencli 0.9.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CDP.md +1 -1
- package/CDP.zh-CN.md +1 -1
- package/CLI-ELECTRON.md +2 -2
- package/CLI-EXPLORER.md +4 -4
- package/README.md +15 -57
- package/README.zh-CN.md +16 -59
- package/SKILL.md +10 -8
- package/TESTING.md +7 -7
- package/dist/browser/daemon-client.d.ts +37 -0
- package/dist/browser/daemon-client.js +82 -0
- package/dist/browser/discover.d.ts +11 -34
- package/dist/browser/discover.js +15 -205
- package/dist/browser/errors.d.ts +6 -20
- package/dist/browser/errors.js +24 -63
- package/dist/browser/index.d.ts +2 -11
- package/dist/browser/index.js +5 -11
- package/dist/browser/mcp.d.ts +9 -18
- package/dist/browser/mcp.js +70 -284
- package/dist/browser/page.d.ts +28 -6
- package/dist/browser/page.js +210 -85
- package/dist/browser.test.js +4 -225
- package/dist/cli-manifest.json +167 -0
- package/dist/clis/neteasemusic/like.d.ts +1 -0
- package/dist/clis/neteasemusic/like.js +25 -0
- package/dist/clis/neteasemusic/lyrics.d.ts +1 -0
- package/dist/clis/neteasemusic/lyrics.js +47 -0
- package/dist/clis/neteasemusic/next.d.ts +1 -0
- package/dist/clis/neteasemusic/next.js +26 -0
- package/dist/clis/neteasemusic/play.d.ts +1 -0
- package/dist/clis/neteasemusic/play.js +26 -0
- package/dist/clis/neteasemusic/playing.d.ts +1 -0
- package/dist/clis/neteasemusic/playing.js +59 -0
- package/dist/clis/neteasemusic/playlist.d.ts +1 -0
- package/dist/clis/neteasemusic/playlist.js +46 -0
- package/dist/clis/neteasemusic/prev.d.ts +1 -0
- package/dist/clis/neteasemusic/prev.js +25 -0
- package/dist/clis/neteasemusic/search.d.ts +1 -0
- package/dist/clis/neteasemusic/search.js +52 -0
- package/dist/clis/neteasemusic/status.d.ts +1 -0
- package/dist/clis/neteasemusic/status.js +16 -0
- package/dist/clis/neteasemusic/volume.d.ts +1 -0
- package/dist/clis/neteasemusic/volume.js +54 -0
- package/dist/daemon.d.ts +13 -0
- package/dist/daemon.js +187 -0
- package/dist/doctor.d.ts +27 -61
- package/dist/doctor.js +70 -601
- package/dist/doctor.test.js +30 -170
- package/dist/main.js +6 -25
- package/dist/pipeline/executor.test.js +1 -0
- package/dist/pipeline/steps/browser.js +2 -2
- package/dist/pipeline/steps/intercept.js +1 -2
- package/dist/setup.d.ts +6 -0
- package/dist/setup.js +46 -160
- package/dist/types.d.ts +6 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/manifest.json +31 -0
- package/extension/package.json +16 -0
- package/extension/src/background.ts +293 -0
- package/extension/src/cdp.ts +125 -0
- package/extension/src/protocol.ts +57 -0
- package/extension/store-assets/screenshot-1280x800.png +0 -0
- package/extension/tsconfig.json +15 -0
- package/extension/vite.config.ts +18 -0
- package/package.json +5 -5
- package/src/browser/daemon-client.ts +113 -0
- package/src/browser/discover.ts +18 -232
- package/src/browser/errors.ts +30 -100
- package/src/browser/index.ts +6 -12
- package/src/browser/mcp.ts +78 -278
- package/src/browser/page.ts +222 -88
- package/src/browser.test.ts +3 -233
- package/src/clis/chatgpt/README.md +1 -1
- package/src/clis/chatgpt/README.zh-CN.md +1 -1
- package/src/clis/neteasemusic/README.md +31 -0
- package/src/clis/neteasemusic/README.zh-CN.md +31 -0
- package/src/clis/neteasemusic/like.ts +28 -0
- package/src/clis/neteasemusic/lyrics.ts +53 -0
- package/src/clis/neteasemusic/next.ts +30 -0
- package/src/clis/neteasemusic/play.ts +30 -0
- package/src/clis/neteasemusic/playing.ts +62 -0
- package/src/clis/neteasemusic/playlist.ts +51 -0
- package/src/clis/neteasemusic/prev.ts +29 -0
- package/src/clis/neteasemusic/search.ts +58 -0
- package/src/clis/neteasemusic/status.ts +18 -0
- package/src/clis/neteasemusic/volume.ts +61 -0
- package/src/daemon.ts +217 -0
- package/src/doctor.test.ts +32 -193
- package/src/doctor.ts +74 -668
- package/src/main.ts +6 -23
- package/src/pipeline/executor.test.ts +1 -0
- package/src/pipeline/steps/browser.ts +2 -2
- package/src/pipeline/steps/intercept.ts +1 -2
- package/src/setup.ts +47 -183
- package/src/types.ts +1 -0
|
@@ -35,7 +35,7 @@ export OPENCLI_CDP_ENDPOINT="http://127.0.0.1:9224"
|
|
|
35
35
|
## 工作原理
|
|
36
36
|
|
|
37
37
|
- **AppleScript 模式**:使用 `osascript` 和 `pbcopy`/`pbpaste` 进行剪贴板文本传输,无需远程调试端口。
|
|
38
|
-
- **CDP 模式**:通过
|
|
38
|
+
- **CDP 模式**:通过 Chrome DevTools Protocol 连接到 Electron 渲染进程,直接操作 DOM。
|
|
39
39
|
|
|
40
40
|
## 限制
|
|
41
41
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# NeteaseMusic Desktop Adapter (网易云音乐)
|
|
2
|
+
|
|
3
|
+
Control **NeteaseMusic** (网易云音乐) from the terminal via Chrome DevTools Protocol (CDP). The app uses Chromium Embedded Framework (CEF).
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Launch with remote debugging port:
|
|
8
|
+
```bash
|
|
9
|
+
/Applications/NeteaseMusic.app/Contents/MacOS/NeteaseMusic --remote-debugging-port=9234
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
export OPENCLI_CDP_ENDPOINT="http://127.0.0.1:9234"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Commands
|
|
19
|
+
|
|
20
|
+
| Command | Description |
|
|
21
|
+
|---------|-------------|
|
|
22
|
+
| `neteasemusic status` | Check CDP connection |
|
|
23
|
+
| `neteasemusic playing` | Current song info (title, artist, album) |
|
|
24
|
+
| `neteasemusic play` | Play / Pause toggle |
|
|
25
|
+
| `neteasemusic next` | Skip to next song |
|
|
26
|
+
| `neteasemusic prev` | Go to previous song |
|
|
27
|
+
| `neteasemusic search "query"` | Search songs, artists |
|
|
28
|
+
| `neteasemusic playlist` | Show current playback queue |
|
|
29
|
+
| `neteasemusic like` | Like / unlike current song |
|
|
30
|
+
| `neteasemusic lyrics` | Get lyrics of current song |
|
|
31
|
+
| `neteasemusic volume [0-100]` | Get or set volume |
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# 网易云音乐桌面端适配器
|
|
2
|
+
|
|
3
|
+
通过 Chrome DevTools Protocol (CDP) 在终端中控制 **网易云音乐**。该应用基于 Chromium Embedded Framework (CEF)。
|
|
4
|
+
|
|
5
|
+
## 前置条件
|
|
6
|
+
|
|
7
|
+
通过远程调试端口启动:
|
|
8
|
+
```bash
|
|
9
|
+
/Applications/NeteaseMusic.app/Contents/MacOS/NeteaseMusic --remote-debugging-port=9234
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 配置
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
export OPENCLI_CDP_ENDPOINT="http://127.0.0.1:9234"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 命令
|
|
19
|
+
|
|
20
|
+
| 命令 | 说明 |
|
|
21
|
+
|------|------|
|
|
22
|
+
| `neteasemusic status` | 检查 CDP 连接 |
|
|
23
|
+
| `neteasemusic playing` | 当前播放歌曲信息 |
|
|
24
|
+
| `neteasemusic play` | 播放 / 暂停切换 |
|
|
25
|
+
| `neteasemusic next` | 下一首 |
|
|
26
|
+
| `neteasemusic prev` | 上一首 |
|
|
27
|
+
| `neteasemusic search "关键词"` | 搜索歌曲 |
|
|
28
|
+
| `neteasemusic playlist` | 显示当前播放列表 |
|
|
29
|
+
| `neteasemusic like` | 喜欢 / 取消喜欢 |
|
|
30
|
+
| `neteasemusic lyrics` | 获取当前歌词 |
|
|
31
|
+
| `neteasemusic volume [0-100]` | 获取或设置音量 |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const likeCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'like',
|
|
7
|
+
description: 'Like/unlike the currently playing song',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Status'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
const result = await page.evaluate(`
|
|
15
|
+
(function() {
|
|
16
|
+
// The like/heart button in the player bar
|
|
17
|
+
const btn = document.querySelector('.m-playbar .icn-love, .m-playbar [class*="like"], .m-player [class*="love"], [data-action="like"]');
|
|
18
|
+
if (!btn) return 'Like button not found';
|
|
19
|
+
|
|
20
|
+
const wasLiked = btn.classList.contains('loved') || btn.classList.contains('active') || btn.getAttribute('data-liked') === 'true';
|
|
21
|
+
btn.click();
|
|
22
|
+
return wasLiked ? 'Unliked' : 'Liked';
|
|
23
|
+
})()
|
|
24
|
+
`);
|
|
25
|
+
|
|
26
|
+
return [{ Status: result }];
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const lyricsCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'lyrics',
|
|
7
|
+
description: 'Get the lyrics of the currently playing song',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Line'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
// Try to open lyrics panel if not visible
|
|
15
|
+
await page.evaluate(`
|
|
16
|
+
(function() {
|
|
17
|
+
const btn = document.querySelector('.m-playbar .icn-lyric, [class*="lyric-btn"], [data-action="lyric"]');
|
|
18
|
+
if (btn) btn.click();
|
|
19
|
+
})()
|
|
20
|
+
`);
|
|
21
|
+
|
|
22
|
+
await page.wait(1);
|
|
23
|
+
|
|
24
|
+
const lyrics = await page.evaluate(`
|
|
25
|
+
(function() {
|
|
26
|
+
// Look for lyrics container
|
|
27
|
+
const selectors = [
|
|
28
|
+
'.m-lyric p, .m-lyric [class*="line"]',
|
|
29
|
+
'[class*="lyric-content"] p',
|
|
30
|
+
'.listlyric li',
|
|
31
|
+
'[class*="lyric"] [class*="line"]',
|
|
32
|
+
'.j-lyric p',
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
for (const sel of selectors) {
|
|
36
|
+
const nodes = document.querySelectorAll(sel);
|
|
37
|
+
if (nodes.length > 0) {
|
|
38
|
+
return Array.from(nodes).map(n => (n.textContent || '').trim()).filter(l => l.length > 0);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Fallback: try the body text for any lyrics-like content
|
|
43
|
+
return [];
|
|
44
|
+
})()
|
|
45
|
+
`);
|
|
46
|
+
|
|
47
|
+
if (lyrics.length === 0) {
|
|
48
|
+
return [{ Line: 'No lyrics found. Try opening the lyrics panel first.' }];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return lyrics.map((line: string) => ({ Line: line }));
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const nextCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'next',
|
|
7
|
+
description: 'Skip to the next song',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Status'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
const clicked = await page.evaluate(`
|
|
15
|
+
(function() {
|
|
16
|
+
const btn = document.querySelector('.m-playbar .btnfwd, .m-playbar [class*="next"], .m-player .btn-next, [data-action="next"]');
|
|
17
|
+
if (btn) { btn.click(); return true; }
|
|
18
|
+
return false;
|
|
19
|
+
})()
|
|
20
|
+
`);
|
|
21
|
+
|
|
22
|
+
if (!clicked) {
|
|
23
|
+
// Fallback: Ctrl+Right is common next-track shortcut
|
|
24
|
+
await page.pressKey('Control+ArrowRight');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await page.wait(1);
|
|
28
|
+
return [{ Status: 'Skipped to next song' }];
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const playCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'play',
|
|
7
|
+
description: 'Toggle play/pause for the current song',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Status'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
// Click the play/pause button or use Space key
|
|
15
|
+
const clicked = await page.evaluate(`
|
|
16
|
+
(function() {
|
|
17
|
+
const btn = document.querySelector('.m-playbar .btnp, .m-playbar [class*="play"], .m-player .btn-play, [data-action="play"]');
|
|
18
|
+
if (btn) { btn.click(); return true; }
|
|
19
|
+
return false;
|
|
20
|
+
})()
|
|
21
|
+
`);
|
|
22
|
+
|
|
23
|
+
if (!clicked) {
|
|
24
|
+
// Fallback: use Space key which is the universal play/pause shortcut
|
|
25
|
+
await page.pressKey('Space');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return [{ Status: 'Play/Pause toggled' }];
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const playingCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'playing',
|
|
7
|
+
description: 'Get the currently playing song info',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Title', 'Artist', 'Album', 'Duration', 'Progress'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
const info = await page.evaluate(`
|
|
15
|
+
(function() {
|
|
16
|
+
// NeteaseMusic player bar is at the bottom
|
|
17
|
+
const selectors = {
|
|
18
|
+
title: '.m-playbar .j-song .name, .m-playbar .song .name, [class*="playing"] .name, .m-player .name',
|
|
19
|
+
artist: '.m-playbar .j-song .by, .m-playbar .song .by, [class*="playing"] .artist, .m-player .by',
|
|
20
|
+
album: '.m-playbar .j-song .album, [class*="playing"] .album',
|
|
21
|
+
time: '.m-playbar .j-dur, .m-playbar .time, .m-player .time',
|
|
22
|
+
progress: '.m-playbar .barbg .rng, .m-playbar [role="progressbar"], .m-player [class*="progress"]',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function getText(sel) {
|
|
26
|
+
for (const s of sel.split(',')) {
|
|
27
|
+
const el = document.querySelector(s.trim());
|
|
28
|
+
if (el) return (el.textContent || el.innerText || '').trim();
|
|
29
|
+
}
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const title = getText(selectors.title);
|
|
34
|
+
const artist = getText(selectors.artist);
|
|
35
|
+
const album = getText(selectors.album);
|
|
36
|
+
const time = getText(selectors.time);
|
|
37
|
+
|
|
38
|
+
// Try to get playback progress from the progress bar width
|
|
39
|
+
let progress = '';
|
|
40
|
+
const bar = document.querySelector('.m-playbar .barbg .rng, [class*="progress"] [class*="played"]');
|
|
41
|
+
if (bar) {
|
|
42
|
+
const style = bar.getAttribute('style') || '';
|
|
43
|
+
const match = style.match(/width:\\s*(\\d+\\.?\\d*)%/);
|
|
44
|
+
if (match) progress = match[1] + '%';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!title) {
|
|
48
|
+
// Fallback: try document title which often contains "songName - NeteaseMusic"
|
|
49
|
+
const docTitle = document.title;
|
|
50
|
+
if (docTitle && !docTitle.includes('NeteaseMusic')) {
|
|
51
|
+
return { Title: docTitle, Artist: '', Album: '', Duration: '', Progress: '' };
|
|
52
|
+
}
|
|
53
|
+
return { Title: 'No song playing', Artist: '—', Album: '—', Duration: '—', Progress: '—' };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { Title: title, Artist: artist, Album: album, Duration: time, Progress: progress };
|
|
57
|
+
})()
|
|
58
|
+
`);
|
|
59
|
+
|
|
60
|
+
return [info];
|
|
61
|
+
},
|
|
62
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const playlistCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'playlist',
|
|
7
|
+
description: 'Show the current playback queue / playlist',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Index', 'Title', 'Artist'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
// Open the playlist panel (usually a button at the bottom bar)
|
|
15
|
+
await page.evaluate(`
|
|
16
|
+
(function() {
|
|
17
|
+
const btn = document.querySelector('.m-playbar .icn-list, .m-playbar [class*="playlist"], [data-action="playlist"], .m-playbar .btnlist');
|
|
18
|
+
if (btn) btn.click();
|
|
19
|
+
})()
|
|
20
|
+
`);
|
|
21
|
+
|
|
22
|
+
await page.wait(1);
|
|
23
|
+
|
|
24
|
+
const items = await page.evaluate(`
|
|
25
|
+
(function() {
|
|
26
|
+
const results = [];
|
|
27
|
+
// Playlist panel items
|
|
28
|
+
const rows = document.querySelectorAll('.m-playlist li, [class*="playlist-panel"] li, .listlyric li, .j-playlist li');
|
|
29
|
+
|
|
30
|
+
rows.forEach((row, i) => {
|
|
31
|
+
const nameEl = row.querySelector('.name, [class*="name"], a, span:first-child');
|
|
32
|
+
const artistEl = row.querySelector('.by, [class*="artist"], .ar');
|
|
33
|
+
|
|
34
|
+
const title = nameEl ? (nameEl.getAttribute('title') || nameEl.textContent || '').trim() : (row.textContent || '').trim();
|
|
35
|
+
const artist = artistEl ? (artistEl.textContent || '').trim() : '';
|
|
36
|
+
|
|
37
|
+
if (title && title.length > 0) {
|
|
38
|
+
results.push({ Index: i + 1, Title: title.substring(0, 80), Artist: artist });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return results;
|
|
43
|
+
})()
|
|
44
|
+
`);
|
|
45
|
+
|
|
46
|
+
if (items.length === 0) {
|
|
47
|
+
return [{ Index: 0, Title: 'Playlist is empty or panel not open', Artist: '—' }];
|
|
48
|
+
}
|
|
49
|
+
return items;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const prevCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'prev',
|
|
7
|
+
description: 'Go back to the previous song',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Status'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
const clicked = await page.evaluate(`
|
|
15
|
+
(function() {
|
|
16
|
+
const btn = document.querySelector('.m-playbar .btnbak, .m-playbar [class*="prev"], .m-player .btn-prev, [data-action="prev"]');
|
|
17
|
+
if (btn) { btn.click(); return true; }
|
|
18
|
+
return false;
|
|
19
|
+
})()
|
|
20
|
+
`);
|
|
21
|
+
|
|
22
|
+
if (!clicked) {
|
|
23
|
+
await page.pressKey('Control+ArrowLeft');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await page.wait(1);
|
|
27
|
+
return [{ Status: 'Went to previous song' }];
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const searchCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'search',
|
|
7
|
+
description: 'Search for songs, artists, albums, or playlists',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [{ name: 'query', required: true, positional: true, help: 'Search query' }],
|
|
12
|
+
columns: ['Index', 'Title', 'Artist'],
|
|
13
|
+
func: async (page: IPage, kwargs: any) => {
|
|
14
|
+
const query = kwargs.query as string;
|
|
15
|
+
|
|
16
|
+
// Focus and fill the search box
|
|
17
|
+
await page.evaluate(`
|
|
18
|
+
(function(q) {
|
|
19
|
+
const input = document.querySelector('.m-search input, #srch, [class*="search"] input, input[type="search"]');
|
|
20
|
+
if (!input) throw new Error('Search input not found');
|
|
21
|
+
input.focus();
|
|
22
|
+
const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
|
|
23
|
+
setter.call(input, q);
|
|
24
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
25
|
+
})(${JSON.stringify(query)})
|
|
26
|
+
`);
|
|
27
|
+
|
|
28
|
+
await page.pressKey('Enter');
|
|
29
|
+
await page.wait(2);
|
|
30
|
+
|
|
31
|
+
// Scrape results
|
|
32
|
+
const results = await page.evaluate(`
|
|
33
|
+
(function() {
|
|
34
|
+
const items = [];
|
|
35
|
+
// Song list items in search results
|
|
36
|
+
const rows = document.querySelectorAll('.srchsongst li, .m-table tbody tr, [class*="songlist"] [class*="item"], table tbody tr');
|
|
37
|
+
|
|
38
|
+
rows.forEach((row, i) => {
|
|
39
|
+
if (i >= 20) return;
|
|
40
|
+
const nameEl = row.querySelector('.sn, .name a, [class*="songName"], td:nth-child(2) a, b[title]');
|
|
41
|
+
const artistEl = row.querySelector('.ar, .artist, [class*="artist"], td:nth-child(4) a, td:nth-child(3) a');
|
|
42
|
+
|
|
43
|
+
const title = nameEl ? (nameEl.getAttribute('title') || nameEl.textContent || '').trim() : '';
|
|
44
|
+
const artist = artistEl ? (artistEl.getAttribute('title') || artistEl.textContent || '').trim() : '';
|
|
45
|
+
|
|
46
|
+
if (title) items.push({ Index: i + 1, Title: title, Artist: artist });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return items;
|
|
50
|
+
})()
|
|
51
|
+
`);
|
|
52
|
+
|
|
53
|
+
if (results.length === 0) {
|
|
54
|
+
return [{ Index: 0, Title: `No results for "${query}"`, Artist: '—' }];
|
|
55
|
+
}
|
|
56
|
+
return results;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const statusCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'status',
|
|
7
|
+
description: 'Check CDP connection to NeteaseMusic Desktop',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [],
|
|
12
|
+
columns: ['Status', 'Url', 'Title'],
|
|
13
|
+
func: async (page: IPage) => {
|
|
14
|
+
const url = await page.evaluate('window.location.href');
|
|
15
|
+
const title = await page.evaluate('document.title');
|
|
16
|
+
return [{ Status: 'Connected', Url: url, Title: title }];
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import type { IPage } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export const volumeCommand = cli({
|
|
5
|
+
site: 'neteasemusic',
|
|
6
|
+
name: 'volume',
|
|
7
|
+
description: 'Get or set the volume level (0-100)',
|
|
8
|
+
domain: 'localhost',
|
|
9
|
+
strategy: Strategy.UI,
|
|
10
|
+
browser: true,
|
|
11
|
+
args: [
|
|
12
|
+
{ name: 'level', required: false, positional: true, help: 'Volume level 0-100 (omit to read current)' },
|
|
13
|
+
],
|
|
14
|
+
columns: ['Status', 'Volume'],
|
|
15
|
+
func: async (page: IPage, kwargs: any) => {
|
|
16
|
+
const level = kwargs.level as string | undefined;
|
|
17
|
+
|
|
18
|
+
if (!level) {
|
|
19
|
+
// Read current volume
|
|
20
|
+
const vol = await page.evaluate(`
|
|
21
|
+
(function() {
|
|
22
|
+
const bar = document.querySelector('.m-playbar .vol .barbg .rng, [class*="volume"] [class*="progress"], [class*="volume"] [class*="played"]');
|
|
23
|
+
if (bar) {
|
|
24
|
+
const style = bar.getAttribute('style') || '';
|
|
25
|
+
const match = style.match(/width:\\s*(\\d+\\.?\\d*)%/);
|
|
26
|
+
if (match) return match[1];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const vol = document.querySelector('.m-playbar .j-vol, [class*="volume-value"]');
|
|
30
|
+
if (vol) return vol.textContent.trim();
|
|
31
|
+
|
|
32
|
+
return 'Unknown';
|
|
33
|
+
})()
|
|
34
|
+
`);
|
|
35
|
+
|
|
36
|
+
return [{ Status: 'Current', Volume: vol + '%' }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Set volume by clicking on the volume bar at the right position
|
|
40
|
+
const targetVol = Math.max(0, Math.min(100, parseInt(level, 10)));
|
|
41
|
+
|
|
42
|
+
await page.evaluate(`
|
|
43
|
+
(function(target) {
|
|
44
|
+
const bar = document.querySelector('.m-playbar .vol .barbg, [class*="volume-bar"], [class*="volume"] [class*="track"]');
|
|
45
|
+
if (!bar) return;
|
|
46
|
+
|
|
47
|
+
const rect = bar.getBoundingClientRect();
|
|
48
|
+
const x = rect.left + (rect.width * target / 100);
|
|
49
|
+
const y = rect.top + rect.height / 2;
|
|
50
|
+
|
|
51
|
+
bar.dispatchEvent(new MouseEvent('click', {
|
|
52
|
+
clientX: x,
|
|
53
|
+
clientY: y,
|
|
54
|
+
bubbles: true,
|
|
55
|
+
}));
|
|
56
|
+
})(${targetVol})
|
|
57
|
+
`);
|
|
58
|
+
|
|
59
|
+
return [{ Status: 'Set', Volume: targetVol + '%' }];
|
|
60
|
+
},
|
|
61
|
+
});
|