Tesserae
e‑ink 디스플레이용 무료 오픈소스 대시보드 서버, 브라우저에서 대시보드 구성·프레임 렌더링·MQTT·REST 전송, 자체 호스팅·추적 없음
Python 3에서 Google Chromecast와 통신하기 위한 라이브러리
Library for Python 3 to communicate with the Google Chromecast.
개발 도구Python · ShellGitHub @home-assistant-libs직접 설치운영자 미확인
써 보셨어요? 한 번만 눌러 주세요. 로그인은 필요 없어요.
메이커가 쓴 소개는 위의 한 줄이 전부입니다. 더 자세한 내용은 저장소 README에서 읽을 수 있습니다. 저장소 README ↗
README 전체를 불러오는 중입니다.
README 전문 보기 ↗.. |Build Status| image:: https://travis-ci.org/balloob/pychromecast.svg?branch=master :target: https://travis-ci.org/balloob/pychromecast
Library for Python 3.14+ to communicate with the Google Chromecast. It currently supports:
Check out Home Assistant <https://home-assistant.io>_ for a
ready-made solution using PyChromecast for controlling and automating
your Chromecast or Cast-enabled device like Google Home.
PyChromecast depends on the Python packages requests, protobuf and
zeroconf. Make sure you have these dependencies installed using
pip install -r requirements.txt
.. code:: python
>> import time
>> import pychromecast
>> import zeroconf
>> # Create a browser which prints the friendly name of found chromecast devices
>> zconf = zeroconf.Zeroconf()
>> browser = pychromecast.CastBrowser(pychromecast.SimpleCastListener(lambda uuid, service: print(browser.devices[uuid].friendly_name)), zconf)
>> browser.start_discovery()
>> # Shut down discovery
>> pychromecast.discovery.stop_discovery(browser)
>> # Discover and connect to chromecasts named Living Room
>> chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=["Living Room"])
>> [cc.cast_info.friendly_name for cc in chromecasts]
['Living Room']
>> # Discover and connect to more than one device
>> chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=["Living Room","Bed Room","Kitchen"])
>> [cc.device.friendly_name for cc in chromecasts]
["Living Room","Bed Room","Kitchen"]
>> # If you are seeing less devices get discovered than expected add the below parameter. You can lessen or extend the timeout as needed.
>> chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=["Living Room","Bed Room","Kitchen"],discovery_timeout=30)
>> [cc.device.friendly_name for cc in chromecasts]
["Living Room","Bed Room","Kitchen"]
>> cast = chromecasts[0]
>> # Start worker thread and wait for cast device to be ready
>> cast.wait()
>> print(cast.cast_info)
CastInfo(services={ServiceInfo(type='mdns', data='Chromecast-Audio-42feced1d94238232fba92623e2682f3._googlecast._tcp.local.')}, uuid=UUID('42feced1-d942-3823-2fba-92623e2682f3'), model_name='Chromecast Audio', friendly_name='Living room', host='192.168.0.189', port=8009, cast_type='audio', manufacturer='Google Inc.')
>> print(cast.status)
CastStatus(is_active_input=True, is_stand_by=False, volume_level=1.0, volume_muted=False, app_id='CC1AD845', display_name='Default Media Receiver', namespaces=['urn:x-cast:com.google.cast.player.message', 'urn:x-cast:com.google.cast.media'], session_id='CCA39713-9A4F-34A6-A8BF-5D97BE7ECA5C', transport_id='web-9', status_text='')
>> mc = cast.media_controller
>> mc.play_media('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', 'video/mp4')
>> mc.block_until_active()
>> print(mc.status)
MediaStatus(current_time=42.458322, content_id='http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', content_type='video/mp4', duration=596.474195, stream_type='BUFFERED', idle_reason=None, media_session_id=1, playback_rate=1, player_state='PLAYING', supported_media_commands=15, volume_level=1, volume_muted=False)
>> mc.pause()
>> time.sleep(5)
>> mc.play()
>> # Shut down discovery
>> pychromecast.discovery.stop_discovery(browser)
Each app that runs on the Chromecast supports namespaces. They specify a JSON-based mini-protocol. This is used to communicate between the Chromecast and your phone/browser and now Python.
Support for extra namespaces is added by using controllers. To add your own namespace to a current chromecast instance you will first have to define your controller. Example of a minimal controller:
.. code:: python
from pychromecast.controllers import BaseController
class MyController(BaseController):
def __init__(self):
super(MyController, self).__init__(
"urn:x-cast:my.super.awesome.namespace")
def receive_message(self, message, data):
print("Wow, I received this message: {}".format(data))
return True # indicate you handled this message
def request_beer(self):
self.send_message({'request': 'beer'})
After you have defined your controller you will have to add an instance to a Chromecast object: cast.register_handler(MyController()). When a message is received with your namespace it will be routed to your controller.
For more options see the BaseController. For an example of a fully implemented controller see the MediaController.
.. _BaseController: https://github.com/balloob/pychromecast/blob/master/pychromecast/controllers/__init__.py .. _MediaController: https://github.com/balloob/pychromecast/blob/master/pychromecast/controllers/media.py
So you've got PyChromecast running and decided it is time to add support to your favorite app. No worries, the following instructions will have you covered in exploring the possibilities.
The following instructions require the use of the Google Chrome browser_ and the Google Cast plugin_.
여기까지가 README 앞부분입니다. 나머지는 원문에서 읽을 수 있습니다. README 전문 보기 ↗