Files
Meting/test/example.js
METO 041d6b56df refactor: 重构为 nodejs 语言 (#118)
* feat: migrate from PHP to Node.js implementation

- Replace PHP implementation with Node.js version
- Add Node.js package configuration (package.json, package-lock.json)
- Add Rollup build configuration for browser compatibility
- Update README with Node.js usage examples and API documentation
- Add comprehensive test suite for all supported platforms
- Add Claude Code development instructions (CLAUDE.md)
- Remove PHP-specific files (composer.json, src/Meting.php)
- Update GitHub workflows for Node.js environment

This migration maintains API compatibility while providing:
- Promise-based async/await support
- ES6 class design with method chaining
- Zero external dependencies (Node.js built-in modules only)
- Support for all existing music platforms (netease, tencent, xiami, kugou, baidu, kuwo)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* refactor: 重构为 Provider 模式架构

- 引入统一的 Provider 接口,实现平台解耦
- 将原有单体文件拆分为模块化 Provider 系统
- 实现真正的内部闭环设计,每个 Provider 独立处理编码/解码
- 优化构建系统,支持版本号注入和 TypeScript 定义生成
- 完善测试覆盖,支持独立平台测试
- 新增架构文档,详细说明设计模式和开发流程

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* fix: 修复 ES Module 导入问题,添加 package.json exports 配置

- 添加 module 字段指向 ESM 版本构建文件
- 添加 exports 字段支持双包发布模式
- 修正 main 字段路径格式
- 解决 import Meting from '@meting/core'; 导入失败问题

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>

* refactor: 简化网易云音乐架构并恢复 search option 参数支持

- 移除 WebAPI 支持,统一使用 EAPI 架构,简化代码结构
- 删除复杂的选项管理系统和全局配置
- 恢复 search 接口的 option 参数支持(type, page, limit)
- 优化构建配置和代码压缩设置
- 更新文档和测试以反映新的 API 结构

Breaking Changes:
- 移除 setOption() 方法
- 删除 WebAPI (weapi) 相关代码
- 简化 netease provider 为纯 EAPI 实现

🤖 Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Happy <[email protected]>
2025-10-10 13:00:21 +08:00

85 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Meting Node.js 使用示例
*/
import Meting from '../lib/meting.esm.js';
async function main() {
// 创建 Meting 实例
const meting = new Meting('netease'); // 可选: 'netease', 'tencent', 'xiami', 'kugou', 'baidu', 'kuwo'
// 开启数据格式化
meting.format(true);
console.log('=== Meting Node.js 示例 ===\n');
try {
// 1. 搜索歌曲
console.log('1. 搜索歌曲:');
const searchResult = await meting.search('烟火里的尘埃', { limit: 3 });
console.log('搜索结果:');
console.log(JSON.stringify(JSON.parse(searchResult), null, 2));
console.log('\n');
// 获取第一首歌的 ID
const songs = JSON.parse(searchResult);
if (songs.length > 0) {
const firstSong = songs[0];
console.log(`选择歌曲: ${firstSong.name} - ${firstSong.artist.join(', ')}\n`);
// 2. 获取歌曲详情
console.log('2. 获取歌曲详情:');
const songDetail = await meting.song(firstSong.id);
console.log('歌曲详情:');
console.log(JSON.stringify(JSON.parse(songDetail), null, 2));
console.log('\n');
// 3. 获取歌曲播放链接
console.log('3. 获取歌曲播放链接:');
const url = await meting.url(firstSong.url_id, 320);
console.log('播放链接:');
console.log(JSON.stringify(JSON.parse(url), null, 2));
console.log('\n');
// 4. 获取歌词
console.log('4. 获取歌词:');
const lyric = await meting.lyric(firstSong.lyric_id);
const lyricData = JSON.parse(lyric);
console.log('歌词预览前5行');
if (lyricData.lyric) {
const lines = lyricData.lyric.split('\n').slice(0, 5);
lines.forEach(line => {
if (line.trim()) console.log(line);
});
} else {
console.log('暂无歌词');
}
console.log('\n');
// 5. 获取封面图片
console.log('5. 获取封面图片:');
const pic = await meting.pic(firstSong.pic_id, 300);
console.log('封面图片:');
console.log(JSON.stringify(JSON.parse(pic), null, 2));
console.log('\n');
}
// 6. 切换到其他平台测试
console.log('6. 切换到腾讯音乐平台:');
meting.site('tencent');
const tencentSearch = await meting.search('邓紫棋', { limit: 2 });
console.log('腾讯音乐搜索结果:');
console.log(JSON.stringify(JSON.parse(tencentSearch), null, 2));
console.log('\n');
} catch (error) {
console.error('发生错误:', error);
}
}
// 运行示例
main().then(() => {
console.log('示例运行完成!');
}).catch(error => {
console.error('示例运行失败:', error);
});