#177 串接歌詞 API
Published in
4 min readSep 18, 2022
串接歌詞 API 顯示歌詞。
基本功能
- 串接歌詞 API。
歌詞 API 的格式如下,歌詞資料庫以英文歌為主。
https://some-random-api.com/others/lyrics?title=how long will i love you
API 回傳的 JSON 範例如下。
{
"title":"How Long Will I Love You",
"author":"Ellie Goulding",
"lyrics":"How long will I love you? As long as stars are above you And longer if I can How long will I need you? As long as the seasons need to Follow their plan How long will I be with you? As long as the sea is bound to Wash up on the sand How long will I want you? As long as you want me to And longer by far How long will I hold you? As long as your father told you As long as you can How long will I give to you? As long as I live through you However long you say How long will I love you? As long as stars are above you And longer if I may How long will I love you? ",
"thumbnail":{
"genius":"https://images.genius.com/498d1108967abafb01a799f6555d0344.300x300x1.png",
},
"links":{
"genius":"https://genius.com/Ellie-goulding-how-long-will-i-love-you-lyrics",
},
"disclaimer":"What the API returns is not guaranteed to return the right lyrics or have a matching title and author.",
"source":0,
}
- 畫面上顯示專輯圖片,歌名,歌手,歌詞和網頁連結的 button。
點選網頁連結的 button 時顯示網頁,網址是 JSON 裡 links > genius 的內容。
- 加入 search bar,可輸入歌名搜尋歌詞。
進階功能
- 串接 iTunes API,利用 JSON 的 previewUrl 播放音樂。
iTunes API 的格式如下。
https://itunes.apple.com/search?term=how long will i love you&media=music