mirror of
https://github.com/Superredstone/spotiflac-cli.git
synced 2026-03-07 20:18:07 +01:00
feat: add first metadata implementation
This commit is contained in:
@@ -30,7 +30,12 @@ func (app *App) Download(url string, outputFolder string, serviceString string)
|
|||||||
serviceString = DEFAULT_DOWNLOAD_SERVICE
|
serviceString = DEFAULT_DOWNLOAD_SERVICE
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = GetUrlType(url)
|
_, err := app.GetMetadata(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = ParseUrlType(url)
|
||||||
|
|
||||||
return errors.New("Invalid URL.")
|
return errors.New("Invalid URL.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,9 +26,41 @@ type Metadata struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) GetMetadata(url string) (Metadata, error) {
|
func (app *App) GetMetadata(url string) (Metadata, error) {
|
||||||
return Metadata{}, nil
|
urlType := ParseUrlType(url)
|
||||||
|
|
||||||
|
switch urlType {
|
||||||
|
case UrlTypeTrack:
|
||||||
|
app.GetTrackMetadata(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Metadata{}, errors.New("Invalid URL.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) GetTrackMetadata(url string) error {
|
||||||
|
client := NewSpotifyClient()
|
||||||
|
|
||||||
|
err := client.Initialize()
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Unable to fetch Spotify metadata.")
|
||||||
|
}
|
||||||
|
|
||||||
|
trackId, err := ParseTrackId(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
payload := BuildSpotifyReqPayloadTrack(trackId)
|
||||||
|
|
||||||
|
rawMetadata, err := client.Query(payload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a, err := json.Marshal(rawMetadata)
|
||||||
|
println(string(a))
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) PrintMetadata(url string) error {
|
func (app *App) PrintMetadata(url string) error {
|
||||||
return errors.New("Invalid URL.")
|
return errors.New("Unimplemented.")
|
||||||
}
|
}
|
||||||
|
|||||||
1837
lib/spotfetch.go
Normal file
1837
lib/spotfetch.go
Normal file
File diff suppressed because it is too large
Load Diff
13
lib/utils.go
13
lib/utils.go
@@ -1,6 +1,7 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ const (
|
|||||||
UrlTypeInvalid
|
UrlTypeInvalid
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUrlType(url string) UrlType {
|
func ParseUrlType(url string) UrlType {
|
||||||
if strings.Contains(url, "https://open.spotify.com/track") {
|
if strings.Contains(url, "https://open.spotify.com/track") {
|
||||||
return UrlTypeTrack
|
return UrlTypeTrack
|
||||||
}
|
}
|
||||||
@@ -23,3 +24,13 @@ func GetUrlType(url string) UrlType {
|
|||||||
|
|
||||||
return UrlTypeInvalid
|
return UrlTypeInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseTrackId(url string) (string, error) {
|
||||||
|
tmp := strings.Split(url, "/")
|
||||||
|
|
||||||
|
if len(tmp) == 0 {
|
||||||
|
return "", errors.New("Invalid URL.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp[len(tmp)-1], nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user