一:学习目的
因进来做一个Android MP3播放器项目,需要用到歌词本地同步和在线同步,本地不存在在通过WiFi或GPRS从网络上获取;
二:学习API的网址:
http://api.geci.me/en/latest/index.html#indices-and-tables
三:学习前掌握的知识:
1)看的懂Json数据格式;
2)如果想深入了解此API要了解汉字和Unicode的转换!
四:学习内容
主要可以通过一下方式来获取歌词:
1) 根据歌曲名来获取歌词
2) 格局歌曲名和歌手名获取歌词
3) 根据歌曲编号获取歌曲URL
4) 根据专辑编号获取专辑封面URL
五:详细分析
<一>:根据歌曲名来获取歌词
1) 请求地址: http://geci.me/api/lyric/:song
2) 返回歌词格式: json字符串
3) 请求方式是:get方式;
Eg:查找“海阔天空”的歌词;url:http://geci.me/api/lyric/海阔天空
获取到的json数据格式如下:
{ "count": 15, "code": 0, "result":
[
{"aid": 1563419, "lrc": "http://s.geci.me/lrc/166/16685/1668536.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1668536},
{"aid": 1571906, "lrc": "http://s.geci.me/lrc/167/16796/1679605.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1679605},
{"aid": 1573814, "lrc": "http://s.geci.me/lrc/168/16819/1681961.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1681961},
{"aid": 1618733, "lrc": "http://s.geci.me/lrc/174/17407/1740790.lrc", "artist": "\u5468\u534e\u5065", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1740790},
{"aid": 1656038, "lrc": "http://s.geci.me/lrc/179/17907/1790768.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1790768},
{"aid": 1718741, "lrc": "http://s.geci.me/lrc/187/18757/1875769.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1875769},
{"aid": 1889264, "lrc": "http://s.geci.me/lrc/210/21070/2107014.lrc", "artist": "\u8d39\u7fd4", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2107014},
{"aid": 2003267, "lrc": "http://s.geci.me/lrc/226/22642/2264296.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2264296},
{"aid": 2020610, "lrc": "http://s.geci.me/lrc/228/22889/2288967.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2288967},
{"aid": 2051678, "lrc": "http://s.geci.me/lrc/233/23323/2332322.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2332322},
{"aid": 2075717, "lrc": "http://s.geci.me/lrc/236/23651/2365157.lrc", "artist": "\u8d39\u7fd4", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2365157},
{"aid": 2253359, "lrc": "http://s.geci.me/lrc/261/26128/2612812.lrc", "artist": "\u9ec4\u79cb\u751f", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2612812},
{"aid": 2319680, "lrc": "http://s.geci.me/lrc/270/27055/2705565.lrc", "artist": "\u4efb\u8d24\u9f50", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2705565},
{"aid": 2346662, "lrc": "http://s.geci.me/lrc/274/27442/2744281.lrc", "artist": "\u6797\u5b50\u7965", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2744281},
{"aid": 2412272, "lrc": "http://s.geci.me/lrc/283/28370/2837015.lrc", "artist": "DJ Tommy", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 2837015}
]
}
这并非我们所找歌曲的歌词,而是在歌词迷库中存在的不同版本歌曲歌词的url;
从这里看有15个版本(坑爹啊);
{"aid": 1563419, "lrc": "http://s.geci.me/lrc/166/16685/1668536.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1668536}
Aid: 经多次测试,得到此编号指
Lrc:歌词的路径;
Artist:Beyond –歌手名字
Song: 海阔天空—歌曲名称;
Sid:是歌词编号;
<二>:根据歌曲名和歌手名获取歌词
1) 请求地址: http://geci.me/api/lyric/:song
2) 返回歌词格式: json字符串
3) 请求方式是:get方式;
Eg:查找黄秋生的“海宽天空” http://geci.me/api/lyric/海阔天空/黄秋生
<三>:根据歌曲编号获取歌词URL
1) 请求地址:http://geci.me/api/cover/:album_id
2) 返回歌词格式: json字符串
3) 请求方式是:get方式;
Eg:
{"aid": 1563419, "lrc": "http://s.geci.me/lrc/166/16685/1668536.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1668536},
知道了以上信息可以通过http://s.geci.me/lrc/166/16685/1668536.lrc中1668536或sid获取歌词路径;
<四>:根据专辑编号获取专辑封面URL
1) 请求地址:http://geci.me/api/cover/:album_id
2) 返回歌词格式: json字符串
3) 请求方式是:get方式;
Eg:查找“海阔天空”的专辑封面:
首先要通过第一步(歌曲名称查询获取信息);
以第一个版本为例:
{"aid": 1563419, "lrc": "http://s.geci.me/lrc/166/16685/1668536.lrc", "artist": "Beyond", "song": "\u6d77\u9614\u5929\u7a7a", "sid": 1668536},
(1) http://geci.me/api/cover/aid
即:http://geci.me/api/cover/1563419
返回一个json字符串:
{"count": 1, "code": 0, "result": {"cover": "http://s.geci.me/album-cover/156/1563419.jpg", "thumb": "http://s.geci.me/album-cover/156/1563419-thumb.jpg"}}
主要看cover对应的值:http://s.geci.me/album-cover/156/1563419.jpg和thumb对应的值:http://s.geci.me/album-cover/156/1563419-thumb.jpg;
Cover和thumb对应的都是专辑封面的路径,但是thumb对的是小图片;