Skip to content

Commit 8736b62

Browse files
authored
feat: Enhance status command output with content ID option (#218)
- Added a flag to the status command to optionally print the content ID if available. - Refactored output logic for improved readability and maintainability. - Updated github actions and goreleaser configuration
1 parent ecc3967 commit 8736b62

File tree

5 files changed

+113
-78
lines changed

5 files changed

+113
-78
lines changed

.github/workflows/goreleaser.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
- name: Checkout
1515
uses: actions/checkout@master
1616
- name: Set up Go
17-
uses: actions/setup-go@v1
17+
uses: actions/setup-go@v5
1818
with:
19-
go-version: '1.23.2'
19+
go-version: '1.24.2'
2020
- name: Run GoReleaser
21-
uses: goreleaser/goreleaser-action@v1
21+
uses: goreleaser/goreleaser-action@v6
2222
with:
23-
version: v0.119.0
24-
args: release --rm-dist
23+
version: '~> v2'
24+
args: release --clean
2525
env:
2626
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go-version: [1.21.x, 1.22.x, 1.23.x]
13+
go-version: [1.21.x, 1.22.x, 1.23.x, 1.24.x]
1414
platform: [ubuntu-latest, macos-latest]
1515
fail-fast: false
1616
runs-on: ${{ matrix.platform }}
1717
steps:
1818
- name: Install Go
19-
uses: actions/setup-go@v2
19+
uses: actions/setup-go@v5
2020
with:
2121
go-version: ${{ matrix.go-version }}
2222
- name: Checkout code
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v4
2424
- name: Cache & restore go mod
25-
uses: actions/cache@v2
25+
uses: actions/cache@v4
2626
id: cache
2727
with:
2828
path: ~/go/pkg/mod
@@ -37,19 +37,19 @@ jobs:
3737
build:
3838
strategy:
3939
matrix:
40-
go-version: [1.21.x, 1.22.x, 1.23.x]
40+
go-version: [1.21.x, 1.22.x, 1.23.x, 1.24.x]
4141
platform: [ubuntu-latest, macos-latest]
4242
fail-fast: false
4343
runs-on: ${{ matrix.platform }}
4444
steps:
4545
- name: Install Go
46-
uses: actions/setup-go@v2
46+
uses: actions/setup-go@v5
4747
with:
4848
go-version: ${{ matrix.go-version }}
4949
- name: Checkout code
50-
uses: actions/checkout@v2
50+
uses: actions/checkout@v4
5151
- name: Cache & restore go mod
52-
uses: actions/cache@v2
52+
uses: actions/cache@v4
5353
id: cache
5454
with:
5555
path: ~/go/pkg/mod

.goreleaser.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
4+
# The lines below are called `modelines`. See `:help modeline`
5+
# Feel free to remove those if you don't want/need to use them.
6+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
7+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8+
9+
version: 2
10+
11+
before:
12+
hooks:
13+
# You may remove this if you don't use go modules.
14+
- go mod tidy
15+
# you may remove this if you don't need go generate
16+
- go generate ./...
17+
18+
builds:
19+
- env:
20+
- CGO_ENABLED=0
21+
goos:
22+
- linux
23+
- windows
24+
- darwin
25+
ldflags:
26+
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
27+
28+
archives:
29+
- formats: [tar.gz]
30+
# this name template makes the OS and Arch compatible with the results of `uname`.
31+
name_template: >-
32+
{{ .ProjectName }}_
33+
{{- title .Os }}_
34+
{{- if eq .Arch "amd64" }}x86_64
35+
{{- else if eq .Arch "386" }}i386
36+
{{- else }}{{ .Arch }}{{ end }}
37+
{{- if .Arm }}v{{ .Arm }}{{ end }}
38+
# use zip for windows archives
39+
format_overrides:
40+
- goos: windows
41+
formats: [zip]
42+
43+
changelog:
44+
sort: asc
45+
filters:
46+
exclude:
47+
- "^docs:"
48+
- "^test:"
49+
50+
release:
51+
footer: >-
52+
53+
---
54+
55+
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).

.goreleaser.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

cmd/status.go

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,57 @@ var statusCmd = &cobra.Command{
3030
exit("unable to get cast application: %v", err)
3131
}
3232
castApplication, castMedia, castVolume := app.Status()
33-
if castApplication == nil {
34-
outputInfo("Idle, volume=%0.2f muted=%t", castVolume.Level, castVolume.Muted)
35-
} else if castApplication.IsIdleScreen {
36-
outputInfo("Idle (%s), volume=%0.2f muted=%t", castApplication.DisplayName, castVolume.Level, castVolume.Muted)
37-
} else if castMedia == nil {
38-
outputInfo("Idle (%s), volume=%0.2f muted=%t", castApplication.DisplayName, castVolume.Level, castVolume.Muted)
39-
} else {
40-
metadata := "unknown"
41-
var usefulID string
42-
switch castMedia.Media.ContentType {
43-
case "x-youtube/video":
44-
usefulID = fmt.Sprintf("[%s] ", castMedia.Media.ContentId)
33+
volumeLevel := castVolume.Level
34+
volumeMuted := castVolume.Muted
35+
36+
contentId, _ := cmd.Flags().GetBool("content-id")
37+
38+
scriptMode := contentId
39+
40+
if scriptMode {
41+
if contentId {
42+
if castMedia != nil {
43+
outputInfo(castMedia.Media.ContentId)
44+
} else {
45+
outputInfo("not available")
46+
}
4547
}
46-
if castMedia.Media.Metadata.Title != "" {
47-
md := castMedia.Media.Metadata
48-
metadata = fmt.Sprintf("title=%q, artist=%q", md.Title, md.Artist)
48+
} else if castApplication == nil {
49+
outputInfo("Idle, volume=%0.2f muted=%t", volumeLevel, volumeMuted)
50+
} else {
51+
displayName := castApplication.DisplayName
52+
if castApplication.IsIdleScreen {
53+
outputInfo("Idle (%s), volume=%0.2f muted=%t", displayName, volumeLevel, volumeMuted)
54+
} else if castMedia == nil {
55+
outputInfo("Idle (%s), volume=%0.2f muted=%t", displayName, volumeLevel, volumeMuted)
56+
} else {
57+
var metadata string
58+
var usefulID string
59+
switch castMedia.Media.ContentType {
60+
case "x-youtube/video":
61+
usefulID = fmt.Sprintf("[%s] ", castMedia.Media.ContentId)
62+
}
63+
if castMedia.Media.Metadata.Title != "" {
64+
md := castMedia.Media.Metadata
65+
metadata = fmt.Sprintf("title=%q, artist=%q", md.Title, md.Artist)
66+
}
67+
if castMedia.Media.ContentId != "" {
68+
if metadata != "" {
69+
metadata += ", "
70+
}
71+
metadata += fmt.Sprintf("[%s]", castMedia.Media.ContentId)
72+
}
73+
if metadata == "" {
74+
metadata = "unknown"
75+
76+
}
77+
outputInfo("%s%s (%s), %s, time remaining=%.0fs/%.0fs, volume=%0.2f, muted=%t", usefulID, displayName, castMedia.PlayerState, metadata, castMedia.CurrentTime, castMedia.Media.Duration, volumeLevel, volumeMuted)
4978
}
50-
outputInfo("%s%s (%s), %s, time remaining=%.0fs/%.0fs, volume=%0.2f, muted=%t", usefulID, castApplication.DisplayName, castMedia.PlayerState, metadata, castMedia.CurrentTime, castMedia.Media.Duration, castVolume.Level, castVolume.Muted)
5179
}
5280
},
5381
}
5482

5583
func init() {
5684
rootCmd.AddCommand(statusCmd)
85+
statusCmd.Flags().Bool("content-id", false, "print the content id if available")
5786
}

0 commit comments

Comments
 (0)