Skip to content

Commit

Permalink
Custom playlist name via command line
Browse files Browse the repository at this point in the history
Fulfills partial requirements for #2
  • Loading branch information
lawrencecraft committed Mar 4, 2016
1 parent fb42f59 commit 1dd7cd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"flag"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/skratchdot/open-golang/open"
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions spotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1dd7cd3

Please sign in to comment.