feat(workflows): add release
This commit is contained in:
28
.github/workflows/release.yml
vendored
Normal file
28
.github/workflows/release.yml
vendored
Normal 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
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
__debug_bin
|
__debug_bin
|
||||||
dist
|
dist
|
||||||
|
.idea
|
||||||
10
README.md
10
README.md
@@ -1,14 +1,12 @@
|
|||||||
# OBS Spotify
|
# OBS Spotify – MacOS
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 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
61
main.go
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user