實作少量 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。 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