Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vishen/go-chromecast
cli for Google Chromecast, Home devices and Cast Groups
https://github.com/vishen/go-chromecast
chromecast golang google-chromecast google-home
Last synced: 17 days ago
JSON representation
cli for Google Chromecast, Home devices and Cast Groups
- Host: GitHub
- URL: https://github.com/vishen/go-chromecast
- Owner: vishen
- License: apache-2.0
- Created: 2017-10-29T22:52:55.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-11T21:02:51.000Z (4 months ago)
- Last Synced: 2024-07-31T20:43:00.629Z (3 months ago)
- Topics: chromecast, golang, google-chromecast, google-home
- Language: Go
- Homepage:
- Size: 6.38 MB
- Stars: 817
- Watchers: 23
- Forks: 80
- Open Issues: 53
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chromecast
Implements a small 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. It also lets you play a slideshow of images with the `slideshow` command.
## Playable Media Content
Can load a local media file or a file hosted on the internet on your chromecast with the following format:
```
Supported Media formats:
- MP3
- AVI
- MKV
- MP4
- WebM
- FLAC
- WAV
```If an unknown video file is found, it will use `ffmpeg` to transcode it to MP4 and stream it to the chromecast.
## Play Local Media Files
We are able to play local media files by creating a http server that will stream the media file to the cast device.
## Cast DNS Lookup
A DNS multicast is used to determine the Chromecast and Google Home devices.
The cast DNS entry is also cached, this means that if you pass through the device name, `-n `, or the
device uuid, `-u `, the results will be cached and it will connect to the chromecast device instantly.## Installing
### Install release binaries
https://github.com/vishen/go-chromecast/releases
- If using Linux: Download the latest release, unzip using `tar -xzf go-chromecast.tar.gz`, and install using `sudo install ./go-chromecast /usr/bin/`
### Install the usual Go way:
#### Go 1.18 and above
```
$ go install github.com/vishen/go-chromecast@latest
```#### Go 1.17 and below
```
$ go get -u github.com/vishen/go-chromecast
```## Commands
```
Control your Google Chromecast or Google Home Mini from the
command line.Usage:
go-chromecast [flags]
go-chromecast [command]Available Commands:
help Help about any command
httpserver Start the HTTP server
load Load and play media on the chromecast
load-app Load and play content on a chromecast app
ls List devices
mute Mute the chromecast
next Play the next available media
pause Pause the currently playing media on the chromecast
playlist Load and play media on the chromecast
previous Play the previous available media
restart Restart the currently playing media
rewind Rewind by seconds the currently playing media
seek Seek by seconds into the currently playing media
seek-to Seek to the in the currently playing media
slideshow Play a slideshow of photos
status Current chromecast status
stop Stop casting
transcode Transcode and play media on the chromecast
tts text-to-speech
ui Run the UI
unmute Unmute the chromecast
unpause Unpause the currently playing media on the chromecast
volume Get or set volume
watch Watch all events sent from a chromecast deviceFlags:
-a, --addr string Address of the chromecast device
-v, --debug debug logging
-d, --device string chromecast device, ie: 'Chromecast' or 'Google Home Mini'
-n, --device-name string chromecast device name
--disable-cache disable the cache
--dns-timeout int Multicast DNS timeout in seconds when searching for chromecast DNS entries (default 3)
--first Use first cast device found
-h, --help help for go-chromecast
-i, --iface string Network interface to use when looking for a local address to use for the http server or for use with multicast dns discovery
-p, --port string Port of the chromecast device if 'addr' is specified (default "8009")
-u, --uuid string chromecast device uuid
--verbose verbose logging
--version display command version
--with-ui run with a UIUse "go-chromecast [command] --help" for more information about a command.
```## Usage
```
# View available cast devices.
$ go-chromecast ls
Found 2 cast devices
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="" uuid="b87d86bed423a6feb8b91a7d2778b55c"# Status of a cast device.
$ go-chromecast status
Found 2 cast dns entries, select one:
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="" uuid="b87d86bed423a6feb8b91a7d2778b55c"
Enter selection: 1
Idle (Backdrop), volume=1.00 muted=false# Specify a cast device name.
$ go-chromecast status -n "Living Room Speaker"
Idle, volume=0.17 muted=false# Specify a cast device by ip address.
$ go-chromecast status -a 192.168.0.52
Idle, volume=0.17 muted=false# Specify a cast device uuid.
$ go-chromecast status -u b87d86bed423a6feb8b91a7d2778b55c
Idle (Default Media Receiver), volume=0.17 muted=false# Play a file hosted on the internet
$ go-chromecast load https://example.com/path/to/media.mp4# Load a local media file (can play both audio and video).
$ go-chromecast load ~/Downloads/SampleAudio_0.4mb.mp3
Found 2 cast dns entries, select one:
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="" uuid="b87d86bed423a6feb8b91a7d2778b55c"
Enter selection: 2# Status of cast device running an audio file.
$ go-chromecast status
Found 2 cast dns entries, select one:
1) device="Chromecast" device_name="MarieGotGame?" address="192.168.0.115:8009" status="" uuid="b380c5847b3182e4fb2eb0d0e270bf16"
2) device="Google Home Mini" device_name="Living Room Speaker" address="192.168.0.52:8009" status="Default Media Receiver" uuid="b87d86bed423a6feb8b91a7d2778b55c"
Enter selection: 2
Default Media Receiver (PLAYING), unknown, time remaining=8s/28s, volume=1.00, muted=false# Play a playlist of media files.
$ go-chromecast playlist ~/playlist_test/ -n "Living Room Speaker"
Attemping to play the following media:
- /home/jonathan/playlist_test/SampleAudio_0.4mb.mp3
- /home/jonathan/playlist_test/sample_1.mp3# Select where to start a playlist from.
$ go-chromecast playlist ~/playlist_test/ -n "Living Room Speaker" --select
Will play the following items, select where to start from:
1) /home/jonathan/playlist_test/SampleAudio_0.4mb.mp3: last played "2018-11-25 11:17:25 +0000 GMT"
2) /home/jonathan/playlist_test/sample_1.mp3: last played "2018-11-25 11:17:28 +0000 GMT"
Enter selection: 2
Attemping to play the following media:
- /home/jonathan/playlist_test/sample_1.mp3# Start a playlist from the start, ignoring if you have previously played that playlist.
$ go-chromecast playlist ~/playlist_test/ -n "Living Room Speaker" --continue=false# Start a playlist and launch the terminal ui
$ go-chromecast playlist ~/playlist_test/ -n "Living Room Speaker" --with-ui# Start a slideshow of images
$ go-chromecast slideshow slideshow_images/*.png --repeat=false# Pause the playing media.
$ go-chromecast pause# Continue playing the currently playing media.
$ go-chromecast play# Play the next item in a playlist.
$ go-chromecast next# Play the previous item in a playlist.
$ go-chromecast previous# Rewind the currently playing media by x seconds.
$ go-chromecast rewind 30# Go forward in the currently playing media by x seconds.
$ go-chromecast seek 30# Get the current volume level
$ go-chromecast volume# Set the volume level
$ go-chromecast volume 0.55# View what messages a cast device is sending out.
$ go-chromecast watch# Use a terminal UI to interact with the cast device
$ go-chromecast ui
```## User Interface
![User-interface example](go-chromecast-ui.png "User-interface example")
A basic terminal user-interface is provided, that supports the following controls:
- Quit: "q"
- Play/Pause: SPACE
- Volume: - / +
- Mute/Unmute: "m"
- Seek (15s): <- / ->
- Previous/Next: PgUp / PgDn
- Stop: "s"It can be run in the following ways:
### Standalone
If you just want to remote-control a chromecast that is already playing something:
```
$ go-chromecast ui
```### Playlist
Use the UI in combination with the `playlist` command (detailed above):
```
$ go-chromecast --with-ui playlist /path/to/directory
```### Load
Use the UI in combination with the `load` command (detailed above):
```
$ go-chromecast --with-ui load /path/to/file.flac
```## HTTP API Server
There is a HTTP API server provided that has the following api:
```
GET /devices?interface=&wait=
POST /connect?uuid=&addr=&port=&interface=&wait=
POST /disconnect?uuid=&stop=
POST /disconnect-all?stop=
POST /status?uuid=
POST /pause?uuid=
POST /unpause?uuid=
POST /mute?uuid=
POST /unmute?uuid=
POST /stop?uuid=
GET /volume?uuid=
POST /volume?uuid=&volume=
POST /rewind?uuid=&seconds=
POST /seek?uuid=&seconds=
POST /seek-to?uuid=&seconds=
POST /load?uuid=&path=&content_type=
``````
$ go-chromecast httpserverStart the HTTP server which provides an HTTP
api to control chromecast devices on a network.Usage:
go-chromecast httpserver [flags]Flags:
-h, --help help for httpserver
--http-addr string addr for the http server to listen on (default "0.0.0.0")
--http-port string port for the http server to listen on (default "8011")
```## Playlist
There is support for playing media items as a playlist.
If playing from a playlist, you are able to pass though the `--select` flag, and this will allow you to select
the media to start playing from. This is useful if you have already played some of the media and want to start
from one you haven't played yet.A cache is kept of played media, so if you are playing media from a playlist, it will check to see what
media files you have recently played and play the next one from the playlist. `--continue=false` can be passed
through and this will start the playlist from the start.## Discover sent and received events from a Device
If you would like to see what a device is sending, you are able to `watch` the protobuf messages being sent from your device:
```
$ go-chromecast watch
```### Text To Speech
Experimental text-to-speech support has been added. This uses [Google
Cloud's Text-to-Speech](https://cloud.google.com/text-to-speech/) to
turn text into an mp3 audio file, this is then streamed to the device.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
```
$ go-chromecast tts --google-service-account=/path/to/service/account.json
```For non en-US languages
```
$ go-chromecast tts --google-service-account=/path/to/service/account.json \
--voice-name en-US-Wavenet-G --speaking-rate 1.05 --pitch 0.9
```List of available voices (voice-name) can be found here: https://cloud.google.com/text-to-speech/
Use [SSML](https://cloud.google.com/text-to-speech/docs/ssml)
```
$ go-chromecast tts 'Helloworld.' \
--google-service-account=/path/to/service/account.json \
--ssml
```