init
This commit is contained in:
62
monochrome/album.go
Normal file
62
monochrome/album.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package monochrome
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type AlbumTrack struct {
|
||||
Type string `json:"type"`
|
||||
Item struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Duration int `json:"duration"`
|
||||
TrackNumber int `json:"trackNumber"`
|
||||
Explicit bool `json:"explicit"`
|
||||
AudioQuality AudioQuality `json:"audioQuality"`
|
||||
} `json:"item"`
|
||||
}
|
||||
|
||||
type AlbumInfo struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Duration int `json:"duration"`
|
||||
NumberOfTracks int `json:"numberOfTracks"`
|
||||
ReleaseDate string `json:"releaseDate"`
|
||||
Type SearchItemType `json:"type"`
|
||||
CoverID string `json:"cover"`
|
||||
VibrantColor string `json:"vibrantColor"`
|
||||
Explicit bool `json:"explicit"`
|
||||
Items []AlbumTrack `json:"items"`
|
||||
}
|
||||
|
||||
type AlbumInfoResponse struct {
|
||||
Data AlbumInfo `json:"data"`
|
||||
}
|
||||
|
||||
func (c *Client) AlbumInfo(id int) (*AlbumInfo, error) {
|
||||
req, err := http.NewRequest("GET", c.config.ApiURL+"/album", nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request: %v", err)
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("id", strconv.Itoa(id))
|
||||
req.URL.RawQuery = params.Encode()
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to send request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
response := AlbumInfoResponse{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode json response: %v", err)
|
||||
}
|
||||
|
||||
return &response.Data, nil
|
||||
}
|
||||
Reference in New Issue
Block a user