feat(cli): add config flag

This commit is contained in:
Mathis Maquenne
2024-10-14 16:22:39 +02:00
parent 05e7f56d4e
commit b49334a810
9 changed files with 194 additions and 15 deletions
+9
View File
@@ -0,0 +1,9 @@
package config
type Config struct {
LicenseToken string `mapstructure:"license_token"`
SecretKey string `mapstructure:"secret_key"`
IV string `mapstructure:"iv"`
}
var Cfg Config
+9 -7
View File
@@ -3,21 +3,18 @@ package crypto
import (
"crypto/cipher"
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/mathismqn/godeez/internal/config"
"golang.org/x/crypto/blowfish"
)
const (
SecretKey = ""
IV = ""
)
func GetBlowfishKey(songID string) []byte {
hash := md5.Sum([]byte(songID))
hashHex := fmt.Sprintf("%x", hash)
key := []byte(SecretKey)
key := []byte(config.Cfg.SecretKey)
for i := 0; i < len(hash); i++ {
key[i] = key[i] ^ hashHex[i] ^ hashHex[i+16]
}
@@ -31,7 +28,12 @@ func DecryptBlowfish(data, key []byte) ([]byte, error) {
return nil, err
}
mode := cipher.NewCBCDecrypter(block, []byte(IV))
iv, err := hex.DecodeString(config.Cfg.IV)
if err != nil {
return nil, err
}
mode := cipher.NewCBCDecrypter(block, iv)
decrypted := make([]byte, len(data))
mode.CryptBlocks(decrypted, data)
+3 -3
View File
@@ -6,6 +6,8 @@ import (
"fmt"
"io"
"net/http"
"github.com/mathismqn/godeez/internal/config"
)
type Song struct {
@@ -16,10 +18,8 @@ type Song struct {
TrackToken string `json:"TRACK_TOKEN"`
}
const LicenseToken = ""
func (s *Song) GetMediaData() (*Media, error) {
reqBody := fmt.Sprintf(`{"license_token":"%s","media":[{"type":"FULL","formats":[{"cipher":"BF_CBC_STRIPE","format":"FLAC"}]}],"track_tokens":["%s"]}`, LicenseToken, s.TrackToken)
reqBody := fmt.Sprintf(`{"license_token":"%s","media":[{"type":"FULL","formats":[{"cipher":"BF_CBC_STRIPE","format":"FLAC"}]}],"track_tokens":["%s"]}`, config.Cfg.LicenseToken, s.TrackToken)
resp, err := http.Post("https://media.deezer.com/v1/get_url", "application/json", bytes.NewBuffer([]byte(reqBody)))
if err != nil {