refactor: use a better API to download playlists with more than 40 tracks
This commit is contained in:
+13
-6
@@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/flytam/filenamify"
|
"github.com/flytam/filenamify"
|
||||||
|
"github.com/mathismqn/godeez/internal/config"
|
||||||
"github.com/mathismqn/godeez/internal/deezer"
|
"github.com/mathismqn/godeez/internal/deezer"
|
||||||
"github.com/mathismqn/godeez/internal/tags"
|
"github.com/mathismqn/godeez/internal/tags"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -44,6 +45,12 @@ func validateInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func downloadContent(contentType string, args []string) {
|
func downloadContent(contentType string, args []string) {
|
||||||
|
session, err := deezer.Authenticate(config.Cfg.ArlCookie)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: could not authenticate: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
nArgs := len(args)
|
nArgs := len(args)
|
||||||
separator := "--------------------------------------------------"
|
separator := "--------------------------------------------------"
|
||||||
|
|
||||||
@@ -57,7 +64,7 @@ func downloadContent(contentType string, args []string) {
|
|||||||
switch contentType {
|
switch contentType {
|
||||||
case "album":
|
case "album":
|
||||||
album := &deezer.Album{}
|
album := &deezer.Album{}
|
||||||
if err := deezer.GetData(album, id); err != nil {
|
if err := session.GetData(album, id); err != nil {
|
||||||
fmt.Printf("\r[%d/%d] Getting data for album %s... FAILED\n", i+1, nArgs, id)
|
fmt.Printf("\r[%d/%d] Getting data for album %s... FAILED\n", i+1, nArgs, id)
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not get album data: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not get album data: %v\n", err)
|
||||||
continue
|
continue
|
||||||
@@ -66,12 +73,12 @@ func downloadContent(contentType string, args []string) {
|
|||||||
songs = album.GetSongs()
|
songs = album.GetSongs()
|
||||||
case "playlist":
|
case "playlist":
|
||||||
playlist := &deezer.Playlist{}
|
playlist := &deezer.Playlist{}
|
||||||
if err := deezer.GetData(playlist, id); err != nil {
|
if err := session.GetData(playlist, id); err != nil {
|
||||||
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not get playlist data: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not get playlist data: %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if playlist.Data.Status == 1 && playlist.Data.CollabKey == "" {
|
if playlist.Results.Data.Status == 1 && playlist.Results.Data.CollabKey == "" {
|
||||||
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
||||||
fmt.Fprintf(os.Stderr, "Error: playlist is private and no valid arl cookie was provided\n")
|
fmt.Fprintf(os.Stderr, "Error: playlist is private and no valid arl cookie was provided\n")
|
||||||
continue
|
continue
|
||||||
@@ -102,7 +109,7 @@ func downloadContent(contentType string, args []string) {
|
|||||||
|
|
||||||
fmt.Printf(" Downloading %s...", songTitle)
|
fmt.Printf(" Downloading %s...", songTitle)
|
||||||
|
|
||||||
media, err := song.GetMediaData(quality)
|
media, err := song.GetMediaData(session.LicenseToken, quality)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("\r Downloading %s... FAILED\n", songTitle)
|
fmt.Printf("\r Downloading %s... FAILED\n", songTitle)
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not get media data: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not get media data: %v\n", err)
|
||||||
@@ -149,14 +156,14 @@ func downloadContent(contentType string, args []string) {
|
|||||||
|
|
||||||
tempo, key, err := song.GetTempoAndKey()
|
tempo, key, err := song.GetTempoAndKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not get tempo and key: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Warning: could not get tempo and key: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" Tempo: %s\n", tempo)
|
fmt.Printf(" Tempo: %s\n", tempo)
|
||||||
fmt.Printf(" Key: %s\n", key)
|
fmt.Printf(" Key: %s\n", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tags.AddTags(resource, song, filePath, tempo, key); err != nil {
|
if err := tags.AddTags(resource, song, filePath, tempo, key); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not add tags to song: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Warning: could not add tags to song: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -39,7 +39,7 @@ func initConfig() {
|
|||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
fmt.Printf("Config file not found, creating one at %s\n", path)
|
fmt.Printf("Config file not found, creating one at %s\n", path)
|
||||||
|
|
||||||
content := []byte("arl_cookie = ''\nlicense_token = ''\nsecret_key = ''\niv = '0001020304050607'\n")
|
content := []byte("arl_cookie = ''\nsecret_key = ''\niv = '0001020304050607'\n")
|
||||||
if err := os.WriteFile(path, content, 0644); err != nil {
|
if err := os.WriteFile(path, content, 0644); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not create config file: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not create config file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -63,10 +63,6 @@ func initConfig() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.LicenseToken == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "Error: license_token is not set in config file")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if cfg.SecretKey == "" {
|
if cfg.SecretKey == "" {
|
||||||
fmt.Fprintln(os.Stderr, "Error: secret_key is not set in config file")
|
fmt.Fprintln(os.Stderr, "Error: secret_key is not set in config file")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
LicenseToken string `mapstructure:"license_token"`
|
ArlCookie string `mapstructure:"arl_cookie"`
|
||||||
ArlCookie string `mapstructure:"arl_cookie"`
|
SecretKey string `mapstructure:"secret_key"`
|
||||||
SecretKey string `mapstructure:"secret_key"`
|
IV string `mapstructure:"iv"`
|
||||||
IV string `mapstructure:"iv"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Cfg Config
|
var Cfg Config
|
||||||
|
|||||||
+18
-16
@@ -9,21 +9,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Album struct {
|
type Album struct {
|
||||||
Data struct {
|
Results struct {
|
||||||
Title string `json:"ALB_TITLE"`
|
Data struct {
|
||||||
Artist string `json:"ART_NAME"`
|
Title string `json:"ALB_TITLE"`
|
||||||
OriginalReleaseDate string `json:"ORIGINAL_RELEASE_DATE"`
|
Artist string `json:"ART_NAME"`
|
||||||
PhysicalReleaseDate string `json:"PHYSICAL_RELEASE_DATE"`
|
OriginalReleaseDate string `json:"ORIGINAL_RELEASE_DATE"`
|
||||||
Label string `json:"LABEL_NAME"`
|
PhysicalReleaseDate string `json:"PHYSICAL_RELEASE_DATE"`
|
||||||
ProducerLine string `json:"PRODUCER_LINE"`
|
Label string `json:"LABEL_NAME"`
|
||||||
} `json:"DATA"`
|
ProducerLine string `json:"PRODUCER_LINE"`
|
||||||
Songs struct {
|
} `json:"DATA"`
|
||||||
Data []*Song `json:"data"`
|
Songs struct {
|
||||||
} `json:"SONGS"`
|
Data []*Song `json:"data"`
|
||||||
|
} `json:"SONGS"`
|
||||||
|
} `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) GetURL(id string) string {
|
func (a *Album) GetType() string {
|
||||||
return "https://www.deezer.com/en/album/" + id
|
return "Album"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) UnmarshalData(data []byte) error {
|
func (a *Album) UnmarshalData(data []byte) error {
|
||||||
@@ -31,11 +33,11 @@ func (a *Album) UnmarshalData(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) GetSongs() []*Song {
|
func (a *Album) GetSongs() []*Song {
|
||||||
return a.Songs.Data
|
return a.Results.Songs.Data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) GetOutputPath(outputDir string) string {
|
func (a *Album) GetOutputPath(outputDir string) string {
|
||||||
base := fmt.Sprintf("%s - %s", a.Data.Artist, a.Data.Title)
|
base := fmt.Sprintf("%s - %s", a.Results.Data.Artist, a.Results.Data.Title)
|
||||||
base, _ = filenamify.Filenamify(base, filenamify.Options{})
|
base, _ = filenamify.Filenamify(base, filenamify.Options{})
|
||||||
outputPath := path.Join(outputDir, base)
|
outputPath := path.Join(outputDir, base)
|
||||||
outputPath, _ = filenamify.Filenamify(outputPath, filenamify.Options{})
|
outputPath, _ = filenamify.Filenamify(outputPath, filenamify.Options{})
|
||||||
@@ -44,5 +46,5 @@ func (a *Album) GetOutputPath(outputDir string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) GetTitle() string {
|
func (a *Album) GetTitle() string {
|
||||||
return a.Data.Title
|
return a.Results.Data.Title
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-14
@@ -8,18 +8,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Playlist struct {
|
type Playlist struct {
|
||||||
Data struct {
|
Results struct {
|
||||||
Title string `json:"TITLE"`
|
Data struct {
|
||||||
Status int `json:"STATUS"`
|
Title string `json:"TITLE"`
|
||||||
CollabKey string `json:"COLLAB_KEY"`
|
Status int `json:"STATUS"`
|
||||||
} `json:"DATA"`
|
CollabKey string `json:"COLLAB_KEY"`
|
||||||
Songs struct {
|
} `json:"DATA"`
|
||||||
Data []*Song `json:"data"`
|
Songs struct {
|
||||||
} `json:"SONGS"`
|
Data []*Song `json:"data"`
|
||||||
|
} `json:"SONGS"`
|
||||||
|
} `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) GetURL(id string) string {
|
func (p *Playlist) GetType() string {
|
||||||
return "https://www.deezer.com/en/playlist/" + id
|
return "Playlist"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) UnmarshalData(data []byte) error {
|
func (p *Playlist) UnmarshalData(data []byte) error {
|
||||||
@@ -27,17 +29,17 @@ func (p *Playlist) UnmarshalData(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) GetSongs() []*Song {
|
func (p *Playlist) GetSongs() []*Song {
|
||||||
return p.Songs.Data
|
return p.Results.Songs.Data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) GetOutputPath(outputDir string) string {
|
func (p *Playlist) GetOutputPath(outputDir string) string {
|
||||||
p.Data.Title, _ = filenamify.Filenamify(p.Data.Title, filenamify.Options{})
|
p.Results.Data.Title, _ = filenamify.Filenamify(p.Results.Data.Title, filenamify.Options{})
|
||||||
outputPath := path.Join(outputDir, p.Data.Title)
|
outputPath := path.Join(outputDir, p.Results.Data.Title)
|
||||||
outputPath, _ = filenamify.Filenamify(outputPath, filenamify.Options{})
|
outputPath, _ = filenamify.Filenamify(outputPath, filenamify.Options{})
|
||||||
|
|
||||||
return outputPath
|
return outputPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) GetTitle() string {
|
func (p *Playlist) GetTitle() string {
|
||||||
return p.Data.Title
|
return p.Results.Data.Title
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-23
@@ -1,57 +1,65 @@
|
|||||||
package deezer
|
package deezer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"strings"
|
||||||
|
|
||||||
"github.com/mathismqn/godeez/internal/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Resource interface {
|
type Resource interface {
|
||||||
GetURL(id string) string
|
GetType() string
|
||||||
UnmarshalData(data []byte) error
|
UnmarshalData(data []byte) error
|
||||||
GetSongs() []*Song
|
GetSongs() []*Song
|
||||||
GetOutputPath(outputDir string) string
|
GetOutputPath(outputDir string) string
|
||||||
GetTitle() string
|
GetTitle() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetData(r Resource, id string) error {
|
func (s *Session) GetData(r Resource, id string) error {
|
||||||
url := r.GetURL(id)
|
payload := map[string]interface{}{
|
||||||
|
"nb": 10000,
|
||||||
client := &http.Client{}
|
"start": 0,
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
"playlist_id": id,
|
||||||
|
"alb_id": id,
|
||||||
|
"lang": "en",
|
||||||
|
"tab": 0,
|
||||||
|
"tags": true,
|
||||||
|
"header": true,
|
||||||
|
}
|
||||||
|
jsonData, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Cfg.ArlCookie != "" {
|
url := fmt.Sprintf("https://www.deezer.com/ajax/gw-light.php?method=deezer.page%s&input=3&api_version=1.0&api_token=%s", r.GetType(), s.APIToken)
|
||||||
req.AddCookie(&http.Cookie{
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
|
||||||
Name: "arl",
|
if err != nil {
|
||||||
Value: config.Cfg.ArlCookie,
|
return err
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := s.Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
return fmt.Errorf("resource not found")
|
|
||||||
}
|
|
||||||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
re := regexp.MustCompile(`window\.__DZR_APP_STATE__ = (\{.*\})`)
|
|
||||||
matches := re.FindStringSubmatch(string(body))
|
if strings.Contains(string(body), `"DATA_ERROR":"playlist::getData"`) {
|
||||||
if len(matches) != 2 {
|
return fmt.Errorf("invalid playlist ID")
|
||||||
return fmt.Errorf("error parsing response")
|
}
|
||||||
|
if strings.Contains(string(body), `"DATA_ERROR":"album::getData"`) {
|
||||||
|
return fmt.Errorf("invalid album ID")
|
||||||
|
}
|
||||||
|
if strings.Contains(string(body), `"results":{}`) {
|
||||||
|
return fmt.Errorf("unexpected response")
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.UnmarshalData([]byte(matches[1]))
|
return r.UnmarshalData(body)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package deezer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/cookiejar"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserDataResponse struct {
|
||||||
|
Results struct {
|
||||||
|
APIToken string `json:"checkForm"`
|
||||||
|
User struct {
|
||||||
|
Id int `json:"USER_ID"`
|
||||||
|
Options struct {
|
||||||
|
LicenseToken string `json:"license_token"`
|
||||||
|
MobileOffline bool `json:"mobile_offline"`
|
||||||
|
WebOffline bool `json:"web_offline"`
|
||||||
|
} `json:"OPTIONS"`
|
||||||
|
} `json:"USER"`
|
||||||
|
} `json:"results"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Session struct {
|
||||||
|
ArlCookie string
|
||||||
|
APIToken string
|
||||||
|
LicenseToken string
|
||||||
|
Client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func Authenticate(arlCookie string) (*Session, error) {
|
||||||
|
jar, err := cookiejar.New(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
client := &http.Client{
|
||||||
|
Jar: jar,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "https://www.deezer.com/ajax/gw-light.php?method=deezer.getUserData&input=3&api_version=1.0&api_token="
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.AddCookie(&http.Cookie{
|
||||||
|
Name: "arl",
|
||||||
|
Value: arlCookie,
|
||||||
|
})
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
var res UserDataResponse
|
||||||
|
if err := json.Unmarshal(body, &res); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.Results.User.Id == 0 {
|
||||||
|
return nil, fmt.Errorf("invalid arl cookie")
|
||||||
|
}
|
||||||
|
if !res.Results.User.Options.MobileOffline && !res.Results.User.Options.WebOffline {
|
||||||
|
return nil, fmt.Errorf("premium account required")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Session{
|
||||||
|
ArlCookie: arlCookie,
|
||||||
|
APIToken: res.Results.APIToken,
|
||||||
|
LicenseToken: res.Results.User.Options.LicenseToken,
|
||||||
|
Client: client,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/mathismqn/godeez/internal/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Song struct {
|
type Song struct {
|
||||||
@@ -32,7 +31,7 @@ type Song struct {
|
|||||||
TrackToken string `json:"TRACK_TOKEN"`
|
TrackToken string `json:"TRACK_TOKEN"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Song) GetMediaData(quality string) (*Media, error) {
|
func (s *Song) GetMediaData(licenseToken, quality string) (*Media, error) {
|
||||||
var formats string
|
var formats string
|
||||||
|
|
||||||
switch quality {
|
switch quality {
|
||||||
@@ -46,7 +45,7 @@ func (s *Song) GetMediaData(quality string) (*Media, error) {
|
|||||||
formats = `[{"cipher":"BF_CBC_STRIPE","format":"FLAC"},{"cipher":"BF_CBC_STRIPE","format":"MP3_320"},{"cipher":"BF_CBC_STRIPE","format":"MP3_128"}]`
|
formats = `[{"cipher":"BF_CBC_STRIPE","format":"FLAC"},{"cipher":"BF_CBC_STRIPE","format":"MP3_320"},{"cipher":"BF_CBC_STRIPE","format":"MP3_128"}]`
|
||||||
}
|
}
|
||||||
|
|
||||||
reqBody := fmt.Sprintf(`{"license_token":"%s","media":[{"type":"FULL","formats":%s}],"track_tokens":["%s"]}`, config.Cfg.LicenseToken, formats, s.TrackToken)
|
reqBody := fmt.Sprintf(`{"license_token":"%s","media":[{"type":"FULL","formats":%s}],"track_tokens":["%s"]}`, licenseToken, formats, s.TrackToken)
|
||||||
resp, err := http.Post("https://media.deezer.com/v1/get_url", "application/json", bytes.NewBuffer([]byte(reqBody)))
|
resp, err := http.Post("https://media.deezer.com/v1/get_url", "application/json", bytes.NewBuffer([]byte(reqBody)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -18,17 +18,17 @@ type FLACTagger struct {
|
|||||||
|
|
||||||
func (t *FLACTagger) AddTags(resource deezer.Resource, song *deezer.Song, cover []byte, path, tempo, key string) error {
|
func (t *FLACTagger) AddTags(resource deezer.Resource, song *deezer.Song, cover []byte, path, tempo, key string) error {
|
||||||
if album, ok := resource.(*deezer.Album); ok {
|
if album, ok := resource.(*deezer.Album); ok {
|
||||||
dateParts := strings.Split(album.Data.PhysicalReleaseDate, "-")
|
dateParts := strings.Split(album.Results.Data.PhysicalReleaseDate, "-")
|
||||||
if len(dateParts) == 3 {
|
if len(dateParts) == 3 {
|
||||||
album.Data.PhysicalReleaseDate = dateParts[0]
|
album.Results.Data.PhysicalReleaseDate = dateParts[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
t.addTag("ALBUM", album.Data.Title)
|
t.addTag("ALBUM", album.Results.Data.Title)
|
||||||
t.addTag("ALBUMARTIST", album.Data.Artist)
|
t.addTag("ALBUMARTIST", album.Results.Data.Artist)
|
||||||
t.addTag("PUBLISHER", album.Data.Label)
|
t.addTag("PUBLISHER", album.Results.Data.Label)
|
||||||
t.addTag("ORIGINALDATE", album.Data.OriginalReleaseDate)
|
t.addTag("ORIGINALDATE", album.Results.Data.OriginalReleaseDate)
|
||||||
t.addTag("DATE", album.Data.PhysicalReleaseDate)
|
t.addTag("DATE", album.Results.Data.PhysicalReleaseDate)
|
||||||
t.addTag("COMMENT", album.Data.ProducerLine)
|
t.addTag("COMMENT", album.Results.Data.ProducerLine)
|
||||||
t.addTag("TRACKNUMBER", song.TrackNumber)
|
t.addTag("TRACKNUMBER", song.TrackNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ func (t *ID3v2Tagger) AddTags(resource deezer.Resource, song *deezer.Song, cover
|
|||||||
song.Duration = fmt.Sprintf("%d", duration*1000)
|
song.Duration = fmt.Sprintf("%d", duration*1000)
|
||||||
|
|
||||||
if album, ok := resource.(*deezer.Album); ok {
|
if album, ok := resource.(*deezer.Album); ok {
|
||||||
t.addTag("TALB", album.Data.Title)
|
t.addTag("TALB", album.Results.Data.Title)
|
||||||
t.addTag("TPE2", album.Data.Artist)
|
t.addTag("TPE2", album.Results.Data.Artist)
|
||||||
t.addTag("TPUB", album.Data.Label)
|
t.addTag("TPUB", album.Results.Data.Label)
|
||||||
t.addTag("TDOR", album.Data.OriginalReleaseDate)
|
t.addTag("TDOR", album.Results.Data.OriginalReleaseDate)
|
||||||
t.addTag("TYER", album.Data.PhysicalReleaseDate)
|
t.addTag("TYER", album.Results.Data.PhysicalReleaseDate)
|
||||||
t.addTag("COMM", album.Data.ProducerLine)
|
t.addTag("COMM", album.Results.Data.ProducerLine)
|
||||||
t.addTag("TRCK", song.TrackNumber)
|
t.addTag("TRCK", song.TrackNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user