feat(workflows): add release

This commit is contained in:
Ilya Suhodolskiy
2024-08-27 16:32:42 +04:00
parent 7afbff6a12
commit 1ac176f43d
4 changed files with 67 additions and 35 deletions

28
.github/workflows/release.yml vendored Normal file
View File

@@ -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"

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.DS_Store .DS_Store
__debug_bin __debug_bin
dist dist
.idea

View File

@@ -1,14 +1,12 @@
# OBS Spotify # OBS Spotify MacOS
![Cover](https://github.com/suhodolskiy/obs-spotify/blob/main/.github/cover.jpg) ![Cover](https://github.com/suhodolskiy/obs-spotify/blob/main/.github/cover.jpg)
## How to use? ## How to use?
1. Download ZIP from last release 1. Download the latest release for your platform & architecture and decompress the file.
2. Open obs-spotify binary 2. Run file.
3. Add new "Browser" source in OBS 3. Add Overlay to OBS Studio with URL from application.
4. Add http://localhost:3000 url
5. Save source
### Options ### Options

61
main.go
View File

@@ -1,17 +1,19 @@
package main package main
import ( import (
"embed"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"net/http" "net/http"
"os"
"os/exec" "os/exec"
"path/filepath"
"text/template" "text/template"
"time" "time"
) )
//go:embed index.html
var tpl embed.FS
const command = ` const command = `
tell application "Spotify" tell application "Spotify"
set ctrack to "{" set ctrack to "{"
@@ -77,43 +79,46 @@ func main() {
port := flag.String("port", "5783", "http port") port := flag.String("port", "5783", "http port")
flag.Parse() flag.Parse()
ex, _ := os.Executable() tmpl, err := template.ParseFS(tpl, "index.html")
tmpl, err := template.ParseFiles(filepath.Join(ex, "../index.html"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { http.HandleFunc(
response := Response{ "/", func(w http.ResponseWriter, req *http.Request) {
Track: getCurrentTrack(), response := Response{
Refresh: time.Second.Milliseconds(), Track: getCurrentTrack(),
Port: *port, 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()
} }
}
if err := tmpl.Execute(w, response); err != nil { refreshQueryParam := req.URL.Query().Get("refresh")
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
http.HandleFunc("/track", func(w http.ResponseWriter, req *http.Request) { if refreshQueryParam != "" {
w.Header().Set("Content-Type", "application/json") if duration, err := time.ParseDuration(refreshQueryParam); err == nil {
w.Header().Set("Access-Control-Allow-Origin", "*") 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) http.ListenAndServe(fmt.Sprintf(":%s", *port), nil)
} }