#Meting API
Meting 类是与 Meting API 交互的核心类,提供所有音乐资源的获取方法。
#构造函数
declare class class Meting Meting {
constructor(server: string | undefined server ?: string);
}| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
server | string | 'netease' | 音乐平台,如 netease 等 |
#配置方法
#site
设置音乐平台。
declare class class Meting Meting {
Meting.site(server: string): this site (server: string server : string): this;
}| 参数 | 类型 | 说明 |
|---|---|---|
server | string | 平台名称,如 netease 等 |
#api
设置自定义 API 地址。默认使用 https://api.qijieya.cn/meting/。
declare class class Meting Meting {
Meting.api(url: string): this api (url: string url : string): this;
}| 参数 | 类型 | 说明 |
|---|---|---|
url | string | Meting API 地址 |
#cookie
设置 Cookie,用于需要认证的请求。
declare class class Meting Meting {
Meting.cookie(cookie: string): this cookie (cookie: string cookie : string): this;
}| 参数 | 类型 | 说明 |
|---|---|---|
cookie | string | Cookie 字符串 |
#format
启用或禁用格式化响应。启用后,返回的数据会统一为 Music 接口格式。
declare class class Meting Meting {
Meting.format(enable: boolean): this format (enable: boolean enable : boolean): this;
}| 参数 | 类型 | 说明 |
|---|---|---|
enable | boolean | 是否启用格式化 |
#数据方法
所有数据方法均返回 Promise<string>(JSON 字符串)。
#search
搜索歌曲。
interface SearchOptions {
SearchOptions.type?: number | undefined type ?: number;
SearchOptions.page?: number | undefined page ?: number;
SearchOptions.limit?: number | undefined limit ?: number;
}
declare class class Meting Meting {
Meting.search(keyword: string, options?: SearchOptions): Promise<string> search (keyword: string keyword : string, options: SearchOptions | undefined options ?: SearchOptions): interface Promise<T>Represents the completion of an asynchronous operation
Promise <string>;
}| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
keyword | string | — | 搜索关键词 |
options.type | number | 1 | 搜索类型 |
options.page | number | 1 | 页码 |
options.limit | number | 30 | 每页结果数 |
#song
获取单曲信息。
declare class class Meting Meting {
Meting.song(id: string | number): Promise<string> song (id: string | number id : string | number): interface Promise<T>Represents the completion of an asynchronous operation
Promise <string>;
}| 参数 | 类型 | 说明 |
|---|---|---|
id | string | number | 歌曲 ID |
#artist
获取歌手的歌曲列表。
declare class class Meting Meting {
Meting.artist(id: string | number, limit?: number): Promise<string> artist (id: string | number id : string | number, limit: number | undefined limit ?: number): interface Promise<T>Represents the completion of an asynchronous operation
Promise <string>;
}| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | string | number | — | 歌手 ID |
limit | number | 30 | 返回数量 |
#playlist
获取歌单中的所有歌曲。
declare class class Meting Meting {
Meting.playlist(id: string | number): Promise<string> playlist (id: string | number id : string | number): interface Promise<T>Represents the completion of an asynchronous operation
Promise <string>;
}| 参数 | 类型 | 说明 |
|---|---|---|
id | string | number | 歌单 ID |
#url
获取歌曲播放 URL。
declare class class Meting Meting {
Meting.url(id: string | number, bitrate?: number): Promise<string> url (id: string | number id : string | number, bitrate: number | undefined bitrate ?: number): interface Promise<T>Represents the completion of an asynchronous operation
Promise <string>;
}| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | string | number | — | 歌曲 ID |
bitrate | number | 320 | 音频码率 |
#lyric
获取歌词信息。
declare class class Meting Meting {
Meting.lyric(id: string | number): Promise<string> lyric (id: string | number id : string | number): interface Promise<T>Represents the completion of an asynchronous operation
Promise <string>;
}| 参数 | 类型 | 说明 |
|---|---|---|
id | string | number | 歌词 ID |
#pic
获取封面图片信息。
declare class class Meting Meting {
Meting.pic(id: string | number, size?: number): Promise<string> pic (id: string | number id : string | number, size: number | undefined size ?: number): interface Promise<T>Represents the completion of an asynchronous operation
Promise <string>;
}| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | string | number | — | 图片 ID |
size | number | 300 | 图片尺寸(px) |
#类型定义
#SearchOptions
interface SearchOptions {
SearchOptions.type?: number | undefined type ?: number; // 搜索类型:1=歌曲, 100=歌手, 1000=专辑, 1004=歌单, 1006=歌词, 1009=用户
SearchOptions.page?: number | undefined page ?: number; // 页码,默认 1
SearchOptions.limit?: number | undefined limit ?: number; // 每页结果数,默认 30
}#Music
interface Music {
Music.id: string id : string; // 歌曲 ID
Music.name: string name : string; // 歌曲名称
Music.artist: string[] artist : string[]; // 艺术家列表
Music.album: string album : string; // 专辑名称
Music.pic_id: string pic_id : string; // 封面图片 ID
Music.pic: string pic : string; // 封面图片 URL
Music.url_id: string url_id : string; // 播放 URL 或 ID
Music.lyric_id: string lyric_id : string; // 歌词 ID
Music.lrc: string lrc : string; // 歌词 URL
Music.source: string source : string; // 来源平台
}#MusicResponse
interface MusicResponse {
MusicResponse.id: string id : string;
MusicResponse.name: string name : string;
MusicResponse.artist: string[] artist : string[];
MusicResponse.album: string album : string;
MusicResponse.pic: string pic : string;
MusicResponse.url: string url : string;
MusicResponse.lrc: string lrc : string;
MusicResponse.source: string source : string;
[key: string key : string]: unknown;
}#完整示例
import { class Meting Meting } 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 searchResults: any searchResults = 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 ('周杰伦', { SearchOptions.type?: number | undefined type : 1, SearchOptions.limit?: number | undefined limit : 5 })
);
// 获取歌曲详情
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'));
// 获取歌单
const const playlist: any playlist = 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'));
// 获取播放 URL
const const urlData: any urlData = 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.url(id: string | number, bitrate?: number): Promise<string> url ('1372188635', 320));
// 获取歌词
const const lyricData: any lyricData = 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.lyric(id: string | number): Promise<string> lyric ('1372188635'));
// 获取封面
const const picData: any picData = 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.pic(id: string | number, size?: number): Promise<string> pic ('1372188635', 300));