append metadata tags after saving tracks
also rewrite requests to monochrome using 2 helper methods
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -20,24 +18,21 @@ type TrackInfoResponse struct {
|
||||
}
|
||||
|
||||
func (c *Client) TrackInfo(id int, quality AudioQuality) (*TrackInfo, error) {
|
||||
req, err := http.NewRequest("GET", c.config.ApiURL+"/track", nil)
|
||||
req, err := c.makeRequest("GET", "/track", nil, map[string]string{
|
||||
"id": strconv.Itoa(id),
|
||||
"quality": quality,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request: %v", err)
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("id", strconv.Itoa(id))
|
||||
params.Set("quality", quality)
|
||||
req.URL.RawQuery = params.Encode()
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
data, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to send request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
response := TrackInfoResponse{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||
if err := json.NewDecoder(bytes.NewReader(data)).Decode(&response); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode json response: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user