Skip to main content

📺 Control Chromecasts from Linux and D-Bus

Project description

📺 Control Chromecasts from Linux

chromecast_mpris is a daemon utility that allows you to control media playback on casting devices from the Linux desktop.

While this service runs, it gathers and publishes data about the media and apps playing on your casting devices.

Note: This package is now called Cast Control, and is available on PyPI as cast_control.

Please upgrade to cast_control for new features and bug fixes.

Integrations

chromecast_mpris controls Chromecasts and casting devices via D-Bus and MPRIS media player controls.

MPRIS is the standard media player interface on Linux desktops.

MPRIS integration is enabled by default in Plasma Desktop, and, along with GNOME's volume control widget, there are widgets for GNOME, too. playerctl provides a CLI for controlling media players through MPRIS.

Check out ▶️mpris_server if you want to integrate MPRIS support into your media player.

Screenshots

Controlling a Chromecast via Plasma Desktop's Media Player widget:

Features

  • Control music and video playback
  • Control app playback
  • View playback information in real-time
  • Display thumbnail and title
  • Display playback position and media length
  • Seek forward and backward
  • Play, pause, and stop playback
  • Volume up and down
  • Play next and previous
  • Quit casted app
  • Open media from D-Bus
  • Play YouTube videos
  • Playlist integration

Installation

Requirements

Installing PyGObject

On Debian-derived distributions like Ubuntu, install python3-gi with apt.

On Arch, you'll want to install python-gobject, or install chromecast_mpris directly from the AUR.

On macOS, install pygobject3 via brew.

Use pip to install PyGObject>=3.34.0 if there are no installation candidates available in your vendor's package repositories.

PyPI

$ python3 -m pip install chromecast_mpris

You'll get a chromecast_mpris executable added to your $PATH.

GitHub

Check out the releases page on GitHub for stable releases.

If you'd like to use the development branch, clone the repository.

Once you have a source copy, run python3 -m pip install -r requirements.txt, followed by python3 setup.py install.

You'll get a chromecast_mpris executable added to your $PATH.

AUR

If you're on Arch, you can install chromecast_mpris directly from the AUR.

$ yay -S chromecast_mpris

Upgrades

Stable releases are uploaded to PyPI. You can upgrade your chromecast_mpris installation like so:

$ python3 -m pip --upgrade chromecast_mpris

See the releases page on GitHub.

Usage

You'll need to make sure that your computer can make network connections with your casting devices. It also helps to know the names of the devices in advance.

Launch

Installing the package via PyPI, GitHub or the AUR will add chromecast_mpris to your pip executables path:

$ which chromecast_mpris 
~/.local/bin/chromecast_mpris

If you have your pip executables path added to your shell's $PATH, you can launch chromecast_mpris like so:

$ chromecast_mpris

You can also launch chromecast_mpris via its Python module. This can be useful if your $PATH doesn't point to your pip executables.

$ python3 -m chromecast_mpris

Help

Shell completion

To enable Bash completion for chromecast_mpris, add the following to your ~/.bashrc:

eval "$(_CHROMECAST_MPRIS_COMPLETE=bash_source chromecast_mpris)"

For the zsh and fish shells, check out the documentation here.

Help command

$ chromecast_mpris --help
Usage: chromecast_mpris [OPTIONS]

  Control casting devices via Linux media controls and desktops.

  This daemon connects your casting device directly to the D-Bus media
  player interface.

Options:
  -n, --name TEXT         Connect to a device via its name, otherwise control
                          the first device found.

  -h, --host TEXT         Connect to a device via its hostname or IP address,
                          otherwise control the first device found.

  -u, --uuid TEXT         Connect to a device via its UUID, otherwise control
                          the first device found

  -w, --wait FLOAT        Seconds to wait between trying to make initial
                          successful connections to a device.

  -r, --retry-wait FLOAT  Seconds to wait between reconnection attempts if a
                          successful connection is interrupted.  [default:
                          5.0]

  -i, --icon              Use a lighter icon instead of the dark icon. The
                          lighter icon goes well with dark themes.  [default:
                          False]

  -l, --log-level TEXT    Set the debugging log level.  [default: WARN]
  --help                  Show this message and exit.

Connect to a device

Connect to a device named "My Device" and run chromecast_mpris in the background.

$ chromecast_mpris --name "My Device" &
[1] 1234

After launching chromecast_mpris, you can use any MPRIS client to interact with it. MPRIS support is built in directly to Plasma Desktop and GNOME 3, and you can use playerctl on the command-line.

Retry until a Chromecast is found

You can use the -w/--wait flag to specify a waiting period in seconds before chromecast_mpris will try to find a casting device again if one is not found initially.

For example, if you want to wait 60 seconds between scans for devices, you can run the following:

$ export SECONDS=60
$ chromecast_mpris --wait $SECONDS

This is useful if you'd like to start chromecast_mpris at login, and there is a chance that your device isn't on, or you're on a different network.

Open a URI on a Chromecast

Get the D-Bus name for your device using playerctl.

$ playerctl --list-all
My_Device

Use the D-Bus name to issue commands to it.

$ export URL="http://ccmixter.org/content/gmz/gmz_-_Parametaphoriquement.mp3"
$ playerctl --player My_Device open "$URL"

This will play a song on your device.

Open a YouTube video

You can cast YouTube videos the same way you can cast a generic URI.

$ export VIDEO="https://www.youtube.com/watch?v=I4nkgJdVZFA"
$ playerctl --player My_Device open "$VIDEO"

Support

Want to support this project and other open-source projects like it?

Buy Me A Coffee

License

See LICENSE. Message me if you'd like to use this project with a different license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chromecast_mpris-0.8.12.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

chromecast_mpris-0.8.12-py2.py3-none-any.whl (63.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file chromecast_mpris-0.8.12.tar.gz.

File metadata

  • Download URL: chromecast_mpris-0.8.12.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.10.0b2+

File hashes

Hashes for chromecast_mpris-0.8.12.tar.gz
Algorithm Hash digest
SHA256 f965c6bd27d9df21e58ac2017229bf9aa54d2aa95fdf9a6ef0258816c508f513
MD5 260304ccfb641ad01bff62bd3e3aa5de
BLAKE2b-256 42b2506c08e20227b3c768f98721d95a03ccf2e29318f456bc144736d7962571

See more details on using hashes here.

File details

Details for the file chromecast_mpris-0.8.12-py2.py3-none-any.whl.

File metadata

  • Download URL: chromecast_mpris-0.8.12-py2.py3-none-any.whl
  • Upload date:
  • Size: 63.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.10.0b2+

File hashes

Hashes for chromecast_mpris-0.8.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3fcc04b9d9be84165afb32d7311e38a1ab37f05d5e17e7c5d9b26733148ce7d3
MD5 1ed997d655a347211c5d96fe9c29c510
BLAKE2b-256 b9d350608349bb3a0e20f6ef6e6aa90c9e0515653235e753ea3302b00f266590

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page