Steven Smith revised this gist . Go to revision
1 file changed, 16 insertions, 9 deletions
cast.py
| @@ -20,23 +20,30 @@ def stop_video(cast): | |||
| 20 | 20 | cast.quit_app() | |
| 21 | 21 | ||
| 22 | 22 | def main(): | |
| 23 | + | casts = pychromecast.get_chromecasts_as_dict() | |
| 23 | 24 | parser = argparse.ArgumentParser() | |
| 24 | - | parser.add_argument("url", nargs="?", help="URL of media to play. Doesn't support local addresses yet. If no URL is supplied, plays paused video.") | |
| 25 | - | parser.add_argument("-p", "--pause", help="Pause playback", action='store_true') | |
| 25 | + | parser.add_argument("url", nargs="?", help="URL of media to play. Doesn't support local addresses yet.") | |
| 26 | + | # parser.add_argument("-p", "--pause", help="Pause playback", action='store_true') | |
| 26 | 27 | parser.add_argument("-s", "--stop", help="Stop playback", action='store_true') | |
| 28 | + | parser.add_argument("-d", "--device", help="Select device. List devices with -D") | |
| 29 | + | parser.add_argument("-D", "--devices", help="List devices", action='store_true') | |
| 27 | 30 | args = parser.parse_args() | |
| 28 | - | cast = pychromecast.get_chromecast() | |
| 29 | - | if not args.pause or not args.stop: | |
| 30 | - | play_video(args.url, cast) | |
| 31 | + | if args.devices: | |
| 32 | + | print ", ".join(casts.keys()) | |
| 31 | 33 | return | |
| 32 | - | elif args.pause: | |
| 33 | - | pause_video(cast) | |
| 34 | + | if args.device: | |
| 35 | + | cast = casts[args.device] | |
| 36 | + | else: | |
| 37 | + | cast = casts[casts.keys()[0]] | |
| 38 | + | if not args.stop: | |
| 39 | + | play_video(args.url, cast) | |
| 34 | 40 | return | |
| 41 | + | # elif args.pause: | |
| 42 | + | # pause_video(cast) | |
| 43 | + | # return | |
| 35 | 44 | elif args.stop: | |
| 36 | 45 | stop_video(cast) | |
| 37 | 46 | return | |
| 38 | - | print "Did nothing" | |
| 39 | - | return | |
| 40 | 47 | ||
| 41 | 48 | if __name__ == "__main__": | |
| 42 | 49 | main() | |
Steven Smith revised this gist . Go to revision
No changes
Steven Smith revised this gist . Go to revision
1 file changed, 42 insertions
cast.py(file created)
| @@ -0,0 +1,42 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | # requires pychromecast and probably python 2.7, sorry | |
| 3 | + | ||
| 4 | + | import pychromecast | |
| 5 | + | import argparse | |
| 6 | + | ||
| 7 | + | def play_video(url, cast): | |
| 8 | + | if cast.media_controller.status.player_state == "PAUSED" or cast.media_controller.status.content_id == url: | |
| 9 | + | cast.media_controller.play() | |
| 10 | + | else: | |
| 11 | + | cast.play_media((url), "video/mp4") | |
| 12 | + | ||
| 13 | + | def pause_video(cast): | |
| 14 | + | if cast.media_controller.status.supports_pause: | |
| 15 | + | cast.media_controller.pause() | |
| 16 | + | else: | |
| 17 | + | print "Cannot pause" | |
| 18 | + | ||
| 19 | + | def stop_video(cast): | |
| 20 | + | cast.quit_app() | |
| 21 | + | ||
| 22 | + | def main(): | |
| 23 | + | parser = argparse.ArgumentParser() | |
| 24 | + | parser.add_argument("url", nargs="?", help="URL of media to play. Doesn't support local addresses yet. If no URL is supplied, plays paused video.") | |
| 25 | + | parser.add_argument("-p", "--pause", help="Pause playback", action='store_true') | |
| 26 | + | parser.add_argument("-s", "--stop", help="Stop playback", action='store_true') | |
| 27 | + | args = parser.parse_args() | |
| 28 | + | cast = pychromecast.get_chromecast() | |
| 29 | + | if not args.pause or not args.stop: | |
| 30 | + | play_video(args.url, cast) | |
| 31 | + | return | |
| 32 | + | elif args.pause: | |
| 33 | + | pause_video(cast) | |
| 34 | + | return | |
| 35 | + | elif args.stop: | |
| 36 | + | stop_video(cast) | |
| 37 | + | return | |
| 38 | + | print "Did nothing" | |
| 39 | + | return | |
| 40 | + | ||
| 41 | + | if __name__ == "__main__": | |
| 42 | + | main() | |