LoginSignup
12
10

More than 3 years have passed since last update.

CATTを使ってラズパイからChromecastやNest Hubに動画やWebサイトをキャストしてみる

Posted at

背景

ChromecastやGoogle Nest Hub、Android TVなどのChromecastデバイスに映像をGravioで送ることができたらいいなぁと思ってたら、最近同僚にCast All The Things(CATT)というPythonで書かれたコマンドが公開されているのを教えてもらった。

Cast All The Things: https://github.com/skorokithakis/catt

使用環境

  • Raspberry Pi 4
  • Ubuntu 20.04.01 LTS
  • Python 3.8.2
  • CATT v0.11.3

インストール手順

PIPのインストール

CATTはPIPで公開されています。PIPのインストールはいろんなやり方があるので、以下を参考にしてください。
https://www.python.jp/install/ubuntu/pip.html

$ sudo apt install python3-pip

CATTのインストール

次にCATTをインストールします。sudoをつけないとユーザー環境としてインストールされるので注意。そっちがいい人はそうしてください。Gravioで実行するにはsudo付きでインストールしておいたほうが吉。

$ sudo pip3 install catt 

CATTでできること

まずはどんなことができるのかヘルプを見てみましょう。

$ catt -h
Usage: catt [OPTIONS] COMMAND [ARGS]...

Options:
  --delete-cache           Empty the Chromecast discovery cache.
  -d, --device NAME_OR_IP  Select Chromecast device.
  --version                Show the version and exit.
  -h, --help               Show this message and exit.

Commands:
  add           Add a video to the queue (YouTube only).
  cast          Send a video to a Chromecast for playing.
  cast_site     Cast any website to a Chromecast.
  clear         Clear the queue (YouTube only).
  del_alias     Delete the alias name of the selected device.
  del_default   Delete the default device.
  ffwd          Fastforward a video by TIME duration.
  info          Show complete information about the currently-playing video.
  pause         Pause a video.
  play          Resume a video after it has been paused.
  play_toggle   Toggle between playing and paused state.
  remove        Remove a video from the queue (YouTube only).
  restore       Return Chromecast to saved state.
  rewind        Rewind a video by TIME duration.
  save          Save the current state of the Chromecast for later use.
  scan          Scan the local network and show all Chromecasts and their IPs.
  seek          Seek the video to TIME position.
  set_alias     Set an alias name for the selected device.
  set_default   Set the selected device as default.
  skip          Skip to end of content.
  status        Show some information about the currently-playing video.
  stop          Stop playing.
  volume        Set the volume to LVL [0-100].
  volumedown    Turn down volume by a DELTA increment.
  volumeup      Turn up volume by a DELTA increment.
  write_config  Please use "set_default".

結構いろんな事ができますね。YouTubeやローカルのムービーファイル、サイトの表示も可能です。ボリュームの操作や再生位置の指定もできたり、キューの操作も可能なので、アイデア次第で色々できそうです。

Chromecastデバイスを検索してみる

では、ネットワーク内のChromecastデバイスを検索してみます。

$ catt scan
Scanning Chromecasts...
192.168.xx.xx - AFTT-51 - Google Inc. AirReceiver
192.168.xx.xx - Chromecast 4K - Google Inc. Chromecast Ultra
192.168.xx.xx - J:COM LINK XA401 - Google Inc. XA401
192.168.xx.xx - ベッドルーム - Google Inc. Google Home Mini
192.168.xx.xx - リビングルーム - Google Inc. Google Nest Hub

我が家には色々Chromecastデバイスがありますのでこれくらい出てきます。Google Home miniはモニターを持っていないので今回は対象外ですね。
J:COMのSTBも最近置き換えたのはAndroid TVなのでキャスト可能です。AFTT-51はKindle FireTV Stickですね。AirReceiverというアプリを入れてます。

YouTubeの動画をキャストしてみる

キャストは簡単です。 -dオプションでキャストするデバイスを指定できます。さきほどcatt scanで見つけたデバイス名を指定します。あとは castのあとにYouTubeのURLを書くだけ。

$ catt -d リビングルーム cast https://youtu.be/tfNJctN1TL0
Casting remote file https://youtu.be/tfNJctN1TL0...
Playing "[動画]ASTERIA Warp 製品紹介 2min|アステリア" on "リビングルーム"...

Webサイトを表示してみる

$ catt -d リビングルーム cast_site https://asteria.com
Casting https://asteria.com on "リビングルーム"...

最後に

以前も結構探してたんですが、いつのまにかこんなに便利なコマンドができてました。これでGravioのセンサーと連携して色々できるようになります。そのあたりはまた後日。

12
10
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10