-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce35e61
commit 1ccfdb7
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/XiaoMengXinX/Music163Api-Go/types" | ||
"github.com/XiaoMengXinX/Music163Api-Go/utils" | ||
) | ||
|
||
// SongDownloadURL 歌曲下载 URL API | ||
const SongDownloadURL = "/api/song/enhance/download/url" | ||
|
||
// SongDownloadURLReq 歌曲下载 URL 的参数配置 | ||
type SongDownloadURLReq struct { | ||
// Br 码率,默认设置了 999000 即最大码率 | ||
Id int `json:"id"` | ||
// Ids 歌曲 ID | ||
Br int `json:"br"` | ||
} | ||
|
||
// CreateSongDownloadURLJson 创建请求 body json | ||
func CreateSongDownloadURLJson(id int) string { | ||
reqBody := SongDownloadURLReq{ | ||
Id: id, | ||
Br: 999000, | ||
} | ||
reqBodyJson, _ := json.Marshal(reqBody) | ||
return string(reqBodyJson) | ||
} | ||
|
||
// GetSongDownloadURL 获取歌曲下载 URL, 非 VIP 账号可通过此 API 获取部分歌曲的无损音质 | ||
func GetSongDownloadURL(data utils.RequestData, id int) (result types.SongDownloadURLData, err error) { | ||
var options utils.EapiOption | ||
options.Path = SongDownloadURL | ||
options.Url = "https://music.163.com/eapi/song/enhance/download/url" | ||
options.Json = CreateSongDownloadURLJson(id) | ||
resBody, _, err := utils.ApiRequest(options, data) | ||
if err != nil { | ||
return result, err | ||
} | ||
err = json.Unmarshal([]byte(resBody), &result) | ||
result.RawJson = resBody | ||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/XiaoMengXinX/Music163Api-Go/types" | ||
"github.com/XiaoMengXinX/Music163Api-Go/utils" | ||
) | ||
|
||
// SongLyricAPI 获取歌词 API | ||
const SongLyricAPI = "/api/song/lyric" | ||
|
||
// SongLyricReq SongLyric API 的 body json | ||
type SongLyricReq struct { | ||
Id int `json:"id"` | ||
Lv int `json:"lv"` | ||
Kv int `json:"kv"` | ||
Tv int `json:"tv"` | ||
} | ||
|
||
// CreateSongLyricReqJson 创建请求 body json | ||
func CreateSongLyricReqJson(id int) string { | ||
reqBody := SongLyricReq{ | ||
Id: id, | ||
Lv: -1, | ||
Kv: -1, | ||
Tv: -1, | ||
} | ||
reqBodyJson, _ := json.Marshal(reqBody) | ||
return string(reqBodyJson) | ||
} | ||
|
||
// GetSongLyric 获取歌曲歌词 | ||
func GetSongLyric(data utils.RequestData, id int) (result types.SongLyricData, err error) { | ||
var options utils.EapiOption | ||
options.Path = SongLyricAPI | ||
options.Url = "https://music.163.com/eapi/song/lyric" | ||
reqBodyJson := CreateSongLyricReqJson(id) | ||
options.Json = reqBodyJson | ||
resBody, _, err := utils.ApiRequest(options, data) | ||
if err != nil { | ||
return result, err | ||
} | ||
err = json.Unmarshal([]byte(resBody), &result) | ||
result.RawJson = resBody | ||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package types | ||
|
||
// SongLyricData 获取歌词 API 返回数据 | ||
type SongLyricData struct { | ||
RawJson string | ||
Sgc bool `json:"sgc"` | ||
Sfy bool `json:"sfy"` | ||
Qfy bool `json:"qfy"` | ||
LyricUser struct { | ||
Id int `json:"id"` | ||
Status int `json:"status"` | ||
Demand int `json:"demand"` | ||
Userid int `json:"userid"` | ||
Nickname string `json:"nickname"` | ||
Uptime int64 `json:"uptime"` | ||
} `json:"lyricUser"` | ||
Lrc struct { | ||
Version int `json:"version"` | ||
Lyric string `json:"lyric"` | ||
} `json:"lrc"` | ||
Klyric struct { | ||
Version int `json:"version"` | ||
Lyric string `json:"lyric"` | ||
} `json:"klyric"` | ||
Tlyric struct { | ||
Version int `json:"version"` | ||
Lyric string `json:"lyric"` | ||
} `json:"tlyric"` | ||
Code int `json:"code"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters