mirror of
https://github.com/Superredstone/spotiflac-cli.git
synced 2026-03-07 20:18:07 +01:00
feat: improve metadata implementation for track
This commit is contained in:
@@ -5,60 +5,34 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Metadata struct {
|
||||
SpotifyID string `json:"spotify_id"`
|
||||
Artists string `json:"artists"`
|
||||
Name string `json:"name"`
|
||||
AlbumName string `json:"album_name"`
|
||||
AlbumArtist string `json:"album_artist"`
|
||||
DurationMS int `json:"duration_ms"`
|
||||
Images string `json:"images"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
TrackNumber int `json:"track_number"`
|
||||
TotalTracks int `json:"total_tracks"`
|
||||
DiscNumber int `json:"disc_number"`
|
||||
TotalDiscs int `json:"total_discs"`
|
||||
ExternalURLs string `json:"external_urls"`
|
||||
Copyright string `json:"copyright"`
|
||||
Publisher string `json:"publisher"`
|
||||
Plays string `json:"plays"`
|
||||
IsExplicit bool `json:"is_explicit"`
|
||||
}
|
||||
|
||||
func (app *App) GetMetadata(url string) (Metadata, error) {
|
||||
urlType := ParseUrlType(url)
|
||||
|
||||
switch urlType {
|
||||
case UrlTypeTrack:
|
||||
app.GetTrackMetadata(url)
|
||||
}
|
||||
|
||||
return Metadata{}, errors.New("Invalid URL.")
|
||||
}
|
||||
|
||||
func (app *App) GetTrackMetadata(url string) error {
|
||||
func (app *App) GetTrackMetadata(url string) (TrackMetadata, error) {
|
||||
client := NewSpotifyClient()
|
||||
var result TrackMetadata
|
||||
|
||||
err := client.Initialize()
|
||||
if err != nil {
|
||||
return errors.New("Unable to fetch Spotify metadata.")
|
||||
return result, errors.New("Unable to fetch Spotify metadata.")
|
||||
}
|
||||
|
||||
trackId, err := ParseTrackId(url)
|
||||
if err != nil {
|
||||
return err
|
||||
return result, err
|
||||
}
|
||||
|
||||
payload := BuildSpotifyReqPayloadTrack(trackId)
|
||||
|
||||
rawMetadata, err := client.Query(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
return result, err
|
||||
}
|
||||
a, err := json.Marshal(rawMetadata)
|
||||
println(string(a))
|
||||
|
||||
return nil
|
||||
byteMetadata, err := json.Marshal(rawMetadata)
|
||||
err = json.Unmarshal(byteMetadata, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (app *App) PrintMetadata(url string) error {
|
||||
|
||||
Reference in New Issue
Block a user