Skip to content

Commit 1181416

Browse files
committed
added --version cmd line flag
Closes: #28
1 parent d463a19 commit 1181416

File tree

4 files changed

+40
-206
lines changed

4 files changed

+40
-206
lines changed

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ before:
99
builds:
1010
- env:
1111
- CGO_ENABLED=0
12+
ldflags:
13+
- -s -w -X main.build={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
1214
archive:
1315
replacements:
1416
darwin: Darwin

README.md

Lines changed: 3 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -1,207 +1,8 @@
1-
# Chromecast
2-
3-
Implements a basic number of the google chromecast commands. Other than the basic commands, it also allows you to play media files from your computer either individually or in a playlist; the `playlist` command will look at all the files in a folder and play them sorted by numerically.
4-
5-
## Media Content Playable
6-
7-
Can play / load a local media file on your chromecast.
8-
9-
```
10-
Supported Media formats:
11-
- MP3
12-
- AVI
13-
- MKV
14-
- MP4
15-
- WebM
16-
- FLAC
17-
```
18-
19-
If an unknown file is found, it will use `ffmpeg` to transcode it to MP4, and stream it to the chromecast.
20-
21-
## Play Local Media Files
22-
23-
We are able to play local media files by creating a http server that will stream the media file to the cast device.
24-
25-
## Cast DNS Lookup
26-
27-
A DNS multicast is used to determine the Chromecast and Google Home devices.
28-
29-
The cast DNS entry is also cached, this means that if you pass through the device name, `-n <name>`, or the
30-
device uuid, `-u <uuid>`, the results will be cached and it will connect to the chromecast device instanly.
31-
32-
## Usage
33-
```
34-
# View available cast devices.
35-
$ go-chromecast ls
36-
Found 2 cast devices
37-
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
38-
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="" uuid="b87d86bed423a6feb8b91a7d2778b55c"
39-
40-
# Status of a cast device.
41-
$ go-chromecast status
42-
Found 2 cast dns entries, select one:
43-
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
44-
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="" uuid="b87d86bed423a6feb8b91a7d2778b55c"
45-
Enter selection: 1
46-
Idle (Backdrop), volume=1.00 muted=false
47-
48-
# Specify a cast device name.
49-
$ go-chromecast status -n "Living Room Speaker"
50-
Idle, volume=0.17 muted=false
51-
52-
# Specify a cat device by ip address.
53-
$ go-chromecast status -a 192.168.0.52
54-
Idle, volume=0.17 muted=false
55-
56-
# Specify a cast device uuid.
57-
$ go-chromecast status -u b87d86bed423a6feb8b91a7d2778b55c
58-
Idle (Default Media Receiver), volume=0.17 muted=false
59-
60-
# Load a local media file (can play both audio and video).
61-
$ go-chromecast load ~/Downloads/SampleAudio_0.4mb.mp3
62-
Found 2 cast dns entries, select one:
63-
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
64-
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="" uuid="b87d86bed423a6feb8b91a7d2778b55c"
65-
Enter selection: 2
66-
67-
# Status of cast device running an audio file.
68-
$ go-chromecast status
69-
Found 2 cast dns entries, select one:
70-
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
71-
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="Default Media Receiver" uuid="b87d86bed423a6feb8b91a7d2778b55c"
72-
Enter selection: 2
73-
Default Media Receiver (PLAYING), unknown, time remaining=8s/28s, volume=1.00, muted=false
74-
75-
# Play a playlist of media files.
76-
$ go-chromecast playlist ~/playlist_test/ -n "Living Room Speaker"
77-
Attemping to play the following media:
78-
- /home/jonathan/playlist_test/SampleAudio_0.4mb.mp3
79-
- /home/jonathan/playlist_test/sample_1.mp3
80-
81-
# Select where to start a playlist from.
82-
$ go-chromecast playlist ~/playlist_test/ -n "Living Room Speaker" --select
83-
Will play the following items, select where to start from:
84-
1) /home/jonathan/playlist_test/SampleAudio_0.4mb.mp3: last played "2018-11-25 11:17:25 +0000 GMT"
85-
2) /home/jonathan/playlist_test/sample_1.mp3: last played "2018-11-25 11:17:28 +0000 GMT"
86-
Enter selection: 2
87-
Attemping to play the following media:
88-
- /home/jonathan/playlist_test/sample_1.mp3
89-
90-
# Start a playlist from the start, ignoring if you have previously played that playlist.
91-
$ go-chromecast playlist ~/playlist_test/ -n "Living Room Speaker" --continue=false
92-
93-
# Pause the playing media.
94-
$ go-chromecast pause
95-
96-
# Continue playing the currently playing media.
97-
$ go-chromecast play
98-
99-
# Play the next item in a playlist.
100-
$ go-chromecast next
101-
102-
# Play the previous item in a playlist.
103-
$ go-chromecast previous
104-
105-
# Rewind the currently playing media by x seconds.
106-
$ go-chromecast rewind 30
107-
108-
# Go forward in the currently playing media by x seconds.
109-
$ go-chromecast seek 30
110-
111-
# View what a cast device is sending out.
112-
$ go-chromecast watch
113-
```
114-
115-
## Playlist
116-
117-
There is support for playing media items as a playlist.
118-
119-
If playing from a playlist, you are able to pass though the `--select` flag, and this will allow you to select
120-
the media to start playing from. This is useful if you have already played some of the media and want to start
121-
from one you haven't played yet.
122-
123-
A cache is kept of played media, so if you are playing media from a playlist, it will check to see what
124-
media files you have recently played and play the next one from the playlist. `--continue=false` can be passed
125-
through and this will start the playlist from the start.
126-
127-
## Watching a Device
128-
129-
If you would like to see what a device is sending, you are able to `watch` the protobuf messages being sent from your device:
130-
131-
```
132-
$ go-chromecast watch
133-
```
134-
135-
### Text To Speech
136-
137-
Experimental text-to-speech support has been added. This uses (Google
138-
Cloud's Text-to-Speech)[https://cloud.google.com/text-to-speech/] to
139-
turn text into an mp3 audio file, this is then streamed to the device.
140-
141-
Text-to-speech api needs to be enabled https://console.cloud.google.com/flows/enableapi?apiid=texttospeech.googleapis.com and a google service account is required https://console.cloud.google.com/apis/credentials/serviceaccountkey
142-
143-
```
144-
$ go-chromecast tts <message> --google-service-account=/path/to/service/account.json
145-
```
146-
147-
148-
## User Interface
149-
150-
![User-interface example](go-chromecast-ui.png "User-interface example")
151-
152-
A basic terminal user-interface is provided, that supports the following controls:
153-
* Quit: "q"
154-
* Play/Pause: SPACE
155-
* Volume: - / +
156-
* Mute/Unmute: "m"
157-
* Seek (15s): <- / ->
158-
* Previous/Next: PgUp / PgDn
159-
* Stop: "s"
160-
161-
It can be run in the following ways:
162-
163-
### Standalone
164-
165-
If you just want to remote-control a chromecast that is already playing something:
166-
167-
```
168-
$ go-chromecast ui
169-
```
170-
171-
### Playlist
172-
173-
Use the UI in combination with the `playlist` command (detailed above):
174-
175-
```
176-
$ go-chromecast --with-ui playlist /path/to/directory
177-
```
178-
179-
### Load
180-
181-
Use the UI in combination with the `load` command (detailed above):
182-
183-
```
184-
$ go-chromecast --with-ui load /path/to/file.flac
185-
```
186-
187-
## Installing
188-
189-
### Install binaries
190-
https://github.com/vishen/go-chromecast/releases
191-
192-
### Install the usual Go way:
193-
194-
```
195-
$ go get -u github.com/vishen/go-chromecast
196-
```
197-
198-
## Commands
199-
200-
```
2011
Control your Google Chromecast or Google Home Mini from the
2022
command line.
2033

2044
Usage:
5+
go-chromecast [flags]
2056
go-chromecast [command]
2067

2078
Available Commands:
@@ -229,10 +30,10 @@ Flags:
22930
-n, --device-name string chromecast device name
23031
--disable-cache disable the cache
23132
-h, --help help for go-chromecast
232-
-i, --iface string Network interface to use
33+
-i, --iface string Network interface to use when looking for a local address to use for the http server
23334
-p, --port string Port of the chromecast device if 'addr' is specified (default "8009")
23435
-u, --uuid string chromecast device uuid
36+
-v, --version display command version
23537
--with-ui run with a UI
23638

23739
Use "go-chromecast [command] --help" for more information about a command.
238-
```

cmd/root.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,52 @@ package cmd
1717
import (
1818
"fmt"
1919
"os"
20+
"time"
2021

2122
"github.com/spf13/cobra"
2223
)
2324

25+
var (
26+
Version = ""
27+
Commit = ""
28+
Date = ""
29+
)
30+
2431
// rootCmd represents the base command when called without any subcommands
2532
var rootCmd = &cobra.Command{
2633
Use: "go-chromecast",
2734
Short: "CLI for interacting with the Google Chromecast",
2835
Long: `Control your Google Chromecast or Google Home Mini from the
29-
command line.
30-
`}
36+
command line.`,
37+
RunE: func(cmd *cobra.Command, args []string) error {
38+
printVersion, _ := cmd.Flags().GetBool("version")
39+
if printVersion {
40+
fmt.Printf("go-chromecast %s (%s) %s\n", Version, Commit, Date)
41+
return nil
42+
}
43+
cmd.Help()
44+
return nil
45+
},
46+
}
3147

3248
// Execute adds all child commands to the root command and sets flags appropriately.
3349
// This is called by main.main(). It only needs to happen once to the rootCmd.
34-
func Execute() {
50+
func Execute(version, commit, date string) {
51+
Version = version
52+
Commit = commit
53+
if date != "" {
54+
Date = date
55+
} else {
56+
Date = time.Now().UTC().Format(time.RFC3339)
57+
}
3558
if err := rootCmd.Execute(); err != nil {
3659
fmt.Println(err)
3760
os.Exit(1)
3861
}
3962
}
4063

4164
func init() {
65+
rootCmd.PersistentFlags().BoolP("version", "v", false, "display command version")
4266
rootCmd.PersistentFlags().Bool("debug", false, "debug logging")
4367
rootCmd.PersistentFlags().Bool("disable-cache", false, "disable the cache")
4468
rootCmd.PersistentFlags().Bool("with-ui", false, "run with a UI")

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ package main
1616

1717
import "github.com/vishen/go-chromecast/cmd"
1818

19+
var (
20+
// These are build-time variables that get set by goreleaser.
21+
version = "dev"
22+
commit = "master"
23+
date = ""
24+
)
25+
1926
func main() {
20-
cmd.Execute()
27+
cmd.Execute(version, commit, date)
2128
}

0 commit comments

Comments
 (0)