Skip to content

Commit

Permalink
inital commit with support for passing spotify SongIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
philnielsen committed Dec 20, 2017
1 parent 3bb2949 commit 61b0485
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

#remove this so we can use dep correctly
vendor/*

#don't show this stuff
local.env
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:latest AS builder

ENV DEP_VERSION=v0.3.2

RUN curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/${DEP_VERSION}/dep-linux-amd64 && chmod +x /usr/local/bin/dep

RUN mkdir -p /go/src/github.com/trisongulate
WORKDIR /go/src/github.com/trisongulate

COPY Gopkg.toml Gopkg.lock ./
# copies the Gopkg.toml and Gopkg.lock to WORKDIR

RUN dep ensure -vendor-only

ADD . .
RUN go install .

ENTRYPOINT [ "/go/bin/trisongulate" ]
39 changes: 39 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"

7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
trisongulate:
build: .
env_file:
- local.env
command: 0zlTLKnLY5hYur9w2hPLqB 7bFOkwjxOcGaw6ZULE58Mh 5VS7aJFWhrm5U4gO7wHbVB
46 changes: 46 additions & 0 deletions trisongulate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"context"
"fmt"
"log"
"os"

"github.com/zmb3/spotify"
"golang.org/x/oauth2/clientcredentials"
)

func main() {
//Get Auth Token for Spotify
config := &clientcredentials.Config{
ClientID: os.Getenv("SPOTIFY_ID"),
ClientSecret: os.Getenv("SPOTIFY_SECRET"),
TokenURL: spotify.TokenURL,
}
token, err := config.Token(context.Background())
if err != nil {
log.Fatalf("couldn't get token: %v", err)
}

client := spotify.Authenticator{}.NewClient(token)

//Get Track IDs
trackIDs := []spotify.ID{spotify.ID(os.Args[1]), spotify.ID(os.Args[2]), spotify.ID(os.Args[3])}

//Build recommend Request
seeds := spotify.Seeds{
Artists: []spotify.ID{},
Tracks: trackIDs,
Genres: []string{},
}

//Get Recs from Spotify
recs, err := client.GetRecommendations(seeds, nil, nil)
if err != nil {
log.Fatalf("couldn't get Recs: %v", err)
}
for _, recommendations := range recs.Tracks {
fmt.Println(" ", recommendations.Name, " ", recommendations.Artists)
}

}

0 comments on commit 61b0485

Please sign in to comment.