mirror of
https://github.com/Superredstone/spotiflac-cli.git
synced 2026-03-07 20:18:07 +01:00
style: clean url recognition
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Superredstone/spotiflac-cli/app"
|
"github.com/Superredstone/spotiflac-cli/app"
|
||||||
)
|
)
|
||||||
@@ -19,7 +18,10 @@ func Download(application *app.App, url string, output_folder string) error {
|
|||||||
output_folder = DEFAULT_DOWNLOAD_OUTPUT_FOLDER
|
output_folder = DEFAULT_DOWNLOAD_OUTPUT_FOLDER
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(url, "https://open.spotify.com/track") {
|
url_type := GetUrlType(url)
|
||||||
|
|
||||||
|
switch url_type {
|
||||||
|
case UrlTypeTrack:
|
||||||
metadata, err := GetMetadata[MetadataSong](application, url)
|
metadata, err := GetMetadata[MetadataSong](application, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -40,10 +42,9 @@ func Download(application *app.App, url string, output_folder string) error {
|
|||||||
|
|
||||||
_, err = application.DownloadTrack(downloadRequest)
|
_, err = application.DownloadTrack(downloadRequest)
|
||||||
return err
|
return err
|
||||||
} else if strings.Contains(url, "https://open.spotify.com/playlist") {
|
case UrlTypePlaylist:
|
||||||
metadata, err := GetMetadata[MetadataPlaylist](application, url)
|
metadata, err := GetMetadata[MetadataPlaylist](application, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unable to fetch metadata for song " + url)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,5 +71,5 @@ func Download(application *app.App, url string, output_folder string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New("Invalid Spotify URL.")
|
return errors.New("Invalid URL.")
|
||||||
}
|
}
|
||||||
|
|||||||
25
pkg/utils.go
Normal file
25
pkg/utils.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UrlType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
UrlTypeTrack UrlType = iota
|
||||||
|
UrlTypePlaylist
|
||||||
|
UrlTypeInvalid
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetUrlType(url string) UrlType {
|
||||||
|
if strings.Contains(url, "https://open.spotify.com/track") {
|
||||||
|
return UrlTypeTrack
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(url, "https://open.spotify.com/playlist") {
|
||||||
|
return UrlTypePlaylist
|
||||||
|
}
|
||||||
|
|
||||||
|
return UrlTypeInvalid
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user