mirror of
https://github.com/Superredstone/spotiflac-cli.git
synced 2026-03-07 20:18:07 +01:00
41 lines
710 B
Go
41 lines
710 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.")
|
|
}
|
|
|
|
tmp2 := strings.Split(tmp[len(tmp)-1], "?")
|
|
if len(tmp2) == 0 {
|
|
return tmp[len(tmp)-1], nil
|
|
}
|
|
|
|
return tmp2[0], nil
|
|
}
|