实现少量 google chromecast 命令。除了基本命令外,它还允许您单独或在播放列表中播放计算机中的媒体文件; playlist
命令将查看文件夹中的所有文件并按数字排序播放它们。它还允许您使用slideshow
命令播放图像的幻灯片。
可以在 chromecast 上加载本地媒体文件或托管在互联网上的文件,格式如下:
Supported Media formats:
- MP3
- AVI
- MKV
- MP4
- WebM
- FLAC
- WAV
如果发现未知视频文件,它将使用ffmpeg
将其转码为 MP4 并将其流式传输到 chromecast。
我们可以通过创建一个 http 服务器来播放本地媒体文件,该服务器会将媒体文件流式传输到投射设备。
DNS 多播用于确定 Chromecast 和 Google Home 设备。
Cast DNS 条目也会被缓存,这意味着如果您传递设备名称-n <name>
或设备 uuid -u <uuid>
,结果将被缓存并立即连接到 chromecast 设备。
https://github.com/vishen/go-chromecast/releases
tar -xzf go-chromecast.tar.gz
解压缩,然后使用sudo install ./go-chromecast /usr/bin/
安装 $ go install github.com/vishen/go-chromecast@latest
$ go get -u github.com/vishen/go-chromecast
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 <timestamp_in_seconds> 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 device
Flags:
-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 UI
Use "go-chromecast [command] --help" for more information about a command.
# 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
提供了基本的终端用户界面,支持以下控件:
它可以通过以下方式运行:
如果您只想远程控制已经在播放某些内容的 chromecast:
$ go-chromecast ui
将 UI 与playlist
命令结合使用(详见上文):
$ go-chromecast --with-ui playlist /path/to/directory
将 UI 与load
命令结合使用(如上所述):
$ go-chromecast --with-ui load /path/to/file.flac
提供了一个 HTTP API 服务器,它具有以下 api:
GET /devices?interface=<network_interface>&wait=<seconds>
POST /connect?uuid=<device_uuid>&addr=<device_addr>&port=<device_port>&interface=<network_interface>&wait=<seconds>
POST /disconnect?uuid=<device_uuid>&stop=<bool>
POST /disconnect-all?stop=<bool>
POST /status?uuid=<device_uuid>
POST /pause?uuid=<device_uuid>
POST /unpause?uuid=<device_uuid>
POST /mute?uuid=<device_uuid>
POST /unmute?uuid=<device_uuid>
POST /stop?uuid=<device_uuid>
GET /volume?uuid=<device_uuid>
POST /volume?uuid=<device_uuid>&volume=<float>
POST /rewind?uuid=<device_uuid>&seconds=<int>
POST /seek?uuid=<device_uuid>&seconds=<int>
POST /seek-to?uuid=<device_uuid>&seconds=<float>
POST /load?uuid=<device_uuid>&path=<filepath_or_url>&content_type=<string>
$ go-chromecast httpserver
Start 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")
支持将媒体项目作为播放列表播放。
如果从播放列表播放,您可以通过--select
标志,这将允许您选择开始播放的媒体。如果您已经播放过某些媒体并想从尚未播放过的媒体开始播放,则此功能非常有用。
缓存保存已播放的媒体,因此如果您正在播放播放列表中的媒体,它将检查您最近播放过的媒体文件并播放播放列表中的下一个媒体文件。 --continue=false
可以通过,这将从头开始播放列表。
如果您想查看设备正在发送的内容,您可以watch
从您的设备发送的 protobuf 消息:
$ go-chromecast watch
添加了实验性文本转语音支持。它使用 Google Cloud 的文本转语音功能将文本转换为 mp3 音频文件,然后将其传输到设备。
需要启用文本转语音 api https://console.cloud.google.com/flows/enableapi?apiid=texttospeech.googleapis.com 并且需要 google 服务帐户 https://console.cloud.google。 com/apis/credentials/serviceaccountkey
$ go-chromecast tts <message_to_say> --google-service-account=/path/to/service/account.json
对于非美国语言
$ go-chromecast tts <message_to_say> --google-service-account=/path/to/service/account.json
--voice-name en-US-Wavenet-G --speaking-rate 1.05 --pitch 0.9
可用语音列表(语音名称)可以在这里找到:https://cloud.google.com/text-to-speech/
使用SSML
$ go-chromecast tts '<speak>Hello<break time="500ms"/>world.</speak>'
--google-service-account=/path/to/service/account.json
--ssml