@jackwener/opencli 0.9.8 → 1.0.1

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.
Files changed (165) hide show
  1. package/CDP.md +1 -1
  2. package/CDP.zh-CN.md +1 -1
  3. package/CLI-ELECTRON.md +2 -2
  4. package/CLI-EXPLORER.md +4 -4
  5. package/README.md +35 -58
  6. package/README.zh-CN.md +36 -60
  7. package/SKILL.md +10 -8
  8. package/TESTING.md +7 -7
  9. package/dist/browser/daemon-client.d.ts +37 -0
  10. package/dist/browser/daemon-client.js +82 -0
  11. package/dist/browser/discover.d.ts +11 -34
  12. package/dist/browser/discover.js +15 -205
  13. package/dist/browser/errors.d.ts +6 -20
  14. package/dist/browser/errors.js +24 -63
  15. package/dist/browser/index.d.ts +2 -12
  16. package/dist/browser/index.js +2 -12
  17. package/dist/browser/mcp.d.ts +9 -21
  18. package/dist/browser/mcp.js +70 -285
  19. package/dist/browser/page.d.ts +36 -7
  20. package/dist/browser/page.js +212 -81
  21. package/dist/browser.test.js +10 -231
  22. package/dist/cli-manifest.json +561 -14
  23. package/dist/clis/apple-podcasts/episodes.d.ts +1 -0
  24. package/dist/clis/apple-podcasts/episodes.js +28 -0
  25. package/dist/clis/apple-podcasts/search.d.ts +1 -0
  26. package/dist/clis/apple-podcasts/search.js +29 -0
  27. package/dist/clis/apple-podcasts/top.d.ts +1 -0
  28. package/dist/clis/apple-podcasts/top.js +34 -0
  29. package/dist/clis/apple-podcasts/utils.d.ts +11 -0
  30. package/dist/clis/apple-podcasts/utils.js +30 -0
  31. package/dist/clis/apple-podcasts/utils.test.d.ts +1 -0
  32. package/dist/clis/apple-podcasts/utils.test.js +57 -0
  33. package/dist/clis/chatwise/history.js +18 -1
  34. package/dist/clis/discord-app/channels.js +33 -21
  35. package/dist/clis/neteasemusic/like.d.ts +1 -0
  36. package/dist/clis/neteasemusic/like.js +25 -0
  37. package/dist/clis/neteasemusic/lyrics.d.ts +1 -0
  38. package/dist/clis/neteasemusic/lyrics.js +47 -0
  39. package/dist/clis/neteasemusic/next.d.ts +1 -0
  40. package/dist/clis/neteasemusic/next.js +26 -0
  41. package/dist/clis/neteasemusic/play.d.ts +1 -0
  42. package/dist/clis/neteasemusic/play.js +26 -0
  43. package/dist/clis/neteasemusic/playing.d.ts +1 -0
  44. package/dist/clis/neteasemusic/playing.js +59 -0
  45. package/dist/clis/neteasemusic/playlist.d.ts +1 -0
  46. package/dist/clis/neteasemusic/playlist.js +46 -0
  47. package/dist/clis/neteasemusic/prev.d.ts +1 -0
  48. package/dist/clis/neteasemusic/prev.js +25 -0
  49. package/dist/clis/neteasemusic/search.d.ts +1 -0
  50. package/dist/clis/neteasemusic/search.js +52 -0
  51. package/dist/clis/neteasemusic/status.d.ts +1 -0
  52. package/dist/clis/neteasemusic/status.js +16 -0
  53. package/dist/clis/neteasemusic/volume.d.ts +1 -0
  54. package/dist/clis/neteasemusic/volume.js +54 -0
  55. package/dist/clis/twitter/accept.d.ts +1 -0
  56. package/dist/clis/twitter/accept.js +202 -0
  57. package/dist/clis/twitter/followers.js +30 -22
  58. package/dist/clis/twitter/following.js +19 -14
  59. package/dist/clis/twitter/notifications.js +29 -22
  60. package/dist/clis/twitter/reply-dm.d.ts +1 -0
  61. package/dist/clis/twitter/reply-dm.js +181 -0
  62. package/dist/clis/twitter/search.js +50 -12
  63. package/dist/clis/weread/book.d.ts +1 -0
  64. package/dist/clis/weread/book.js +26 -0
  65. package/dist/clis/weread/highlights.d.ts +1 -0
  66. package/dist/clis/weread/highlights.js +23 -0
  67. package/dist/clis/weread/notebooks.d.ts +1 -0
  68. package/dist/clis/weread/notebooks.js +21 -0
  69. package/dist/clis/weread/notes.d.ts +1 -0
  70. package/dist/clis/weread/notes.js +29 -0
  71. package/dist/clis/weread/ranking.d.ts +1 -0
  72. package/dist/clis/weread/ranking.js +28 -0
  73. package/dist/clis/weread/search.d.ts +1 -0
  74. package/dist/clis/weread/search.js +25 -0
  75. package/dist/clis/weread/shelf.d.ts +1 -0
  76. package/dist/clis/weread/shelf.js +24 -0
  77. package/dist/clis/weread/utils.d.ts +20 -0
  78. package/dist/clis/weread/utils.js +72 -0
  79. package/dist/clis/weread/utils.test.d.ts +1 -0
  80. package/dist/clis/weread/utils.test.js +85 -0
  81. package/dist/daemon.d.ts +13 -0
  82. package/dist/daemon.js +187 -0
  83. package/dist/doctor.d.ts +10 -65
  84. package/dist/doctor.js +49 -602
  85. package/dist/doctor.test.js +30 -170
  86. package/dist/main.js +12 -41
  87. package/dist/pipeline/executor.test.js +1 -0
  88. package/dist/pipeline/steps/browser.js +2 -2
  89. package/dist/pipeline/steps/intercept.js +1 -2
  90. package/dist/runtime.d.ts +1 -4
  91. package/dist/runtime.js +1 -4
  92. package/dist/setup.d.ts +6 -0
  93. package/dist/setup.js +46 -160
  94. package/dist/types.d.ts +6 -0
  95. package/extension/dist/background.js +484 -0
  96. package/extension/icons/icon-128.png +0 -0
  97. package/extension/icons/icon-16.png +0 -0
  98. package/extension/icons/icon-32.png +0 -0
  99. package/extension/icons/icon-48.png +0 -0
  100. package/extension/manifest.json +31 -0
  101. package/extension/package.json +16 -0
  102. package/extension/src/background.ts +370 -0
  103. package/extension/src/cdp.ts +125 -0
  104. package/extension/src/protocol.ts +57 -0
  105. package/extension/store-assets/screenshot-1280x800.png +0 -0
  106. package/extension/tsconfig.json +15 -0
  107. package/extension/vite.config.ts +18 -0
  108. package/package.json +5 -5
  109. package/src/browser/daemon-client.ts +113 -0
  110. package/src/browser/discover.ts +18 -232
  111. package/src/browser/errors.ts +30 -100
  112. package/src/browser/index.ts +2 -13
  113. package/src/browser/mcp.ts +81 -282
  114. package/src/browser/page.ts +223 -83
  115. package/src/browser.test.ts +9 -239
  116. package/src/clis/apple-podcasts/episodes.ts +28 -0
  117. package/src/clis/apple-podcasts/search.ts +29 -0
  118. package/src/clis/apple-podcasts/top.ts +34 -0
  119. package/src/clis/apple-podcasts/utils.test.ts +72 -0
  120. package/src/clis/apple-podcasts/utils.ts +37 -0
  121. package/src/clis/chatgpt/README.md +1 -1
  122. package/src/clis/chatgpt/README.zh-CN.md +1 -1
  123. package/src/clis/chatwise/history.ts +15 -1
  124. package/src/clis/discord-app/channels.ts +33 -21
  125. package/src/clis/neteasemusic/README.md +31 -0
  126. package/src/clis/neteasemusic/README.zh-CN.md +31 -0
  127. package/src/clis/neteasemusic/like.ts +28 -0
  128. package/src/clis/neteasemusic/lyrics.ts +53 -0
  129. package/src/clis/neteasemusic/next.ts +30 -0
  130. package/src/clis/neteasemusic/play.ts +30 -0
  131. package/src/clis/neteasemusic/playing.ts +62 -0
  132. package/src/clis/neteasemusic/playlist.ts +51 -0
  133. package/src/clis/neteasemusic/prev.ts +29 -0
  134. package/src/clis/neteasemusic/search.ts +58 -0
  135. package/src/clis/neteasemusic/status.ts +18 -0
  136. package/src/clis/neteasemusic/volume.ts +61 -0
  137. package/src/clis/twitter/accept.ts +213 -0
  138. package/src/clis/twitter/followers.ts +36 -29
  139. package/src/clis/twitter/following.ts +25 -20
  140. package/src/clis/twitter/notifications.ts +34 -27
  141. package/src/clis/twitter/reply-dm.ts +193 -0
  142. package/src/clis/twitter/search.ts +53 -13
  143. package/src/clis/weread/book.ts +28 -0
  144. package/src/clis/weread/highlights.ts +25 -0
  145. package/src/clis/weread/notebooks.ts +23 -0
  146. package/src/clis/weread/notes.ts +31 -0
  147. package/src/clis/weread/ranking.ts +29 -0
  148. package/src/clis/weread/search.ts +26 -0
  149. package/src/clis/weread/shelf.ts +26 -0
  150. package/src/clis/weread/utils.test.ts +104 -0
  151. package/src/clis/weread/utils.ts +74 -0
  152. package/src/daemon.ts +217 -0
  153. package/src/doctor.test.ts +32 -193
  154. package/src/doctor.ts +58 -669
  155. package/src/main.ts +11 -34
  156. package/src/pipeline/executor.test.ts +1 -0
  157. package/src/pipeline/steps/browser.ts +2 -2
  158. package/src/pipeline/steps/intercept.ts +1 -2
  159. package/src/runtime.ts +2 -6
  160. package/src/setup.ts +47 -183
  161. package/src/types.ts +1 -0
  162. package/tests/e2e/public-commands.test.ts +68 -1
  163. package/dist/clis/grok/debug.d.ts +0 -1
  164. package/dist/clis/grok/debug.js +0 -45
  165. package/src/clis/grok/debug.ts +0 -49
@@ -0,0 +1,34 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ import { CliError } from '../../errors.js';
3
+ // Apple Marketing Tools RSS API — public, no key required
4
+ const CHARTS_URL = 'https://rss.applemarketingtools.com/api/v2';
5
+ cli({
6
+ site: 'apple-podcasts',
7
+ name: 'top',
8
+ description: 'Top podcasts chart on Apple Podcasts',
9
+ strategy: Strategy.PUBLIC,
10
+ browser: false,
11
+ args: [
12
+ { name: 'limit', type: 'int', default: 20, help: 'Number of podcasts (max 100)' },
13
+ { name: 'country', default: 'us', help: 'Country code (e.g. us, cn, gb, jp)' },
14
+ ],
15
+ columns: ['rank', 'title', 'author', 'id'],
16
+ func: async (_page, args) => {
17
+ const limit = Math.max(1, Math.min(Number(args.limit), 100));
18
+ const country = String(args.country || 'us').trim().toLowerCase();
19
+ const url = `${CHARTS_URL}/${country}/podcasts/top/${limit}/podcasts.json`;
20
+ const resp = await fetch(url);
21
+ if (!resp.ok)
22
+ throw new CliError('FETCH_ERROR', `Charts API HTTP ${resp.status}`, `Check country code: ${country}`);
23
+ const data = await resp.json();
24
+ const results = data?.feed?.results;
25
+ if (!results?.length)
26
+ throw new CliError('NOT_FOUND', 'No chart data found', `Try a different country code`);
27
+ return results.map((p, i) => ({
28
+ rank: i + 1,
29
+ title: p.name,
30
+ author: p.artistName,
31
+ id: p.id,
32
+ }));
33
+ },
34
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Shared Apple Podcasts utilities.
3
+ *
4
+ * Uses the public iTunes Search API — no API key required.
5
+ * https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/
6
+ */
7
+ export declare function itunesFetch(path: string): Promise<any>;
8
+ /** Format milliseconds to mm:ss. Returns '-' for missing input. */
9
+ export declare function formatDuration(ms: number): string;
10
+ /** Format ISO date string to YYYY-MM-DD. Returns '-' for missing input. */
11
+ export declare function formatDate(iso: string): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shared Apple Podcasts utilities.
3
+ *
4
+ * Uses the public iTunes Search API — no API key required.
5
+ * https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/
6
+ */
7
+ import { CliError } from '../../errors.js';
8
+ const BASE = 'https://itunes.apple.com';
9
+ export async function itunesFetch(path) {
10
+ const resp = await fetch(`${BASE}${path}`);
11
+ if (!resp.ok) {
12
+ throw new CliError('FETCH_ERROR', `iTunes API HTTP ${resp.status}`, 'Check your search term or podcast ID');
13
+ }
14
+ return resp.json();
15
+ }
16
+ /** Format milliseconds to mm:ss. Returns '-' for missing input. */
17
+ export function formatDuration(ms) {
18
+ if (!ms || !Number.isFinite(ms))
19
+ return '-';
20
+ const totalSec = Math.round(ms / 1000);
21
+ const m = Math.floor(totalSec / 60);
22
+ const s = totalSec % 60;
23
+ return `${m}:${String(s).padStart(2, '0')}`;
24
+ }
25
+ /** Format ISO date string to YYYY-MM-DD. Returns '-' for missing input. */
26
+ export function formatDate(iso) {
27
+ if (!iso)
28
+ return '-';
29
+ return iso.slice(0, 10);
30
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { formatDuration, formatDate, itunesFetch } from './utils.js';
3
+ describe('formatDuration', () => {
4
+ it('formats typical duration in ms', () => {
5
+ expect(formatDuration(3661000)).toBe('61:01');
6
+ });
7
+ it('pads single-digit seconds', () => {
8
+ expect(formatDuration(65000)).toBe('1:05');
9
+ });
10
+ it('formats exact minutes', () => {
11
+ expect(formatDuration(3600000)).toBe('60:00');
12
+ });
13
+ it('rounds fractional milliseconds', () => {
14
+ expect(formatDuration(3600500)).toBe('60:01');
15
+ });
16
+ it('returns dash for zero', () => {
17
+ expect(formatDuration(0)).toBe('-');
18
+ });
19
+ it('returns dash for NaN', () => {
20
+ expect(formatDuration(NaN)).toBe('-');
21
+ });
22
+ });
23
+ describe('formatDate', () => {
24
+ it('extracts YYYY-MM-DD from ISO string', () => {
25
+ expect(formatDate('2026-03-19T12:00:00.000Z')).toBe('2026-03-19');
26
+ });
27
+ it('handles date-only string', () => {
28
+ expect(formatDate('2025-01-01')).toBe('2025-01-01');
29
+ });
30
+ it('returns dash for empty string', () => {
31
+ expect(formatDate('')).toBe('-');
32
+ });
33
+ it('returns dash for undefined', () => {
34
+ expect(formatDate(undefined)).toBe('-');
35
+ });
36
+ });
37
+ describe('itunesFetch', () => {
38
+ beforeEach(() => {
39
+ vi.restoreAllMocks();
40
+ });
41
+ it('returns parsed JSON on success', async () => {
42
+ const mockData = { resultCount: 1, results: [{ collectionId: 123 }] };
43
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
44
+ ok: true,
45
+ json: () => Promise.resolve(mockData),
46
+ }));
47
+ const result = await itunesFetch('/search?term=test&media=podcast&limit=1');
48
+ expect(result).toEqual(mockData);
49
+ });
50
+ it('throws CliError on HTTP error', async () => {
51
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
52
+ ok: false,
53
+ status: 403,
54
+ }));
55
+ await expect(itunesFetch('/search?term=test')).rejects.toThrow('iTunes API HTTP 403');
56
+ });
57
+ });
@@ -38,6 +38,23 @@ export const historyCommand = cli({
38
38
  if (items.length === 0) {
39
39
  return [{ Index: 0, Title: 'No history found. Ensure the sidebar is visible.' }];
40
40
  }
41
- return items;
41
+ const dateHeaders = /^(today|yesterday|last week|last month|last year|this week|this month|older|previous \d+ days|\d+ days ago)$/i;
42
+ const numericOnly = /^[\d\s]+$/;
43
+ const modelPath = /^[\w.-]+\/[\w.-]/;
44
+ const seen = new Set();
45
+ const deduped = items.filter((item) => {
46
+ const t = item.Title.trim();
47
+ if (dateHeaders.test(t))
48
+ return false;
49
+ if (numericOnly.test(t))
50
+ return false;
51
+ if (modelPath.test(t))
52
+ return false;
53
+ if (seen.has(t))
54
+ return false;
55
+ seen.add(t);
56
+ return true;
57
+ }).map((item, i) => ({ Index: i + 1, Title: item.Title }));
58
+ return deduped;
42
59
  },
43
60
  });
@@ -12,28 +12,40 @@ export const channelsCommand = cli({
12
12
  const channels = await page.evaluate(`
13
13
  (function() {
14
14
  const results = [];
15
- // Discord channel list items
16
- const items = document.querySelectorAll('[data-list-item-id*="channels___"], [class*="containerDefault_"]');
17
-
18
- items.forEach((item, i) => {
19
- const nameEl = item.querySelector('[class*="name_"], [class*="channelName"]');
20
- const name = nameEl ? nameEl.textContent.trim() : (item.textContent || '').trim().substring(0, 50);
21
-
22
- if (!name || name.length < 1) return;
23
-
24
- // Detect channel type from icon or aria-label
25
- const iconEl = item.querySelector('[class*="icon"]');
26
- let type = 'Text';
27
- if (iconEl) {
28
- const cls = iconEl.className || '';
29
- if (cls.includes('voice') || cls.includes('speaker')) type = 'Voice';
30
- else if (cls.includes('forum')) type = 'Forum';
31
- else if (cls.includes('announcement')) type = 'Announcement';
32
- }
33
-
34
- results.push({ Index: i + 1, Channel: name, Type: type });
15
+
16
+ // Discord channel links: <a> tags with href like /channels/GUILD/CHANNEL
17
+ const links = document.querySelectorAll('a[href*="/channels/"][data-list-item-id^="channels___"]');
18
+
19
+ links.forEach(function(el) {
20
+ var label = el.getAttribute('aria-label') || '';
21
+ if (!label) return;
22
+
23
+ // Skip categories
24
+ if (/[((]category[))]/i.test(label)) return;
25
+
26
+ // Strip any leading status prefix before the first comma (e.g. "unread, ", locale-agnostic)
27
+ var commaIdx = label.search(/[,,]/);
28
+ var cleaned = commaIdx !== -1 ? label.slice(commaIdx + 1).trimStart() : label;
29
+
30
+ // Extract name and type from "name (type)" or "name(type)"
31
+ var m = cleaned.match(/^(.+?)\s*[((](.+?)[))]\s*$/);
32
+ // If no type annotation found, skip — real channels always have "(Type channel)" in aria-label
33
+ if (!m) return;
34
+ var name = m[1].trim();
35
+ var rawType = m[2].toLowerCase();
36
+
37
+ // Discord channel names are ASCII-only; skip placeholder entries (e.g. locked channels)
38
+ if (!name || !/^[\x20-\x7E]+$/.test(name)) return;
39
+
40
+ var type = 'Text';
41
+ if (rawType.includes('voice')) type = 'Voice';
42
+ else if (rawType.includes('forum')) type = 'Forum';
43
+ else if (rawType.includes('announcement')) type = 'Announcement';
44
+ else if (rawType.includes('stage')) type = 'Stage';
45
+
46
+ results.push({ Index: results.length + 1, Channel: name, Type: type });
35
47
  });
36
-
48
+
37
49
  return results;
38
50
  })()
39
51
  `);
@@ -0,0 +1 @@
1
+ export declare const likeCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,25 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const likeCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'like',
5
+ description: 'Like/unlike the currently playing song',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Status'],
11
+ func: async (page) => {
12
+ const result = await page.evaluate(`
13
+ (function() {
14
+ // The like/heart button in the player bar
15
+ const btn = document.querySelector('.m-playbar .icn-love, .m-playbar [class*="like"], .m-player [class*="love"], [data-action="like"]');
16
+ if (!btn) return 'Like button not found';
17
+
18
+ const wasLiked = btn.classList.contains('loved') || btn.classList.contains('active') || btn.getAttribute('data-liked') === 'true';
19
+ btn.click();
20
+ return wasLiked ? 'Unliked' : 'Liked';
21
+ })()
22
+ `);
23
+ return [{ Status: result }];
24
+ },
25
+ });
@@ -0,0 +1 @@
1
+ export declare const lyricsCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,47 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const lyricsCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'lyrics',
5
+ description: 'Get the lyrics of the currently playing song',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Line'],
11
+ func: async (page) => {
12
+ // Try to open lyrics panel if not visible
13
+ await page.evaluate(`
14
+ (function() {
15
+ const btn = document.querySelector('.m-playbar .icn-lyric, [class*="lyric-btn"], [data-action="lyric"]');
16
+ if (btn) btn.click();
17
+ })()
18
+ `);
19
+ await page.wait(1);
20
+ const lyrics = await page.evaluate(`
21
+ (function() {
22
+ // Look for lyrics container
23
+ const selectors = [
24
+ '.m-lyric p, .m-lyric [class*="line"]',
25
+ '[class*="lyric-content"] p',
26
+ '.listlyric li',
27
+ '[class*="lyric"] [class*="line"]',
28
+ '.j-lyric p',
29
+ ];
30
+
31
+ for (const sel of selectors) {
32
+ const nodes = document.querySelectorAll(sel);
33
+ if (nodes.length > 0) {
34
+ return Array.from(nodes).map(n => (n.textContent || '').trim()).filter(l => l.length > 0);
35
+ }
36
+ }
37
+
38
+ // Fallback: try the body text for any lyrics-like content
39
+ return [];
40
+ })()
41
+ `);
42
+ if (lyrics.length === 0) {
43
+ return [{ Line: 'No lyrics found. Try opening the lyrics panel first.' }];
44
+ }
45
+ return lyrics.map((line) => ({ Line: line }));
46
+ },
47
+ });
@@ -0,0 +1 @@
1
+ export declare const nextCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,26 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const nextCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'next',
5
+ description: 'Skip to the next song',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Status'],
11
+ func: async (page) => {
12
+ const clicked = await page.evaluate(`
13
+ (function() {
14
+ const btn = document.querySelector('.m-playbar .btnfwd, .m-playbar [class*="next"], .m-player .btn-next, [data-action="next"]');
15
+ if (btn) { btn.click(); return true; }
16
+ return false;
17
+ })()
18
+ `);
19
+ if (!clicked) {
20
+ // Fallback: Ctrl+Right is common next-track shortcut
21
+ await page.pressKey('Control+ArrowRight');
22
+ }
23
+ await page.wait(1);
24
+ return [{ Status: 'Skipped to next song' }];
25
+ },
26
+ });
@@ -0,0 +1 @@
1
+ export declare const playCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,26 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const playCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'play',
5
+ description: 'Toggle play/pause for the current song',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Status'],
11
+ func: async (page) => {
12
+ // Click the play/pause button or use Space key
13
+ const clicked = await page.evaluate(`
14
+ (function() {
15
+ const btn = document.querySelector('.m-playbar .btnp, .m-playbar [class*="play"], .m-player .btn-play, [data-action="play"]');
16
+ if (btn) { btn.click(); return true; }
17
+ return false;
18
+ })()
19
+ `);
20
+ if (!clicked) {
21
+ // Fallback: use Space key which is the universal play/pause shortcut
22
+ await page.pressKey('Space');
23
+ }
24
+ return [{ Status: 'Play/Pause toggled' }];
25
+ },
26
+ });
@@ -0,0 +1 @@
1
+ export declare const playingCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,59 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const playingCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'playing',
5
+ description: 'Get the currently playing song info',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Title', 'Artist', 'Album', 'Duration', 'Progress'],
11
+ func: async (page) => {
12
+ const info = await page.evaluate(`
13
+ (function() {
14
+ // NeteaseMusic player bar is at the bottom
15
+ const selectors = {
16
+ title: '.m-playbar .j-song .name, .m-playbar .song .name, [class*="playing"] .name, .m-player .name',
17
+ artist: '.m-playbar .j-song .by, .m-playbar .song .by, [class*="playing"] .artist, .m-player .by',
18
+ album: '.m-playbar .j-song .album, [class*="playing"] .album',
19
+ time: '.m-playbar .j-dur, .m-playbar .time, .m-player .time',
20
+ progress: '.m-playbar .barbg .rng, .m-playbar [role="progressbar"], .m-player [class*="progress"]',
21
+ };
22
+
23
+ function getText(sel) {
24
+ for (const s of sel.split(',')) {
25
+ const el = document.querySelector(s.trim());
26
+ if (el) return (el.textContent || el.innerText || '').trim();
27
+ }
28
+ return '';
29
+ }
30
+
31
+ const title = getText(selectors.title);
32
+ const artist = getText(selectors.artist);
33
+ const album = getText(selectors.album);
34
+ const time = getText(selectors.time);
35
+
36
+ // Try to get playback progress from the progress bar width
37
+ let progress = '';
38
+ const bar = document.querySelector('.m-playbar .barbg .rng, [class*="progress"] [class*="played"]');
39
+ if (bar) {
40
+ const style = bar.getAttribute('style') || '';
41
+ const match = style.match(/width:\\s*(\\d+\\.?\\d*)%/);
42
+ if (match) progress = match[1] + '%';
43
+ }
44
+
45
+ if (!title) {
46
+ // Fallback: try document title which often contains "songName - NeteaseMusic"
47
+ const docTitle = document.title;
48
+ if (docTitle && !docTitle.includes('NeteaseMusic')) {
49
+ return { Title: docTitle, Artist: '', Album: '', Duration: '', Progress: '' };
50
+ }
51
+ return { Title: 'No song playing', Artist: '—', Album: '—', Duration: '—', Progress: '—' };
52
+ }
53
+
54
+ return { Title: title, Artist: artist, Album: album, Duration: time, Progress: progress };
55
+ })()
56
+ `);
57
+ return [info];
58
+ },
59
+ });
@@ -0,0 +1 @@
1
+ export declare const playlistCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,46 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const playlistCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'playlist',
5
+ description: 'Show the current playback queue / playlist',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Index', 'Title', 'Artist'],
11
+ func: async (page) => {
12
+ // Open the playlist panel (usually a button at the bottom bar)
13
+ await page.evaluate(`
14
+ (function() {
15
+ const btn = document.querySelector('.m-playbar .icn-list, .m-playbar [class*="playlist"], [data-action="playlist"], .m-playbar .btnlist');
16
+ if (btn) btn.click();
17
+ })()
18
+ `);
19
+ await page.wait(1);
20
+ const items = await page.evaluate(`
21
+ (function() {
22
+ const results = [];
23
+ // Playlist panel items
24
+ const rows = document.querySelectorAll('.m-playlist li, [class*="playlist-panel"] li, .listlyric li, .j-playlist li');
25
+
26
+ rows.forEach((row, i) => {
27
+ const nameEl = row.querySelector('.name, [class*="name"], a, span:first-child');
28
+ const artistEl = row.querySelector('.by, [class*="artist"], .ar');
29
+
30
+ const title = nameEl ? (nameEl.getAttribute('title') || nameEl.textContent || '').trim() : (row.textContent || '').trim();
31
+ const artist = artistEl ? (artistEl.textContent || '').trim() : '';
32
+
33
+ if (title && title.length > 0) {
34
+ results.push({ Index: i + 1, Title: title.substring(0, 80), Artist: artist });
35
+ }
36
+ });
37
+
38
+ return results;
39
+ })()
40
+ `);
41
+ if (items.length === 0) {
42
+ return [{ Index: 0, Title: 'Playlist is empty or panel not open', Artist: '—' }];
43
+ }
44
+ return items;
45
+ },
46
+ });
@@ -0,0 +1 @@
1
+ export declare const prevCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,25 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const prevCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'prev',
5
+ description: 'Go back to the previous song',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Status'],
11
+ func: async (page) => {
12
+ const clicked = await page.evaluate(`
13
+ (function() {
14
+ const btn = document.querySelector('.m-playbar .btnbak, .m-playbar [class*="prev"], .m-player .btn-prev, [data-action="prev"]');
15
+ if (btn) { btn.click(); return true; }
16
+ return false;
17
+ })()
18
+ `);
19
+ if (!clicked) {
20
+ await page.pressKey('Control+ArrowLeft');
21
+ }
22
+ await page.wait(1);
23
+ return [{ Status: 'Went to previous song' }];
24
+ },
25
+ });
@@ -0,0 +1 @@
1
+ export declare const searchCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,52 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const searchCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'search',
5
+ description: 'Search for songs, artists, albums, or playlists',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [{ name: 'query', required: true, positional: true, help: 'Search query' }],
10
+ columns: ['Index', 'Title', 'Artist'],
11
+ func: async (page, kwargs) => {
12
+ const query = kwargs.query;
13
+ // Focus and fill the search box
14
+ await page.evaluate(`
15
+ (function(q) {
16
+ const input = document.querySelector('.m-search input, #srch, [class*="search"] input, input[type="search"]');
17
+ if (!input) throw new Error('Search input not found');
18
+ input.focus();
19
+ const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
20
+ setter.call(input, q);
21
+ input.dispatchEvent(new Event('input', { bubbles: true }));
22
+ })(${JSON.stringify(query)})
23
+ `);
24
+ await page.pressKey('Enter');
25
+ await page.wait(2);
26
+ // Scrape results
27
+ const results = await page.evaluate(`
28
+ (function() {
29
+ const items = [];
30
+ // Song list items in search results
31
+ const rows = document.querySelectorAll('.srchsongst li, .m-table tbody tr, [class*="songlist"] [class*="item"], table tbody tr');
32
+
33
+ rows.forEach((row, i) => {
34
+ if (i >= 20) return;
35
+ const nameEl = row.querySelector('.sn, .name a, [class*="songName"], td:nth-child(2) a, b[title]');
36
+ const artistEl = row.querySelector('.ar, .artist, [class*="artist"], td:nth-child(4) a, td:nth-child(3) a');
37
+
38
+ const title = nameEl ? (nameEl.getAttribute('title') || nameEl.textContent || '').trim() : '';
39
+ const artist = artistEl ? (artistEl.getAttribute('title') || artistEl.textContent || '').trim() : '';
40
+
41
+ if (title) items.push({ Index: i + 1, Title: title, Artist: artist });
42
+ });
43
+
44
+ return items;
45
+ })()
46
+ `);
47
+ if (results.length === 0) {
48
+ return [{ Index: 0, Title: `No results for "${query}"`, Artist: '—' }];
49
+ }
50
+ return results;
51
+ },
52
+ });
@@ -0,0 +1 @@
1
+ export declare const statusCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,16 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const statusCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'status',
5
+ description: 'Check CDP connection to NeteaseMusic Desktop',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [],
10
+ columns: ['Status', 'Url', 'Title'],
11
+ func: async (page) => {
12
+ const url = await page.evaluate('window.location.href');
13
+ const title = await page.evaluate('document.title');
14
+ return [{ Status: 'Connected', Url: url, Title: title }];
15
+ },
16
+ });
@@ -0,0 +1 @@
1
+ export declare const volumeCommand: import("../../registry.js").CliCommand;
@@ -0,0 +1,54 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ export const volumeCommand = cli({
3
+ site: 'neteasemusic',
4
+ name: 'volume',
5
+ description: 'Get or set the volume level (0-100)',
6
+ domain: 'localhost',
7
+ strategy: Strategy.UI,
8
+ browser: true,
9
+ args: [
10
+ { name: 'level', required: false, positional: true, help: 'Volume level 0-100 (omit to read current)' },
11
+ ],
12
+ columns: ['Status', 'Volume'],
13
+ func: async (page, kwargs) => {
14
+ const level = kwargs.level;
15
+ if (!level) {
16
+ // Read current volume
17
+ const vol = await page.evaluate(`
18
+ (function() {
19
+ const bar = document.querySelector('.m-playbar .vol .barbg .rng, [class*="volume"] [class*="progress"], [class*="volume"] [class*="played"]');
20
+ if (bar) {
21
+ const style = bar.getAttribute('style') || '';
22
+ const match = style.match(/width:\\s*(\\d+\\.?\\d*)%/);
23
+ if (match) return match[1];
24
+ }
25
+
26
+ const vol = document.querySelector('.m-playbar .j-vol, [class*="volume-value"]');
27
+ if (vol) return vol.textContent.trim();
28
+
29
+ return 'Unknown';
30
+ })()
31
+ `);
32
+ return [{ Status: 'Current', Volume: vol + '%' }];
33
+ }
34
+ // Set volume by clicking on the volume bar at the right position
35
+ const targetVol = Math.max(0, Math.min(100, parseInt(level, 10)));
36
+ await page.evaluate(`
37
+ (function(target) {
38
+ const bar = document.querySelector('.m-playbar .vol .barbg, [class*="volume-bar"], [class*="volume"] [class*="track"]');
39
+ if (!bar) return;
40
+
41
+ const rect = bar.getBoundingClientRect();
42
+ const x = rect.left + (rect.width * target / 100);
43
+ const y = rect.top + rect.height / 2;
44
+
45
+ bar.dispatchEvent(new MouseEvent('click', {
46
+ clientX: x,
47
+ clientY: y,
48
+ bubbles: true,
49
+ }));
50
+ })(${targetVol})
51
+ `);
52
+ return [{ Status: 'Set', Volume: targetVol + '%' }];
53
+ },
54
+ });
@@ -0,0 +1 @@
1
+ export {};