fix: resolve bugs found in pre-release review

This commit is contained in:
Mathis Maquenne
2026-08-05 21:33:08 +02:00
parent 5bb1448650
commit a695fb4de3
17 changed files with 258 additions and 60 deletions
+1
View File
@@ -213,6 +213,7 @@ func (c *Client) MediaStream(ctx context.Context, media *Media) (io.ReadCloser,
}
if resp.StatusCode != http.StatusOK {
resp.Body.Close()
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
+4
View File
@@ -120,6 +120,10 @@ func (m *mobileClient) authenticate(ctx context.Context) (string, string, string
return "", "", "", err
}
if len(decrypted) < 96 {
return "", "", "", fmt.Errorf("unexpected response from gateway")
}
token := string(decrypted[0:64])
tokenKey := string(decrypted[64:80])
userKey := string(decrypted[80:96])
+7 -1
View File
@@ -2,6 +2,7 @@ package deezer
import (
"context"
"errors"
"fmt"
)
@@ -12,9 +13,14 @@ func resolveARL(ctx context.Context, validate func(ctx context.Context, arl stri
}
if creds != nil && creds.ARL != "" {
if verr := validate(ctx, creds.ARL); verr == nil {
verr := validate(ctx, creds.ARL)
if verr == nil {
return creds.ARL, nil
}
if !errors.Is(verr, ErrInvalidARL) {
return "", fmt.Errorf("stored session could not be validated: %w", verr)
}
}
if creds != nil && creds.Email != "" && creds.Password != "" {
+4 -1
View File
@@ -3,6 +3,7 @@ package deezer
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -10,6 +11,8 @@ import (
"time"
)
var ErrInvalidARL = errors.New("invalid or expired ARL cookie")
type Session struct {
APIToken string
LicenseToken string
@@ -71,7 +74,7 @@ func authenticate(ctx context.Context, arlCookie string) (*Session, error) {
}
if res.Results.User.ID == 0 {
return nil, fmt.Errorf("invalid or expired ARL cookie")
return nil, ErrInvalidARL
}
opts := res.Results.User.Options
+23 -3
View File
@@ -62,7 +62,27 @@ func (t *Track) Filename(kind Kind, mediaFormat string) string {
}
}
fileName := fmt.Sprintf("%s%s - %s.%s", prefix, t.Artist, t.FullTitle(), ext)
fileName, _ = filenamify.Filenamify(fileName, filenamify.Options{MaxLength: 255})
return fileName
base := fmt.Sprintf("%s%s - %s", prefix, t.Artist, t.FullTitle())
base, _ = filenamify.Filenamify(base, filenamify.Options{MaxLength: 255})
base = truncateBytes(base, 255-len(ext)-1-len("-id3v2"))
return base + "." + ext
}
func truncateBytes(s string, max int) string {
if max <= 0 {
return ""
}
if len(s) <= max {
return s
}
last := 0
for i := range s {
if i > max {
return s[:last]
}
last = i
}
return s[:last]
}