• Stars
    star
    468
  • Rank 93,767 (Top 2 %)
  • Language
    Python
  • License
    Other
  • Created over 4 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“บ Control Chromecasts from Linux and D-Bus

๐Ÿ“บ Control Chromecasts from Linux

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

While this service runs, it collects data about the media and apps playing on your casting devices and displays it on your computer.

Integrations

cast_control 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 and gobject-introspection, or install cast_control 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 cast_control

You'll get a cast_control 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 cast_control executable added to your $PATH.

AUR

If you're on Arch, you can install cast_control directly from the AUR. Thanks, @yochananmarqos!

$ yay -S cast_control

Upgrades

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

$ python3 -m pip --upgrade cast_control

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 cast_control to your pip executables path:

$ which cast_control 
~/.local/bin/cast_control

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

$ cast_control --help

Or, using the short name launcher castctl:

$ castctl --help

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

$ python3 -m cast_control --help

Help

Shell completion

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

eval "$(_CAST_CONTROL_COMPLETE=bash_source cast_control)"

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

Help text

$ cast_control --help
Usage: cast_control [OPTIONS] COMMAND [ARGS]...

  Control casting devices via Linux media controls and desktops.

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

  See https://github.com/alexdelorenzo/cast_control for more information.

Options:
  -L, --license  Show license and copyright information.
  -V, --version  Show version information.
  --help         Show this message and exit.

Commands:
  connect  Connect to the device and run the service in the foreground.
  service  Connect, disconnect or reconnect the background service to or...
connect command
$ cast_control connect --help
Usage: cast_control connect [OPTIONS]

  Connect to the device and run the service in the foreground.

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.
service command
$ cast_control service --help
Usage: cast_control service [OPTIONS] COMMAND [ARGS]...

  Connect, disconnect or reconnect the background service to or from your
  device.

Options:
  --help  Show this message and exit.

Commands:
  connect     Connect the background service to the device.
  disconnect  Disconnect the background service from the device.
  reconnect   Reconnect the background service to the device.
  log         Show the service log.
service connect command
$ cast_control service connect --help
Usage: cast_control service connect [OPTIONS]

  Connect the background service to the device.

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":

$ cast_control connect --name "My Device"

Connect to a device named "My Device" and run cast_control in the background:

$ cast_control service connect --name "My Device"

After launching cast_control, 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 cast_control 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
$ cast_control connect --wait $SECONDS
# or
$ cast_control service connect --wait $SECONDS

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

Reconnect or disconnect the background service

If the background service is running, you can force it to reconnect and restart, or disconnect it entirely.

$ cast_control service reconnect
# or
$ cast_control service disconnect

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"

Logs

You can set the log level using the -l/--log-level flag with the connect or service connect commands:

$ cast_control connect --log-level debug

Here's a list of log levels supported by cast_control.

You can view the background service's log file with the service log command:

$ cast_control service log

Support

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

Buy Me A Coffee

License

See LICENSE. If you'd like to use this project with a different license, please get in touch.

More Repositories

1

onhold

๐Ÿ”Š Play sounds while and after shell jobs complete
Python
156
star
2

screenshot

๐Ÿ“ธ Automate capturing screenshots of apps and windows on macOS
Python
153
star
3

aiopath

๐Ÿ“ Asynchronous pathlib for Python
Python
134
star
4

mpris_server

โ–ถ๏ธ Integrate MPRIS Media Player support into your app
Python
25
star
5

brightness

โ˜€๏ธ Dim your Mac's display from the command line via CoreDisplay
Python
25
star
6

limiter

โฒ๏ธ Easy rate limiting for Python using a token bucket algorithm, with async and thread-safe decorators and context managers
Python
20
star
7

parse_google_sms

๐Ÿ“ฑData forensics and recovery utility for Google Voice chats saved via Google Takeout
Python
18
star
8

save_skype

๐Ÿ’ฌ Data forensics and recovery utility for Skype chats and history
Python
13
star
9

cast_convert

๐Ÿ“ฝ๏ธ Convert videos to Chromecast compatible formats
Python
7
star
10

ding

Python
7
star
11

play_sounds

๐Ÿ”Š Play music and sounds in your Python scripts, synchronously and asynchronously.
Python
6
star
12

intel-gvtg

Scripts for managing Intel virtual gfx and KVM
Shell
6
star
13

strs

๐Ÿงต Easy string tools for the shell
Python
4
star
14

app_paths

๐Ÿ“‚ Like appdirs, but with pathlib, path creation and async support.
Python
4
star
15

grub2systemd

๐Ÿ’พ Convert grub.cfg to systemd-boot EFI loader entries
Python
4
star
16

unpackable

๐Ÿ“ฆ Destructure Python objects
Python
3
star
17

dreamhost-dyndns

Updates Dreamhost DNS Records via DynamicDNS (DynDNS) API
Python
3
star
18

delete_scrobbles

โŒ Automatically delete scrobbles on Last.fm
JavaScript
3
star
19

alexdelorenzo

2
star
20

disjoint_set

Union find / disjoint union set
Python
2
star
21

pinterest_tools

TamperMonkey tools for Pinterest
JavaScript
2
star
22

find-ubuntu-mirrors

๐Ÿ” Find Apt repository mirrors for Ubuntu
Shell
2
star
23

npm-user

๐Ÿ  Install npm packages as a non-root user
Shell
2
star
24

ubuntu-kernel

Download latest mainline kernel from Ubuntu's kernel PPA
Shell
2
star
25

rust-book

Code examples, tests, and responses from the Rust Book https://doc.rust-lang.org/book/
Assembly
2
star
26

transmission_user

Change the user of the transmission-daemon in Debian/Ubuntu
Shell
2
star
27

buf_stream

Rust
1
star
28

nth_py

Python
1
star
29

nth_rs

Return or exclude the nth item via stdin
Rust
1
star
30

minesweeper

minesweeper game + shoddily put together gui + a board solver
Python
1
star
31

cacheit

Caching decorator for Python callables
Python
1
star
32

buffers-rs

โŒ› A stream buffer backed by a temporary file.
Rust
1
star
33

userscripts

JavaScript
1
star
34

html_wrapper

HTML parser with lxml backend. Implements subset of BeautifulSoup API
Python
1
star
35

cheapbook

Send email/SMS notifications about Apple's refurb stock
Python
1
star
36

byte_lines

Iterate over lines of bytes from anything that implements std::io::Read
Rust
1
star
37

buffer

โŒ› A stream buffer backed by tempfile.SpooledTemporaryFile
Python
1
star
38

covid_schools

Script that puts together a COVID spreadsheet
Python
1
star
39

wordpress_menu

Drop down menu for Wordpress
JavaScript
1
star