From 6d660e3f512cedd1cb225935425dc1e04b636ed0 Mon Sep 17 00:00:00 2001 From: Mathis Maquenne <124215603+mathismqn@users.noreply.github.com> Date: Sun, 13 Oct 2024 16:07:42 +0200 Subject: [PATCH] feat(playlist): download private playlists with arl cookie --- .example-config | 5 +++-- cmd/download.go | 6 ++++++ internal/config/config.go | 1 + internal/deezer/playlist.go | 4 +++- internal/deezer/resource.go | 17 ++++++++++++++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.example-config b/.example-config index 2a3ad61..ff4d1fd 100644 --- a/.example-config +++ b/.example-config @@ -1,3 +1,4 @@ -license_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' +license_token = 'AAAAA1bcDFgHJKLmnOPqrsTUvwXYZ12o3lmNOjR2xWiQRT3v5zxL4mKoWjxL82jD7sWx93KfYGsN2IkdPxsUw9PTas7oFbgR3nY9qpZmVyHFJKLPxT7sWmqErXyTn5iKoNpRtV7bPdQZ8qLmWoJpU2nKrXz6vW' +arl_cookie = '1d9e90abb452a61b1b7463f0953e1b303c4e2e7e5fd404fde9b385f4de01c340ac0f62f1c8c1550405b0b9beded0e28c481e96a6148e8f4548351add5d7db746b2785ecf83b1768e5dd8cc73b1ad30c18d07c9cb37f5c6b9cd7a78a4de2aff11' secret_key = 'hTv1IAw19qWy9i3f' -iv = 'cn1aSvHsV4yBO7x5' \ No newline at end of file +iv = '0001020304050607' \ No newline at end of file diff --git a/cmd/download.go b/cmd/download.go index cc0d2f9..5e704c0 100644 --- a/cmd/download.go +++ b/cmd/download.go @@ -71,6 +71,12 @@ func downloadContent(contentType string, args []string) { fmt.Fprintf(os.Stderr, "Error: could not get playlist data: %v\n", err) continue } + if playlist.Data.Status == 1 && playlist.Data.CollabKey == "" { + 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") + continue + } + resource = playlist songs = playlist.GetSongs() } diff --git a/internal/config/config.go b/internal/config/config.go index c0daa61..0a30e86 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config type Config struct { LicenseToken string `mapstructure:"license_token"` + ArlCookie string `mapstructure:"arl_cookie"` SecretKey string `mapstructure:"secret_key"` IV string `mapstructure:"iv"` } diff --git a/internal/deezer/playlist.go b/internal/deezer/playlist.go index 24f41ff..2715b12 100644 --- a/internal/deezer/playlist.go +++ b/internal/deezer/playlist.go @@ -9,7 +9,9 @@ import ( type Playlist struct { Data struct { - Title string `json:"TITLE"` + Title string `json:"TITLE"` + Status int `json:"STATUS"` + CollabKey string `json:"COLLAB_KEY"` } `json:"DATA"` Songs struct { Data []*Song `json:"data"` diff --git a/internal/deezer/resource.go b/internal/deezer/resource.go index 766a50b..aa16c9b 100644 --- a/internal/deezer/resource.go +++ b/internal/deezer/resource.go @@ -5,6 +5,8 @@ import ( "io" "net/http" "regexp" + + "github.com/mathismqn/godeez/internal/config" ) type Resource interface { @@ -18,7 +20,20 @@ type Resource interface { func GetData(r Resource, id string) error { url := r.GetURL(id) - resp, err := http.Get(url) + client := &http.Client{} + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return err + } + + if config.Cfg.ArlCookie != "" { + req.AddCookie(&http.Cookie{ + Name: "arl", + Value: config.Cfg.ArlCookie, + }) + } + + resp, err := client.Do(req) if err != nil { return err }