style: rename accessors to idiomatic names
This commit is contained in:
@@ -26,11 +26,11 @@ type Album struct {
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
func (a *Album) GetTitle() string {
|
||||
func (a *Album) Title() string {
|
||||
return a.Results.Data.Title
|
||||
}
|
||||
|
||||
func (a *Album) GetTracks() []*Track {
|
||||
func (a *Album) Tracks() []*Track {
|
||||
return a.Results.Tracks.Data
|
||||
}
|
||||
|
||||
@@ -38,12 +38,12 @@ func (a *Album) SetTracks(t []*Track) {
|
||||
a.Results.Tracks.Data = t
|
||||
}
|
||||
|
||||
func (a *Album) GetOutputDir(outputDir string) string {
|
||||
func (a *Album) OutputDir(outputDir string) string {
|
||||
base := fmt.Sprintf("%s - %s", a.Results.Data.Artist, a.Results.Data.Title)
|
||||
base, _ = filenamify.Filenamify(base, filenamify.Options{})
|
||||
return path.Join(outputDir, base)
|
||||
}
|
||||
|
||||
func (a *Album) Unmarshal(data []byte) error {
|
||||
func (a *Album) decode(data []byte) error {
|
||||
return json.Unmarshal(data, a)
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ type Artist struct {
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
func (a *Artist) GetTitle() string {
|
||||
func (a *Artist) Title() string {
|
||||
return a.Results.Data.Name
|
||||
}
|
||||
|
||||
func (a *Artist) GetTracks() []*Track {
|
||||
func (a *Artist) Tracks() []*Track {
|
||||
return a.Results.Tracks.Data
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ func (a *Artist) SetTracks(t []*Track) {
|
||||
a.Results.Tracks.Data = t
|
||||
}
|
||||
|
||||
func (a *Artist) GetOutputDir(outputDir string) string {
|
||||
func (a *Artist) OutputDir(outputDir string) string {
|
||||
base, _ := filenamify.Filenamify(a.Results.Data.Name, filenamify.Options{})
|
||||
return path.Join(outputDir, base)
|
||||
}
|
||||
|
||||
func (a *Artist) Unmarshal(data []byte) error {
|
||||
func (a *Artist) decode(data []byte) error {
|
||||
return json.Unmarshal(data, a)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (c *Client) FetchResource(ctx context.Context, kind Kind, id string) (Resou
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.Session.HttpClient.Do(req)
|
||||
resp, err := c.Session.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (c *Client) FetchResource(ctx context.Context, kind Kind, id string) (Resou
|
||||
return nil, fmt.Errorf("unexpected response")
|
||||
}
|
||||
|
||||
if err := resource.Unmarshal(body); err != nil {
|
||||
if err := resource.decode(body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func (c *Client) FetchMedia(ctx context.Context, track *Track, quality string) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.Session.HttpClient.Do(req)
|
||||
resp, err := c.Session.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (c *Client) FetchCoverImage(ctx context.Context, track *Track) ([]byte, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.Session.HttpClient.Do(req)
|
||||
resp, err := c.Session.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -198,13 +198,13 @@ func (c *Client) FetchCoverImage(ctx context.Context, track *Track) ([]byte, err
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
func (c *Client) GetMediaStream(ctx context.Context, media *Media) (io.ReadCloser, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", media.GetURL(), nil)
|
||||
func (c *Client) MediaStream(ctx context.Context, media *Media) (io.ReadCloser, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", media.URL(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
streamingClient := *c.Session.HttpClient
|
||||
streamingClient := *c.Session.HTTPClient
|
||||
streamingClient.Timeout = 0
|
||||
|
||||
resp, err := streamingClient.Do(req)
|
||||
|
||||
@@ -18,10 +18,10 @@ type mediaError struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (m *Media) GetURL() string {
|
||||
func (m *Media) URL() string {
|
||||
return m.Data[0].Media[0].Sources[0].URL
|
||||
}
|
||||
|
||||
func (m *Media) GetFormat() string {
|
||||
func (m *Media) Format() string {
|
||||
return m.Data[0].Media[0].Format
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ type Playlist struct {
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
func (p *Playlist) GetTitle() string {
|
||||
func (p *Playlist) Title() string {
|
||||
return p.Results.Data.Title
|
||||
}
|
||||
|
||||
func (p *Playlist) GetTracks() []*Track {
|
||||
func (p *Playlist) Tracks() []*Track {
|
||||
return p.Results.Tracks.Data
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ func (p *Playlist) SetTracks(t []*Track) {
|
||||
p.Results.Tracks.Data = t
|
||||
}
|
||||
|
||||
func (p *Playlist) GetOutputDir(outputDir string) string {
|
||||
func (p *Playlist) OutputDir(outputDir string) string {
|
||||
base, _ := filenamify.Filenamify(p.Results.Data.Title, filenamify.Options{})
|
||||
return path.Join(outputDir, base)
|
||||
}
|
||||
|
||||
func (p *Playlist) Unmarshal(data []byte) error {
|
||||
func (p *Playlist) decode(data []byte) error {
|
||||
return json.Unmarshal(data, p)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package deezer
|
||||
|
||||
type Resource interface {
|
||||
GetTitle() string
|
||||
GetTracks() []*Track
|
||||
Title() string
|
||||
Tracks() []*Track
|
||||
SetTracks(tracks []*Track)
|
||||
GetOutputDir(outputDir string) string
|
||||
Unmarshal(data []byte) error
|
||||
OutputDir(outputDir string) string
|
||||
decode(data []byte) error
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
type Session struct {
|
||||
APIToken string
|
||||
LicenseToken string
|
||||
HttpClient *http.Client
|
||||
HTTPClient *http.Client
|
||||
Premium bool
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func authenticate(ctx context.Context, arlCookie string) (*Session, error) {
|
||||
return &Session{
|
||||
APIToken: res.Results.APIToken,
|
||||
LicenseToken: opts.LicenseToken,
|
||||
HttpClient: client,
|
||||
HTTPClient: client,
|
||||
Premium: opts.MobileOffline || opts.WebOffline,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ type Single struct {
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
func (s *Single) GetTitle() string {
|
||||
func (s *Single) Title() string {
|
||||
if s.Results.Data == nil {
|
||||
return ""
|
||||
}
|
||||
return s.Results.Data.GetTitle()
|
||||
return s.Results.Data.FullTitle()
|
||||
}
|
||||
|
||||
func (s *Single) GetTracks() []*Track {
|
||||
func (s *Single) Tracks() []*Track {
|
||||
if s.Results.Data == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -27,10 +27,10 @@ func (s *Single) GetTracks() []*Track {
|
||||
|
||||
func (s *Single) SetTracks(tracks []*Track) {}
|
||||
|
||||
func (s *Single) GetOutputDir(outputDir string) string {
|
||||
func (s *Single) OutputDir(outputDir string) string {
|
||||
return path.Join(outputDir, "Singles")
|
||||
}
|
||||
|
||||
func (s *Single) Unmarshal(data []byte) error {
|
||||
func (s *Single) decode(data []byte) error {
|
||||
return json.Unmarshal(data, s)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ type Track struct {
|
||||
TrackToken string `json:"TRACK_TOKEN"`
|
||||
}
|
||||
|
||||
func (t *Track) GetTitle() string {
|
||||
func (t *Track) FullTitle() string {
|
||||
if t.Version != "" {
|
||||
return t.Title + " " + t.Version
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (t *Track) Filename(kind Kind, mediaFormat string) string {
|
||||
}
|
||||
}
|
||||
|
||||
fileName := fmt.Sprintf("%s%s - %s.%s", prefix, t.Artist, t.GetTitle(), ext)
|
||||
fileName := fmt.Sprintf("%s%s - %s.%s", prefix, t.Artist, t.FullTitle(), ext)
|
||||
fileName, _ = filenamify.Filenamify(fileName, filenamify.Options{MaxLength: 255})
|
||||
return fileName
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user