Implementiert eine kleine Anzahl der Google Chromecast-Befehle. Abgesehen von den grundlegenden Befehlen können Sie damit auch Mediendateien von Ihrem Computer einzeln oder in einer Wiedergabeliste abspielen. Der Befehl playlist
durchsucht alle Dateien in einem Ordner und spielt sie nach Zahlen sortiert ab. Außerdem können Sie mit dem Befehl slideshow
eine Diashow mit Bildern abspielen.
Kann eine lokale Mediendatei oder eine im Internet gehostete Datei im folgenden Format auf Ihren Chromecast laden:
Supported Media formats:
- MP3
- AVI
- MKV
- MP4
- WebM
- FLAC
- WAV
Wenn eine unbekannte Videodatei gefunden wird, wird sie mit ffmpeg
in MP4 transkodiert und an den Chromecast gestreamt.
Wir können lokale Mediendateien abspielen, indem wir einen http-Server erstellen, der die Mediendatei auf das Cast-Gerät streamt.
Zur Ermittlung der Chromecast- und Google Home-Geräte wird ein DNS-Multicast verwendet.
Der Cast-DNS-Eintrag wird ebenfalls zwischengespeichert. Das heißt, wenn Sie den Gerätenamen -n <name>
oder die Geräte-UUId -u <uuid>
übergeben, werden die Ergebnisse zwischengespeichert und es wird sofort eine Verbindung zum Chromecast-Gerät hergestellt .
https://github.com/vishen/go-chromecast/releases
tar -xzf go-chromecast.tar.gz
und installieren Sie sie mit 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
Es wird eine grundlegende Terminal-Benutzeroberfläche bereitgestellt, die die folgenden Steuerelemente unterstützt:
Es kann auf folgende Arten ausgeführt werden:
Wenn Sie nur einen Chromecast fernsteuern möchten, der bereits etwas abspielt:
$ go-chromecast ui
Verwenden Sie die Benutzeroberfläche in Kombination mit dem playlist
-Befehl (siehe oben):
$ go-chromecast --with-ui playlist /path/to/directory
Verwenden Sie die Benutzeroberfläche in Kombination mit dem load
(siehe oben):
$ go-chromecast --with-ui load /path/to/file.flac
Es wird ein HTTP-API-Server bereitgestellt, der über die folgende API verfügt:
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")
Es gibt Unterstützung für die Wiedergabe von Medienelementen als Playlist.
Wenn Sie von einer Wiedergabeliste abspielen, können Sie das Flag --select
verwenden und so das Medium auswählen, von dem aus die Wiedergabe gestartet werden soll. Dies ist nützlich, wenn Sie einige Medien bereits abgespielt haben und mit einem Medium beginnen möchten, das Sie noch nicht abgespielt haben.
Für die abgespielten Medien wird ein Cache gespeichert. Wenn Sie also Medien aus einer Wiedergabeliste abspielen, wird geprüft, welche Mediendateien Sie kürzlich abgespielt haben, und die nächste Datei aus der Wiedergabeliste wird abgespielt. --continue=false
kann übergeben werden und dadurch wird die Wiedergabeliste von vorne gestartet.
Wenn Sie sehen möchten, was ein Gerät sendet, können Sie die von Ihrem Gerät gesendeten Protobuf-Nachrichten watch
:
$ go-chromecast watch
Experimentelle Text-to-Speech-Unterstützung wurde hinzugefügt. Hierbei wird Text-to-Speech von Google Cloud verwendet, um Text in eine MP3-Audiodatei umzuwandeln, die dann auf das Gerät gestreamt wird.
Die Text-to-Speech-API muss aktiviert sein https://console.cloud.google.com/flows/enableapi?apiid=texttospeech.googleapis.com und ein Google-Dienstkonto ist erforderlich https://console.cloud.google. com/apis/credentials/serviceaccountkey
$ go-chromecast tts <message_to_say> --google-service-account=/path/to/service/account.json
Für nicht-amerikanische Sprachen
$ 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
Eine Liste der verfügbaren Stimmen (Stimmenname) finden Sie hier: https://cloud.google.com/text-to-speech/
Verwenden Sie SSML
$ go-chromecast tts '<speak>Hello<break time="500ms"/>world.</speak>'
--google-service-account=/path/to/service/account.json
--ssml