Files
spotiflac-cli/lib/utils.go

36 lines
618 B
Go

package lib
import (
"errors"
"strings"
)
type UrlType int
const (
UrlTypeTrack UrlType = iota
UrlTypePlaylist
)
func ParseUrlType(url string) (UrlType, error) {
if strings.Contains(url, "https://open.spotify.com/track") {
return UrlTypeTrack, nil
}
if strings.Contains(url, "https://open.spotify.com/playlist") {
return UrlTypePlaylist, nil
}
return UrlTypeTrack, errors.New("Invalid URL, not a playlist nor a track.")
}
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
}