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"

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.DS_Store
__debug_bin
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)
## 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

61
main.go
View File

@@ -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)
}