#编程使用
Music Getter 不仅是一个 CLI 工具,也可以作为 Node.js 库集成到你的项目中。
#安装
npm install music-getter#快速开始
import { class Meting Meting , const download: DownloadManager download } from 'music-getter';
// 创建 Meting 实例
const const meting: Meting meting = new new Meting(server?: string): Meting Meting ('netease');
const meting: Meting meting .Meting.format(enable: boolean): Meting format (true);
// 搜索歌曲
const const results: any results = var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON .JSON.parse(text: string, reviver?: (this: any, key: string, value: any) => any): anyConverts a JavaScript Object Notation (JSON) string into an object.
@paramtext A valid JSON string.@paramreviver A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.@throws{SyntaxError} If text is not valid JSON. parse (await const meting: Meting meting .Meting.search(keyword: string, options?: SearchOptions): Promise<string> search ('Daylight', { SearchOptions.limit?: number | undefined limit : 10 }));
var console: Console console .Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log (const results: any results );
// 获取歌曲详情
const const song: any song = var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON .JSON.parse(text: string, reviver?: (this: any, key: string, value: any) => any): anyConverts a JavaScript Object Notation (JSON) string into an object.
@paramtext A valid JSON string.@paramreviver A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.@throws{SyntaxError} If text is not valid JSON. parse (await const meting: Meting meting .Meting.song(id: string | number): Promise<string> song ('1372188635'));
var console: Console console .Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log (const song: any song );
// 下载歌曲
const download: DownloadManager download .DownloadManager.add(url: string | (() => Promise<string>), output: string): void add (const song: any song [0].url_id, './output.mp3');
await const download: DownloadManager download .DownloadManager.startAll(): Promise<void> startAll ();#核心模块
Music Getter 提供两个核心模块:
- Meting 类 — 音乐资源获取客户端,支持搜索、获取歌曲/歌单/歌词/封面等
- download 实例 — 下载管理器,支持队列下载和进度显示
详细的 API 参考请查看:
- Meting API 文档 — 完整的构造函数、配置方法、数据方法和类型定义
- Download API 文档 — 完整的下载管理方法和示例
#示例:批量下载歌单
import { class Meting Meting , const download: DownloadManager download } from 'music-getter';
const const meting: Meting meting = new new Meting(server?: string): Meting Meting ('netease');
const meting: Meting meting .Meting.format(enable: boolean): Meting format (true);
// 获取歌单
const const songs: any songs = var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON .JSON.parse(text: string, reviver?: (this: any, key: string, value: any) => any): anyConverts a JavaScript Object Notation (JSON) string into an object.
@paramtext A valid JSON string.@paramreviver A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.@throws{SyntaxError} If text is not valid JSON. parse (await const meting: Meting meting .Meting.playlist(id: string | number): Promise<string> playlist ('7697114803'));
// 添加下载任务
for (const const song: any song of const songs: any songs ) {
const download: DownloadManager download .DownloadManager.add(url: string | (() => Promise<string>), output: string): void add (const song: any song .url_id, `./downloads/${const song: any song .name}.mp3`);
}
// 开始下载
var console: Console console .Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log (`开始下载 ${const download: DownloadManager download .DownloadManager.getCount(): number getCount ()} 首歌曲...`);
await const download: DownloadManager download .DownloadManager.startAll(): Promise<void> startAll ();#自定义 API
如果你需要部署自己的 Meting API 服务,请参考 自定义 API 文档。
