Files
Meting/README.md
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 <noreply@anthropic.com>

* refactor: 重构为 Provider 模式架构

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

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

Co-Authored-By: Claude <noreply@anthropic.com>

* 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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>

* 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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Happy <yesreply@happy.engineering>
2025-10-10 13:00:21 +08:00

7.6 KiB

Meting

🍰 A powerful music API framework for Node.js

Introduction

Meting is a powerful music API framework designed to accelerate music-related development. This is the Node.js version of the original PHP Meting project, providing unified APIs for multiple music platforms.

Features

  • 🎵 Multi-Platform Support - Supports NetEase Cloud Music, Tencent Music, Xiami, KuGou, Baidu Music, and Kuwo
  • 🚀 Lightweight & Fast - Zero external dependencies, built with Node.js native modules only
  • 📱 Modern Async/Await - Promise-based APIs with full async/await support
  • 🔄 Unified Interface - Standardized data format across all music platforms
  • 🔐 Built-in Encryption - Platform-specific encryption and signing built-in
  • Chain-able API - Fluent interface design for elegant code

Requirements

  • Node.js >= 12.0.0
  • No external dependencies required

Installation

Install via npm:

npm install @meting/core

Or via yarn:

yarn add @meting/core

Quick Start

Basic Usage

import Meting from '@meting/core';

// Initialize with a music platform
const meting = new Meting('netease'); // 'netease', 'tencent', 'xiami', 'kugou', 'baidu', 'kuwo'

// Enable data formatting for consistent output
meting.format(true);

// Search for songs
try {
  const searchResult = await meting.search('Hello Adele', { page: 1, limit: 10 });
  const songs = JSON.parse(searchResult);
  console.log(songs);
} catch (error) {
  console.error('Search failed:', error);
}

Comprehensive Example

import Meting from '@meting/core';

async function musicExample() {
  const meting = new Meting('netease');
  meting.format(true);
  
  try {
    // 1. Search for songs
    const searchResult = await meting.search('Hello Adele');
    const songs = JSON.parse(searchResult);
    
    if (songs.length > 0) {
      const song = songs[0];
      console.log(`Found: ${song.name} by ${song.artist.join(', ')}`);
      
      // 2. Get song details
      const details = await meting.song(song.id);
      console.log('Song details:', JSON.parse(details));
      
      // 3. Get streaming URL
      const urlInfo = await meting.url(song.url_id, 320); // 320kbps
      console.log('Streaming URL:', JSON.parse(urlInfo));
      
      // 4. Get lyrics
      const lyrics = await meting.lyric(song.lyric_id);
      console.log('Lyrics:', JSON.parse(lyrics));
      
      // 5. Get album cover
      const cover = await meting.pic(song.pic_id, 300); // 300x300
      console.log('Album cover:', JSON.parse(cover));
    }
    
    // Switch platform and search again
    meting.site('tencent');
    const tencentResult = await meting.search('周杰伦');
    console.log('Tencent results:', JSON.parse(tencentResult));
    
  } catch (error) {
    console.error('Error:', error);
  }
}

musicExample();

API Documentation

Constructor

const meting = new Meting(server);
  • server (string): Music platform ('netease', 'tencent', 'xiami', 'kugou', 'baidu', 'kuwo')

Core Methods

Platform Management

meting.site(server)    // Switch music platform
meting.cookie(cookie)  // Set platform-specific cookies
meting.format(enable)  // Enable/disable data formatting

Search & Discovery

// Search for songs, albums, or artists
await meting.search(keyword, {
  type: 1,
  page: 1,
  limit: 30,
});

Search Options

  • type (number, optional) - Search category for providers that support it. NetEase uses 1 for songs (default), 10 for albums, 100 for artists, etc.
  • page (number, optional) - Page number starting from 1. Defaults to 1.
  • limit (number, optional) - Number of results per page. Defaults to 30.

Music Information

await meting.song(id)           // Get song details
await meting.album(id)          // Get album information
await meting.artist(id, limit)  // Get artist's songs
await meting.playlist(id)       // Get playlist content

Media Resources

await meting.url(id, bitrate)   // Get streaming URL
await meting.lyric(id)          // Get song lyrics
await meting.pic(id, size)      // Get album artwork

Supported Platforms

Platform Code Search Song Album Artist Playlist URL Lyric Picture
NetEase Cloud Music netease
Tencent Music tencent
Xiami Music xiami
KuGou Music kugou
Baidu Music baidu
Kuwo Music kuwo

Data Format

When format(true) is enabled, all platforms return standardized JSON:

{
  "id": "35847388",
  "name": "Hello",
  "artist": ["Adele"],
  "album": "Hello",
  "pic_id": "1407374890649284",
  "url_id": "35847388", 
  "lyric_id": "35847388",
  "source": "netease"
}

Development

Running Examples

# Install dependencies
npm install

# Run the example
npm start
# or
npm run example

Running Tests

# Run tests for all platforms
npm test

Build from Source

# Build the library
npm run build

# Development mode with file watching
npm run dev

Error Handling

The library uses Promise-based error handling. Always wrap API calls in try-catch blocks:

try {
  const result = await meting.search('keyword');
  // Handle success
} catch (error) {
  console.error('API Error:', error);
  
  // Try fallback platform
  meting.site('tencent');
  const fallback = await meting.search('keyword');
}

Rate Limiting

To avoid being rate-limited by music platforms:

  • Add delays between consecutive requests
  • Don't make too many requests in a short time
  • Consider implementing request queuing for heavy usage
// Example: Add delay between requests
await new Promise(resolve => setTimeout(resolve, 2000));

Important Notes

  • Copyright Compliance: Respect music platform terms of service and copyright laws
  • Platform Changes: Music platform APIs may change without notice
  • Availability: Some features may be restricted based on geographical location
  • Rate Limits: Each platform has different rate limiting policies

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Meting Node.js © metowolf, Released under the MIT License.

Blog @meto · GitHub @metowolf · Twitter @metowolf


Made with ❤️ for the music community