分享⼀个⾳乐API接⼝
直接上源码C#的,使⽤其他语⾔的,直接看调⽤的API地址就好。
public class BaiduMusicAPI
{
/// <summary>
/// 搜索歌曲解析⽹页的⽅式
/// </summary>
/// <param name="key"></param>
public static List<MMusic> Search(string key, int page)
{
List<MMusic> musics = new List<MMusic>();
if (page <= 0)
{
page = 1;param name
}
// music.baidu/search/song?s=1&key=%E5%87%89%E5%87%89&jump=0&start=0&size=20&third_type=0
string url = string.Format("music.baidu/search/song?s=1&key={0}&jump=0&start={1}&size=20&third_type=0", key, (page - 1) * 20);
MyHttpClient client = new MyHttpClient(url);
string html = client.ExecuteGet();
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
HtmlNode node = doc.DocumentNode;
HtmlNode resultdiv = node.SelectSingleNode("//div[@monkey='result-song']/div");
HtmlNodeCollection list = resultdiv.SelectNodes("//div[@class='song-item clearfix yyr-song']");
MMusic model = null;
for (int i = 0; i < list.Count; i++)
{
model = new MMusic();
HtmlNode temp = list[i];
string title = temp.SelectSingleNode("//span[@class='song-title']/a/em").InnerText;
string singer = temp.SelectSingleNode("//span[@class='singer']/span[@class='author_list']/a").GetAttributeValue("title", "");
string playurl = temp.SelectSingleNode("//a[@class='list-micon icon-play']").GetAttributeValue("href", "");
model.Title = title;
model.Singer = singer;
model.PlayUrl = playurl;
musics.Add(model);
}
return musics;
}
// 获取列表
// 参数: type = 1-新歌榜,2-热歌榜,11-摇滚榜,12-爵⼠,16-流⾏,21-欧美⾦曲榜,22-经典⽼歌榜,23-情歌对唱榜,24-影视⾦曲榜,25-⽹络歌曲榜
// size = 10 //返回条⽬数量
// offset = 0 //获取偏移
// tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.billboard.billList&type=1&size=10&offset=0
/// <summary>
/// 获取列表 type = 1-新歌榜,2-热歌榜....
/// </summary>
/// <param name="offset"></param>
/// <returns></returns>
public static MSongList GetSongList(int type, int size, int offset)
{
MSongList list = new MSongList();
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.billboard.billLis
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.billboar
MyHttpClient client = new MyHttpClient(url);
string html = client.ExecuteGet();
list = JsonConvert.DeserializeObject<MSongList>(html);
return list;
}
// 搜索
// 参数:query = '' //搜索关键字
// tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&meth
od=baidu.ting.search.catalogSug&query=%E4%B8%80%
/// <summary>
/// 搜索歌名或歌⼿
/// </summary>
/// <param name="key"></param>
public static MQuerySong QuerySong(string key)
{
MQuerySong model = new MQuerySong();
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.search.catalog MyHttpClient client = new MyHttpClient(url);
string html = client.ExecuteGet();
html = html.Replace("(", string.Empty).Replace(");", string.Empty);
model = JsonConvert.DeserializeObject<MQuerySong>(html);
return model;
}
// 播放
// 参数:songid = 877578 //歌曲id
// tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.song.play&songid=877578
/// <summary>
/// 播放歌曲信息
/// </summary>
/// <param name="songid"></param>
/// <returns></returns>
public static MPlaySong PlaySong(string songid)
{
MPlaySong model = new MPlaySong();
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.song.play&son MyHttpClient client = new MyHttpClient(url);
string html = client.ExecuteGet();
html = html.Replace("(", string.Empty).Replace(");", string.Empty);
model = JsonConvert.DeserializeObject<MPlaySong>(html);
return model;
}
// 歌词
// 参数:songid = 877578 //歌曲id
// tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.song.lry&songid=877578
/// <summary>
/// 歌词信息
/// </summary>
/// <param name="songid"></param>
/// <returns></returns>
public static MPlaySongLrc PlaySongLRC(string songid)
{
MPlaySongLrc model = new MPlaySongLrc();
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.song.lry&songi MyHttpClient client = new MyHttpClient(url);
string html = client.ExecuteGet();
model = JsonConvert.DeserializeObject<MPlaySongLrc>(html);
return model;
}
// 下载
// 参数: songid = 877578//歌曲id
// _t = 1430215999,, //时间戳
// tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.song.downWeb&songid=73866069&bit=2
/
// <summary>
/// 下载歌曲到本地不可⽤
/// </summary>
/// <param name="songid"></param>
/// <returns></returns>
public static string DownLoadSong(string songid, string filepath)
{
string _t = StringUtils.GetTimeStamp(true);
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.ting.song.downWeb
MyHttpClient client = new MyHttpClient(url, filepath, true);
string path = client.HttpDownloadFile();
return path;
}
/// <summary>
/// 通过播放信息中的url去下载
/// </summary>
/// <param name="url"></param>
/// <param name="filepath"></param>
/// <param name="api"></param>
/// <returns></returns>
public static string DownLoadSong(string url, string filepath, bool api)
{
MyHttpClient client = new MyHttpClient(url, filepath, true);
string path = client.HttpDownloadFile();
return path;
}
// 歌⼿信息
// 参数: tinguid = 877578 //歌⼿ting id
// tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.Info&tinguid=877578
/// <summary>
/// 歌⼿信息
/// </summary>
/// <param name="ting_id"></param>
/// <returns></returns>
public static MArtistInfo GetArtistInfo(string ting_id)
{
MArtistInfo model = new MArtistInfo();
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.Info&t MyHttpClient client = new MyHttpClient(url);
string json = client.ExecuteGet();
json = json.Replace("(", string.Empty).Replace(");", string.Empty);
model = JsonConvert.DeserializeObject<MArtistInfo>(json);
return model;
}
// 歌⼿歌曲列表
// 参数: tinguid = 877578//歌⼿ting id
// limits = 6//返回条⽬数量
//
// tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.SongList&tinguid=110942340&lim
/// <summary>
/// 获取歌⼿歌曲列表
/// </summary>
/// <param name="tinguid"></param>
/// <param name="limits"></param>
/// <returns></returns>
public static MSingerSongList GetSingerSongs(string tinguid, int limits)
{
MSingerSongList model = new MSingerSongList();
string url = string.Format("tingapi.ting.baidu/v1/restserver/ting?format=json&callback=&from=webapp_music&method=baidu.SongL
return model;
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论