diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2954ae7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: Release Go Binaries + +on: + release: + types: [created] + workflow_dispatch: + +permissions: + contents: write + packages: write + +jobs: + releases-matrix: + name: Release Go Binary + runs-on: ubuntu-latest + strategy: + matrix: + goos: [darwin] + goarch: [amd64, arm64] + steps: + - uses: actions/checkout@v4 + - uses: wangyoucao577/go-release-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + goversion: "1.18" + ldflags: "-s -w" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6ec00ec..cde5b7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store __debug_bin -dist \ No newline at end of file +dist +.idea \ No newline at end of file diff --git a/README.md b/README.md index 28bd811..eb9f665 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ -# OBS Spotify +# OBS Spotify – MacOS ![Cover](https://github.com/suhodolskiy/obs-spotify/blob/main/.github/cover.jpg) ## How to use? -1. Download ZIP from last release -2. Open obs-spotify binary -3. Add new "Browser" source in OBS -4. Add http://localhost:3000 url -5. Save source +1. Download the latest release for your platform & architecture and decompress the file. +2. Run file. +3. Add Overlay to OBS Studio with URL from application. ### Options diff --git a/main.go b/main.go index e4e4bb7..b4145c2 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,19 @@ package main import ( + "embed" "encoding/json" "flag" "fmt" "net/http" - "os" "os/exec" - "path/filepath" "text/template" "time" ) +//go:embed index.html +var tpl embed.FS + const command = ` tell application "Spotify" set ctrack to "{" @@ -77,43 +79,46 @@ func main() { port := flag.String("port", "5783", "http port") flag.Parse() - ex, _ := os.Executable() - tmpl, err := template.ParseFiles(filepath.Join(ex, "../index.html")) + tmpl, err := template.ParseFS(tpl, "index.html") if err != nil { panic(err) } - http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { - response := Response{ - Track: getCurrentTrack(), - Refresh: time.Second.Milliseconds(), - Port: *port, - } - - refreshQueryParam := req.URL.Query().Get("refresh") - - if refreshQueryParam != "" { - if duration, err := time.ParseDuration(refreshQueryParam); err == nil { - response.Refresh = duration.Milliseconds() + http.HandleFunc( + "/", func(w http.ResponseWriter, req *http.Request) { + response := Response{ + Track: getCurrentTrack(), + Refresh: time.Second.Milliseconds(), + Port: *port, } - } - if err := tmpl.Execute(w, response); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - }) + refreshQueryParam := req.URL.Query().Get("refresh") - http.HandleFunc("/track", func(w http.ResponseWriter, req *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.Header().Set("Access-Control-Allow-Origin", "*") + if refreshQueryParam != "" { + if duration, err := time.ParseDuration(refreshQueryParam); err == nil { + response.Refresh = duration.Milliseconds() + } + } - resp, _ := json.Marshal(getCurrentTrack()) + if err := tmpl.Execute(w, response); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + }, + ) - fmt.Fprint(w, string(resp)) - }) + http.HandleFunc( + "/track", func(w http.ResponseWriter, req *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.Header().Set("Access-Control-Allow-Origin", "*") - fmt.Printf("The server is running on port %s!", *port) + resp, _ := json.Marshal(getCurrentTrack()) + + fmt.Fprint(w, string(resp)) + }, + ) + + fmt.Printf("Add Overlay to OBS Studio with URL: http://localhost:%s/", *port) http.ListenAndServe(fmt.Sprintf(":%s", *port), nil) }