Skip to content

Instantly share code, notes, and snippets.

@YtvwlD
Last active February 6, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YtvwlD/1da1fbee3eb250f178be957f9303c33e to your computer and use it in GitHub Desktop.
Save YtvwlD/1da1fbee3eb250f178be957f9303c33e to your computer and use it in GitHub Desktop.
Puts Maurudor.de to a Chromecast.
#!/usr/bin/env python3
import pychromecast
from pychromecast.controllers.media import MediaController
from sys import argv
from random import random
from time import sleep
print("Searching for devices...")
casts = pychromecast.get_chromecasts()
if len(argv) != 2:
print("Specify the Chromecast to use. Chromecasts found: {}".format([cc.device.friendly_name for cc in casts]))
exit()
print("Connecting to {}...".format(argv[1]))
cast = next(cc for cc in casts if cc.device.friendly_name == argv[1])
if not cast:
print("Didn't find the specified device. Chromecasts found: {}".format(list(casts.keys())))
mc = MediaController()
cast.register_handler(mc)
print("Connected. To stop, press ^C.")
try:
while True:
mc.play_media("https://maurudor.de/?{}".format(random()), "Image/jpg")
sleep(20)
except KeyboardInterrupt:
print("Exiting...")
cast.quit_app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment