Last active
September 11, 2016 04:03
-
-
Save deferraz/6296de04406d3c50eb5e411168c005d6 to your computer and use it in GitHub Desktop.
playchromecast script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| import pychromecast | |
| import pychromecast.controllers.youtube as youtube | |
| import sys | |
| def cli_loop(): | |
| line = '' | |
| action = '' | |
| param = '' | |
| yt_id = None | |
| cast = pychromecast.get_chromecast() | |
| while action != 'exit': | |
| try: | |
| line = raw_input('Chromecast: ') | |
| except EOFError: | |
| sys.exit(0) | |
| try: | |
| action = line.split(' ')[0] | |
| param = line.split(' ')[1] | |
| except IndexError: | |
| pass | |
| if action == 'media': | |
| mc = pychromecast.controllers.media.MediaController() | |
| cast.register_handler(mc) | |
| if param is not None: | |
| cast.play_media(param, "video/mp4") | |
| elif action == 'pause': | |
| mc.pause() | |
| elif action == 'play': | |
| mc.play() | |
| elif action == 'status': | |
| print cast.status | |
| elif action == 'youtube': | |
| yt = youtube.YouTubeController() | |
| cast.register_handler(yt) | |
| try: | |
| yt_id = param.split('=')[1] | |
| except IndexError: | |
| pass | |
| if yt_id is not None: | |
| yt.play_video(yt_id) | |
| cast.quit_app() | |
| def main(): | |
| cli_loop() | |
| return 0 | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment