media.chromecast

media.chromecast

class platypush.plugins.media.chromecast.MediaChromecastPlugin(chromecast=None, *args, **kwargs)[source]

Plugin to interact with Chromecast devices

Supported formats:

  • HTTP media URLs

  • YouTube URLs

  • Plex (through media.plex plugin, experimental)

Requires:

  • pychromecast (pip install pychromecast)

__init__(chromecast=None, *args, **kwargs)[source]
Parameters:

chromecast (str) – Default Chromecast to cast to if no name is specified

disconnect(chromecast=None, timeout=None, blocking=True)[source]

Disconnect a Chromecast and wait for it to terminate

Parameters:
  • chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

  • timeout (float) – Number of seconds to wait for disconnection (default: None: block until termination)

  • blocking (bool) – If set (default), then the code will wait until disconnection, otherwise it will return immediately.

download(url, filename=None, directory=None)

Download a media URL

Parameters:
  • url – Media URL

  • filename – Media filename (default: URL filename)

  • directory – Destination directory (default: download_dir)

Returns:

The absolute path to the downloaded file

get_chromecasts(tries=2, retry_wait=10, timeout=60, blocking=True, callback=None)[source]

Get the list of Chromecast devices

Parameters:
  • tries (int) – Number of retries (default: 2)

  • retry_wait (int) – Number of seconds between retries (default: 10 seconds)

  • timeout (int) – Timeout before failing the call (default: 60 seconds)

  • blocking (bool) – If true, then the function will block until all the Chromecast devices have been scanned. If false, then the provided callback function will be invoked when a new device is discovered

  • callback (func) – If blocking is false, then you can provide a callback function that will be invoked when a new device is discovered

get_media_file_duration(filename)

Get the duration of a media file in seconds. Requires ffmpeg

join(chromecast=None, timeout=None)[source]

Blocks the thread until the Chromecast connection is terminated.

Parameters:
  • chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

  • timeout (float) – Number of seconds to wait for disconnection (default: None: block until termination)

mute(chromecast=None)[source]

Toggle the mute status on the Chromecast

Parameters:

chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

next()

Play the next item in the queue

play(resource, content_type=None, chromecast=None, title=None, image_url=None, autoplay=True, current_time=0, stream_type='BUFFERED', subtitles=None, subtitles_lang='en-US', subtitles_mime='text/vtt', subtitle_id=1)[source]

Cast media to a visible Chromecast

Parameters:
  • resource (str) – Media to cast

  • content_type (str) – Content type as a MIME type string

  • chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

  • title (str) – Optional title

  • image_url (str) – URL of the image to use for the thumbnail

  • autoplay (bool) – Set it to false if you don’t want the content to start playing immediately (default: true)

  • current_time (int) – Time to start the playback in seconds (default: 0)

  • stream_type (str) – Type of stream to cast. Can be BUFFERED (default), LIVE or UNKNOWN

  • subtitles (str) – URL of the subtitles to be shown

  • subtitles_lang (str) – Subtitles language (default: en-US)

  • subtitles_mime (str) – Subtitles MIME type (default: text/vtt)

  • subtitle_id (int) – ID of the subtitles to be loaded (default: 1)

quit(chromecast=None)[source]

Exits the current app on the Chromecast

Parameters:

chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

reboot(chromecast=None)[source]

Reboots the Chromecast

Parameters:

chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

search(query, types=None, queue_results=False, autoplay=False, search_timeout=60)

Perform a video search.

Parameters:
  • query (str) – Query string, video name or partial name

  • types (list) – Video types to search (default: ["youtube", "file", "torrent"])

  • queue_results (bool) – Append the results to the current playing queue (default: False)

  • autoplay (bool) – Play the first result of the search (default: False)

  • search_timeout (float) – Search timeout (default: 60 seconds)

set_volume(volume, chromecast=None)[source]

Set the Chromecast volume

Parameters:
  • volume (float) – Volume to be set, between 0 and 100

  • chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

start_streaming(media, subtitles=None, download=False)

Starts streaming local media over the specified HTTP port. The stream will be available to HTTP clients on http://{this-ip}:{http_backend_port}/media/<media_id>

Parameters:
  • media (str) – Media to stream

  • subtitles (str) – Path or URL to the subtitles track to be used

  • download (bool) – Set to True if you prefer to download the file from the streaming link instead of streaming it

Returns:

dict containing the streaming URL.Example:

{
    "id": "0123456abcdef.mp4",
    "source": "file:///mnt/media/movies/movie.mp4",
    "mime_type": "video/mp4",
    "url": "http://192.168.1.2:8008/media/0123456abcdef.mp4"
}
voldown(chromecast=None, step=10)[source]

Turn down the Chromecast volume by 10% or step.

Parameters:
  • chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

  • step (float) – Volume decrement between 0 and 100 (default: 100%)

volup(chromecast=None, step=10)[source]

Turn up the Chromecast volume by 10% or step.

Parameters:
  • chromecast (str) – Chromecast to cast to. If none is specified, then the default configured Chromecast will be used.

  • step (float) – Volume increment between 0 and 100 (default: 100%)