diff --git a/main.go b/main.go index 745cf7d..73eac04 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "flag" "fmt" log "github.com/Sirupsen/logrus" "github.com/skratchdot/open-golang/open" @@ -124,6 +125,9 @@ func main() { os.Exit(1) } + str := flag.String("p", "", "Default playlist name") + flag.Parse() + url := os.Args[len(os.Args)-1] songs, err := GetShows(url) @@ -150,7 +154,7 @@ func main() { os.Exit(1) } - playlist, err := BuildPlaylist(client, songs, "GB") + playlist, err := BuildPlaylist(client, *str, songs, "GB") if err != nil { fmt.Println("Error building playlist:", err) diff --git a/spotify.go b/spotify.go index d5055ef..0e53104 100644 --- a/spotify.go +++ b/spotify.go @@ -93,7 +93,7 @@ func generateState() string { // BuildPlaylist creates a Spotify playlist and returns a playlist identifier. authedClient is // an authenticated Spotify client, and songs is a list of songs scraped from the Echoes website -func BuildPlaylist(authedClient *spotify.Client, songs []EchoesSong, market string) (string, error) { +func BuildPlaylist(authedClient *spotify.Client, playlistName string, songs []EchoesSong, market string) (string, error) { terms := echoesSongsToSearchStrings(songs) fmt.Println("Buildling playlist of", len(terms), "terms") results := make([]chan *spotify.SearchResult, 0, len(songs)) @@ -151,14 +151,16 @@ func BuildPlaylist(authedClient *spotify.Client, songs []EchoesSong, market stri } if len(tracks) > 0 { - return CreatePlaylist(authedClient, tracks) + return CreatePlaylist(authedClient, playlistName, tracks) } return "", errors.New("No tracks found") } // CreatePlaylist creates a new playlist given a set of tracks with a default name -func CreatePlaylist(authedClient *spotify.Client, tracks []spotify.FullTrack) (string, error) { - playlistName := generatePlaylistName(time.Now()) +func CreatePlaylist(authedClient *spotify.Client, playlistName string, tracks []spotify.FullTrack) (string, error) { + if playlistName == "" { + playlistName = generatePlaylistName(time.Now()) + } user, err := authedClient.CurrentUser() if err != nil {