Compare commits

...

10 Commits

Author SHA1 Message Date
485ec0ec0a escape double quotes
Some checks failed
continuous-integration/drone/push Build is failing
2022-01-27 18:00:49 +00:00
39f84a94ac write connection refused error to stderr
All checks were successful
continuous-integration/drone/push Build is passing
2022-01-24 14:30:38 +00:00
4b71fa248a Truncate file when directly sharing
All checks were successful
continuous-integration/drone/push Build is passing
Fixes bug where recipient instance would have a bit of the previous
track data on the end of the output if the previous track data was
longer, which effectively froze the output on waybar as it was no longer
valid JSON.
2021-10-29 15:10:53 +01:00
c26c13e984 upload to buildrone before apt
All checks were successful
continuous-integration/drone/push Build is passing
2021-06-25 01:57:29 +01:00
174d243f15 fix apt versioning
Some checks failed
continuous-integration/drone/push Build is failing
2021-05-31 23:19:31 +01:00
6cab493189 mention repo in README
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-24 22:44:07 +01:00
69be0dcf8a fix typo
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-24 21:48:44 +01:00
22ad0e29cb make debs/rpms, upload .debs to repo
Some checks failed
continuous-integration/drone/push Build is failing
2021-05-24 20:27:45 +01:00
8340ef1f20 always return the expected number of bytes written
All checks were successful
continuous-integration/drone/push Build is passing
emptyEveryWrite was returning the wrong number, so it ignores the real
value and just returns the expected value (len(bytes in)). For #4 again.
2021-05-24 14:51:21 +01:00
fe851278f4 change order of writers in io.Multiwriter
All checks were successful
continuous-integration/drone/push Build is passing
io.MultiWriter (i think) thinks dataWrite.Write fails, and so doesn't
continue writing to all other outputs. This just makes it the last one,
should fix #4.
2021-05-21 16:03:33 +01:00
14 changed files with 80 additions and 115 deletions

View File

@@ -5,20 +5,29 @@ type: docker
steps: steps:
- name: build - name: build
image: golang:latest image: golang:latest
volumes:
- name: ssh_key
path: /id_rsa
commands: commands:
- apt update -y - apt update -y
- apt install -y python3-pip curl - apt install -y python3-pip curl
- go mod download - go mod download
- curl -sL https://git.io/goreleaser > goreleaser.sh - curl -sL https://git.io/goreleaser > goreleaser.sh
- chmod +x goreleaser.sh - chmod +x goreleaser.sh
- ./goreleaser.sh --snapshot --skip-publish --rm-dist - ./version.sh ./goreleaser.sh --snapshot --skip-publish --rm-dist
- wget https://builds.hrfee.pw/upload.py - wget https://builds.hrfee.pw/upload.py
- pip3 install requests - pip3 install requests
- bash -c 'python3 upload.py https://builds2.hrfee.pw hrfee waybar-mpris --upload ./dist/*.tar.gz' - bash -c 'python3 upload.py https://builds2.hrfee.pw hrfee waybar-mpris --upload ./dist/*.tar.gz ./dist/*.rpm'
- bash -c 'sftp -P 2022 -i /id_rsa -o StrictHostKeyChecking=no root@161.97.102.153:/repo/incoming <<< $"put dist/*.deb"'
- bash -c 'ssh -i /id_rsa root@161.97.102.153 -p 2022 "repo-process-deb trusty-unstable"'
environment: environment:
BUILDRONE_KEY: BUILDRONE_KEY:
from_secret: BUILDRONE_KEY from_secret: BUILDRONE_KEY
volumes:
- name: ssh_key
host:
path: /root/.ssh/id_rsa_packaging
trigger: trigger:
branch: branch:
- main - main

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
./main ./main
waybar-mpris waybar-mpris
dist/*

View File

@@ -8,7 +8,8 @@ before:
hooks: hooks:
- go mod download - go mod download
builds: builds:
- dir: ./ - id: main
dir: ./
env: env:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
@@ -18,16 +19,37 @@ builds:
- arm - arm
- arm64 - arm64
archives: archives:
- replacements: - id: main
builds:
- main
replacements:
linux: Linux linux: Linux
amd64: x86_64 amd64: x86_64
checksum: checksum:
name_template: 'checksums.txt' name_template: 'checksums.txt'
snapshot: snapshot:
name_template: "git-{{.ShortCommit}}" name_template: "0.0.0-{{.Env.NFPM_EPOCH}}"
changelog: changelog:
sort: asc sort: asc
filters: filters:
exclude: exclude:
- '^docs:' - '^docs:'
- '^test:' - '^test:'
nfpms:
- id: main
file_name_template: '{{ .ProjectName }}-git-{{ .ShortCommit }}_{{ .Arch }}'
package_name: waybar-mpris
homepage: https://git.hrfee.pw/hrfee/waybar-mpris
description: MPRIS2 waybar component
maintainer: Harvey Tindall <hrfee@hrfee.dev>
license: MIT
vendor: hrfee.dev
version_metadata: git
builds:
- main
contents:
- src: ./LICENSE
dst: /usr/share/licenses/waybar-mpris
formats:
- deb
- rpm

View File

@@ -21,6 +21,15 @@ MPRIS2 is widely supported, so this component should work with:
## Install ## Install
Available on the AUR as [waybar-mpris-git](https://aur.archlinux.org/packages/waybar-mpris-git/) (Thanks @nichobi!) Available on the AUR as [waybar-mpris-git](https://aur.archlinux.org/packages/waybar-mpris-git/) (Thanks @nichobi!)
Available on my Debian repo as well:
```sh
sudo apt-get update && sudo apt-get install curl apt-transport-https gnupg
curl https://apt.hrfee.dev/hrfee.pubkey.gpg | sudo apt-key add -
echo "deb https://apt.hrfee.dev trusty-unstable main" | sudo tee /etc/apt/sources.list.d/hrfee.list
sudo apt-get update
sudo apt-get install waybar-mpris
```
`go get git.hrfee.pw/hrfee/waybar-mpris` will compile from source and install. `go get git.hrfee.pw/hrfee/waybar-mpris` will compile from source and install.
You can also download a precompiled binary from [here](https://builds2.hrfee.pw/view/hrfee/waybar-mpris). You can also download a precompiled binary from [here](https://builds2.hrfee.pw/view/hrfee/waybar-mpris).

3
dist/checksums.txt vendored
View File

@@ -1,3 +0,0 @@
57ca953082ee67820539a128d6c285b1bc1e4e917e1376c86cbbc2436880330a waybar-mpris_git-750317a_Linux_x86_64.tar.gz
6e638c4c4e7b1aa324abbbbedda193600390988001c9d4c8d5ed4700f1f6ca0a waybar-mpris_git-750317a_Linux_armv6.tar.gz
c710c2cd4e4a3ed3c4d5e2b8f2a86077904c26365102496ea9b429e5ad2204a6 waybar-mpris_git-750317a_Linux_arm64.tar.gz

88
dist/config.yaml vendored
View File

@@ -1,88 +0,0 @@
project_name: waybar-mpris
release:
github:
owner: hrfee
name: waybar-mpris
gitea:
owner: hrfee
name: waybar-mpris
name_template: v{{.Version}}
milestones:
- repo:
owner: hrfee
name: waybar-mpris
name_template: '{{ .Tag }}'
scoop:
name: waybar-mpris
commit_author:
name: goreleaserbot
email: goreleaser@carlosbecker.com
commit_msg_template: Scoop update for {{ .ProjectName }} version {{ .Tag }}
builds:
- id: waybar-mpris
goos:
- linux
goarch:
- amd64
- arm
- arm64
goarm:
- "6"
targets:
- linux_amd64
- linux_arm_6
- linux_arm64
dir: ./
main: .
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser
binary: waybar-mpris
env:
- CGO_ENABLED=0
lang: go
gobinary: go
archives:
- id: default
builds:
- waybar-mpris
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
replacements:
amd64: x86_64
linux: Linux
format: tar.gz
files:
- licence*
- LICENCE*
- license*
- LICENSE*
- readme*
- README*
- changelog*
- CHANGELOG*
allow_different_binary_count: false
snapshot:
name_template: git-{{.ShortCommit}}
checksum:
name_template: checksums.txt
algorithm: sha256
changelog:
filters:
exclude:
- '^docs:'
- '^test:'
sort: asc
dist: dist
env_files:
github_token: ~/.config/goreleaser/github_token
gitlab_token: ~/.config/goreleaser/gitlab_token
gitea_token: ~/.config/goreleaser/gitea_token
before:
hooks:
- go mod download
source:
name_template: '{{ .ProjectName }}-{{ .Version }}'
format: tar.gz
github_urls:
download: https://github.com
gitlab_urls:
download: https://gitlab.com

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

51
main.go
View File

@@ -150,6 +150,10 @@ func secondsToString(seconds int) string {
// JSON returns json for waybar to consume. // JSON returns json for waybar to consume.
func playerJSON(p *player) string { func playerJSON(p *player) string {
artist := strings.ReplaceAll(p.Artist, "\"", "\\\"")
album := strings.ReplaceAll(p.Album, "\"", "\\\"")
title := strings.ReplaceAll(p.Title, "\"", "\\\"")
name := strings.ReplaceAll(p.Name, "\"", "\\\"")
symbol := PLAY symbol := PLAY
out := "{\"class\": \"" out := "{\"class\": \""
if p.Playing { if p.Playing {
@@ -177,24 +181,24 @@ func playerJSON(p *player) string {
case "SYMBOL": case "SYMBOL":
items = append(items, symbol) items = append(items, symbol)
case "ARTIST": case "ARTIST":
if p.Artist != "" { if artist != "" {
items = append(items, p.Artist) items = append(items, artist)
} }
case "ALBUM": case "ALBUM":
if p.Album != "" { if album != "" {
items = append(items, p.Album) items = append(items, album)
} }
case "TITLE": case "TITLE":
if p.Title != "" { if title != "" {
items = append(items, p.Title) items = append(items, title)
} }
case "POSITION": case "POSITION":
if pos != "" && SHOW_POS { if pos != "" && SHOW_POS {
items = append(items, pos) items = append(items, pos)
} }
case "PLAYER": case "PLAYER":
if p.Name != "" { if name != "" {
items = append(items, p.Name) items = append(items, name)
} }
} }
} }
@@ -214,14 +218,14 @@ func playerJSON(p *player) string {
text += v + right text += v + right
} }
out += "\",\"text\":\"" + text + "\"," out += "\",\"text\":\"" + text + "\","
out += "\"tooltip\":\"" + strings.ReplaceAll(p.Title, "&", "&amp;") + "\\n" out += "\"tooltip\":\"" + strings.ReplaceAll(title, "&", "&amp;") + "\\n"
if p.Artist != "" { if artist != "" {
out += "by " + strings.ReplaceAll(p.Artist, "&", "&amp;") + "\\n" out += "by " + strings.ReplaceAll(artist, "&", "&amp;") + "\\n"
} }
if p.Album != "" { if album != "" {
out += "from " + strings.ReplaceAll(p.Album, "&", "&amp;") + "\\n" out += "from " + strings.ReplaceAll(album, "&", "&amp;") + "\\n"
} }
out += "(" + p.Name + ")\"}" out += "(" + name + ")\"}"
return out return out
// return fmt.Sprintf("{\"class\":\"%s\",\"text\":\"%s\",\"tooltip\":\"%s\"}", data["class"], data["text"], data["tooltip"]) // return fmt.Sprintf("{\"class\":\"%s\",\"text\":\"%s\",\"tooltip\":\"%s\"}", data["class"], data["text"], data["tooltip"])
// out, err := json.Marshal(data) // out, err := json.Marshal(data)
@@ -484,9 +488,9 @@ func listenForCommands(players *players) {
players, players,
} }
if isSharing { if isSharing {
WRITER = io.MultiWriter(SHAREWRITER, DATAWRITER, os.Stdout) WRITER = io.MultiWriter(os.Stdout, SHAREWRITER, DATAWRITER)
} else { } else {
WRITER = io.MultiWriter(DATAWRITER, os.Stdout) WRITER = io.MultiWriter(os.Stdout, DATAWRITER)
} }
isDataSharing = true isDataSharing = true
} }
@@ -530,7 +534,9 @@ type dataWrite struct {
func (w dataWrite) Write(p []byte) (n int, err error) { func (w dataWrite) Write(p []byte) (n int, err error) {
line := toData(&player{w.Players.mpris2.List[w.Players.mpris2.Current], true}) line := toData(&player{w.Players.mpris2.List[w.Players.mpris2.Current], true})
return w.emptyEveryWrite.Write([]byte(line)) _, err = w.emptyEveryWrite.Write([]byte(line))
n = len(p)
return
} }
type emptyEveryWrite struct { type emptyEveryWrite struct {
@@ -538,11 +544,18 @@ type emptyEveryWrite struct {
} }
func (w emptyEveryWrite) Write(p []byte) (n int, err error) { func (w emptyEveryWrite) Write(p []byte) (n int, err error) {
n = len(p)
// Set new size in case previous data was longer and would leave garbage at the end of the file.
err = w.file.Truncate(int64(n))
if err != nil {
return 0, err
}
offset, err := w.file.Seek(0, 0) offset, err := w.file.Seek(0, 0)
if err != nil { if err != nil {
return 0, err return 0, err
} }
return w.file.WriteAt(p, offset) _, err = w.file.WriteAt(p, offset)
return
} }
func main() { func main() {
@@ -591,7 +604,7 @@ func main() {
} }
// When waybar-mpris is already running, we attach to its output instead of launching a whole new instance. // When waybar-mpris is already running, we attach to its output instead of launching a whole new instance.
} else if err := duplicateOutput(); err != nil { } else if err := duplicateOutput(); err != nil {
os.Stdout.WriteString("Couldn't dial socket, deleting instead: " + err.Error()) os.Stderr.WriteString("Couldn't dial socket, deleting instead: " + err.Error())
os.Remove(SOCK) os.Remove(SOCK)
os.Remove(OUTFILE) os.Remove(OUTFILE)
} }

2
version.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
NFPM_EPOCH=$(git rev-list --all --count) $@