Coder Social home page Coder Social logo

home-assistant-libs / pychromecast Goto Github PK

View Code? Open in Web Editor NEW
2.5K 91.0 379.0 1.04 MB

Library for Python 3 to communicate with the Google Chromecast.

License: MIT License

Python 99.94% Shell 0.06%
cast chromecast python chromecast-audio internet-of-things

pychromecast's People

Contributors

am0s avatar balloob avatar blawford avatar bramkragten avatar clach04 avatar d8ahazard avatar dependabot-preview[bot] avatar dependabot[bot] avatar eerovil avatar emlove avatar emontnemery avatar erik avatar fondberg avatar kharts avatar martinhjelmare avatar maykar avatar minektur avatar molobrakos avatar noob-4-life avatar ottowinter avatar raynes avatar rcludwick avatar rmkraus avatar shane-wiseman-bose avatar smblott-github avatar splinterhead avatar strunker avatar theychx avatar tnyeanderson avatar ur1katz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pychromecast's Issues

Connection failure

Hi,

I am using pychromecast with Home Assistant. I leave my Chromecast attached to the power permanently so I can use it to wake up my TV remotely via home assistant. Pychromecast connects to my Chromecast perfectly well when I first plug it in but after 12-24 hours uptime I start getting the error below. I can still cast media to the Chromecast from my phone but pychromecast is unable to connect. The only way to work around this error is to power cycle the Chromecast.

Sorry but I am not sure what more I can do to debug this error. I have detailed my set up below:

Pychromecast version 0.7.1 (and git clone from github)
Python version 2.7.9 & 3.4.2
Raspberry Pi v2 (up to date Raspbian Jessie)
Chromecast 1 - Firmware 1.17.46278

$ python example.py --show-debug
INFO:pychromecast:Querying device status
INFO:urllib3.connectionpool:Starting new HTTP connection (1): 192.168.0.4
DEBUG:urllib3.connectionpool:"GET /ssdp/device-desc.xml HTTP/1.1" 200 1092
ERROR:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
Traceback (most recent call last):
  File "/home/pi/git/pychromecast/pychromecast/socket_client.py", line 233, in initialize_connection
    self.socket.connect((self.host, self.port))
  File "/usr/lib/python2.7/ssl.py", line 824, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python2.7/ssl.py", line 815, in _real_connect
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 788, in do_handshake
    self._sslobj.do_handshake()
SSLEOFError: EOF occurred in violation of protocol (_ssl.c:581)
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
^CTraceback (most recent call last):
  File "example.py", line 16, in <module>
    cast = pychromecast.get_chromecast()
  File "/home/pi/git/pychromecast/pychromecast/__init__.py", line 162, in get_chromecast
    results = _get_all_chromecasts(tries, retry_wait)
  File "/home/pi/git/pychromecast/pychromecast/__init__.py", line 56, in _get_all_chromecasts
    retry_wait=retry_wait))
  File "/home/pi/git/pychromecast/pychromecast/__init__.py", line 251, in __init__
    tries=tries, timeout=timeout, retry_wait=retry_wait)
  File "/home/pi/git/pychromecast/pychromecast/socket_client.py", line 197, in __init__
    self.initialize_connection()
  File "/home/pi/git/pychromecast/pychromecast/socket_client.py", line 259, in initialize_connection
    time.sleep(self.retry_wait)
KeyboardInterrupt
Exception AttributeError: "'Chromecast' object has no attribute 'socket_client'" in <bound method Chromecast.__del__ of Chromecast('192.168.0.4', port=8009, device=DeviceStatus(friendly_name=u'Chromecast4315', model_name=u'Chromecast', manufacturer=u'Google Inc.', api_version=(1, 0), uuid=UUID('REDACTED'), cast_type='cast'))> ignored

UnboundLocalError at first try

I cant figure out the error, but the test script throws this.
fresh install

from __future__ import print_function
import time
import pychromecast
pychromecast.get_chromecasts_as_dict().keys()

i get

>>> from __future__ import print_function
>>> import time
>>> import pychromecast
>>> pychromecast.get_chromecasts_as_dict().keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pychromecast\__init__.py", line 131, in get_chromecasts_as_dict
    **filters)}
  File "C:\Python27\lib\site-packages\pychromecast\__init__.py", line 88, in get_chromecasts
    cc_list = set(_get_all_chromecasts(tries, retry_wait, timeout))
  File "C:\Python27\lib\site-packages\pychromecast\__init__.py", line 39, in _get_all_chromecasts
    hosts = discover_chromecasts()
  File "C:\Python27\lib\site-packages\pychromecast\discovery.py", line 89, in discover_chromecasts
    browser.cancel()
UnboundLocalError: local variable 'browser' referenced before assignment
>>>

i first thought dongle could not be found but that aint the case with second test script.

from __future__ import print_function
import time
import pychromecast
from pychromecast import *


CHROMECAST_HOST = '10.0.0.187'
globals = [0]
bob = pychromecast.get_device_status('10.0.0.187')
print (bob)
cast = pychromecast.Chromecast(CHROMECAST_HOST)

it finds dongle but get second error here.

DeviceStatus(friendly_name=u'Pegasus-Cast', model_name=u'Eureka Dongle', manufacturer=u'Google Inc.', api_version=(1, 0), uuid=UUID('**********-18ab-1a1a-d241-ceceb703f7e0'), cast_type='cast')
No handlers could be found for logger "pychromecast.socket_client"

YouTubeController doesn't display video

Running the exact example given in the description, YouTubeController used to work perfectly.

Now, however, it just hangs on the YouTube splash screen and never actually displays the video.

Any ideas? I captured the data being sent to the chromecast when I cast a video from chrome:

urn:x-cast:com.google.youtube.mdx( 2K{"type":"flingVideo","data":{"videoId":"IPCx9u93XdA","currentTime":22.009}}

So nothing seems to have changed there.

RFE - Support for Multiroom feature of Chromecast Audio

Hi,
it would be great if you support the new Multiroom feature for Chromecast Audio. It was just released. pychromecast is already recognizing something but not yet in a usable way. If I create a group within the Chromecast App an my mobile I see another Chromecast.

pychromecast.get_chromecasts()
[Chromecast(192.168.42.36, zermeiggern, Chromecast Audio, Google Inc., api=1.0), Chromecast(192.168.42.36, zermeiggern, Chromecast Audio, Google Inc., api=1.0), Chromecast(192.168.42.37, furgstalden, Chromecast Audio, Google Inc., api=1.0)]

As you can see it is currently two times the same device. I assume this is something like a master controller for the group. As soon as I remove the group, the second one disappears.

Br
Michael

socket.error: [Errno 92] Protocol not available

My code:

import pychromecast
pychromecast.get_chromecasts_as_dict().keys()

The first result:

Traceback (most recent call last):
  File "cc.py", line 3, in <module>
    print pychromecast.get_chromecasts_as_dict().keys()
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 98, in get_chromecasts_as_dict
    for cc in get_chromecasts(tries=tries, **filters)}
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 60, in get_chromecasts
    cc_list = set(_get_all_chromecasts(tries=tries))
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 26, in _get_all_chromecasts
    hosts = discover_chromecasts()
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/discovery.py", line 67, in discover_chromecasts
    browser.cancel()
UnboundLocalError: local variable 'browser' referenced before assignment

The original PyChromecast code:

def discover_chromecasts(max_devices=None, timeout=DISCOVER_TIMEOUT):
    """ Discover chromecasts on the network. """
    try:
        zconf = Zeroconf()
        listener = CastListener()
        browser = ServiceBrowser(zconf, "_googlecast._tcp.local.", listener)

        if max_devices is None:
            time.sleep(timeout)
            return listener.devices

        else:
            start = time.time()

            while (time.time() - start < timeout and
                   listener.count < max_devices):
                time.sleep(.1)

            return listener.devices
    finally:
        browser.cancel()
        zconf.close()

After some fixup:

def discover_chromecasts(max_devices=None, timeout=DISCOVER_TIMEOUT):
    """ Discover chromecasts on the network. """
    browser = None
    zconf = None
    try:
        zconf = Zeroconf()
        listener = CastListener()
        browser = ServiceBrowser(zconf, "_googlecast._tcp.local.", listener)

        if max_devices is None:
            time.sleep(timeout)
            return listener.devices

        else:
            start = time.time()

            while (time.time() - start < timeout and
                   listener.count < max_devices):
                time.sleep(.1)

            return listener.devices
    finally:
        if browser:
            browser.cancel()
        if zconf:
            zconf.close()

Detailed error:

Traceback (most recent call last):
  File "cc.py", line 3, in <module>
    print pychromecast.get_chromecasts_as_dict().keys()
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 98, in get_chromecasts_as_dict
    for cc in get_chromecasts(tries=tries, **filters)}
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 60, in get_chromecasts
    cc_list = set(_get_all_chromecasts(tries=tries))
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 26, in _get_all_chromecasts
    hosts = discover_chromecasts()
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/discovery.py", line 49, in discover_chromecasts
    zconf = Zeroconf()
  File "/usr/local/lib/python2.7/dist-packages/zeroconf.py", line 1336, in __init__
    self._listen_socket = new_socket()
  File "/usr/local/lib/python2.7/dist-packages/zeroconf.py", line 1303, in new_socket
    s.setsockopt(socket.SOL_SOCKET, reuseport, 1)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 92] Protocol not available

versions:

PyChromecast==0.6.9
protobuf==3.0.0a3
zeroconf==0.17.2
requests==2.7.0

system:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04
Codename:       trusty

Any fixing ideas?

Feature request: Kodi (XBMC) service addon?

Would anyone be interested in making a Chromecast Audio (Cast) casting script for Kodi (formerly XBMC) in the form of an service addon for Kodi?

Kodi is an open source media player software has an integrated Python interpreter for running native addons inside Kodi, so it would be very cool if someone would make a Chromecast Audio addon for it based on pychromecast.

The foremost feature that I would like to have it so be able to playback music inside Kodi and have that output (cast) to Chromecast Audio, having Kodi act as a casting sender, however it would also be cool to have Kodi act as a Chromecast Audio receiver as well since you most likly have Kodi connected to your television with speakers anyway.

For my own I think that Kodi (cast) output support would be awesome for multi-room music playback.

PS: To have Kodi act as a Chromecast Audio or Video reciever you could probably take ideas of the existing AirPlay / AirTunes service addon for Kodi.

Implement MDNS

Seems that DIAL is deprecated in favor of MDNS, it might be a good idea to start implementing this too, then.

Not receiving events and always getting the same media status.

It's happening with every video, this is what happens all along the Big buck bunny video from example.py

Please let me know if I can help you further to detect this issue

Media status MediaStatus(current_time=0.583322, content_id=None, content_type=None, duration=0, stream_type=None, idle_reason=None, media_session_id=1, playback_rate=1, player_state=u'PLAYING', supported_media_commands=15, volume_level=1, volume_muted=False, media_customData=None)
Media status MediaStatus(current_time=0.583322, content_id=None, content_type=None, duration=0, stream_type=None, idle_reason=None, media_session_id=1, playback_rate=1, player_state=u'PLAYING', supported_media_commands=15, volume_level=1, volume_muted=False, media_customData=None)

Exception in thread WebSocketClient (most likely raised during interpreter shutdown)

Code:
import time
import pychromecast
cast = pychromecast.PyChromecast()
print cast.device
print cast.app
if cast.app_id == pychromecast.APP_ID['HOME']:
print "Chromecast is on the home screen"

Results:
DeviceStatus(friendly_name='Chromecast', model_name='Eureka Dongle', manufacturer='Google Inc.', api_version=(1, 0))
AppStatus(app_id='GoogleMusic', description="Where It's At", state='running', options={'allowStop': 'true'}, service_url='http://192.168.1.11:8008/connection/GoogleMusic', service_protocols=['ramp'])
Exception in thread WebSocketClient (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
File "/usr/lib/python2.7/threading.py", line 505, in run
File "/usr/local/lib/python2.7/dist-packages/ws4py/websocket.py", line 427, in run
File "/usr/local/lib/python2.7/dist-packages/ws4py/websocket.py", line 305, in once
File "/usr/local/lib/python2.7/dist-packages/ws4py/websocket.py", line 357, in process
File "/usr/local/lib/python2.7/dist-packages/ws4py/streaming.py", line 185, in receiver
File "/usr/local/lib/python2.7/dist-packages/ws4py/framing.py", line 138, in _parsing

on debian wheezy.

app is None for rdio

Was playing around with this today. Noticed that all app related properties are None when the Rdio app is running on the chromecast.

Any idea what's up?

Thread sometimes bails with'Bad file descriptor'

[paultag@cassiel:~][โŒš 12:24 AM] โ™ฅ  python
Python 3.4.3+ (default, Jul 28 2015, 13:17:50) 
[GCC 4.9.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pychromecast
>>> pychromecast.get_chromecasts_as_dict()
{}
>>> Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/zeroconf.py", line 1063, in run
    handler(self.zc)
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/zeroconf.py", line 1014, in <lambda>
    state_change=state_change,
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/zeroconf.py", line 931, in fire
    h(**kwargs)
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/zeroconf.py", line 989, in on_change
    listener.add_service(*args)
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/pychromecast/discovery.py", line 34, in add_service
    service = zconf.get_service_info(typ, name)
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/zeroconf.py", line 1398, in get_service_info
    if info.request(self, timeout):
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/zeroconf.py", line 1221, in request
    zc.send(out)
  File "/home/paultag/.virtualenvs/cuttlebot/lib/python3.4/site-packages/zeroconf.py", line 1657, in send
    bytes_sent = s.sendto(packet, 0, (addr, port))
OSError: [Errno 9] Bad file descriptor

Zero length field name

Tried to import pychromecast into EventGhost, ran into some trouble though. Managed to add the packages requests and ws4py but still get the following import when I try to import pychromecast:

Traceback (most recent call last):
Python script "36", line 1, in
import pychromecast
File "C:\Program Files (x86)\EventGhost\lib26\site-packages\pychromecast__init__.py", line 9, in
from .upnp import discover_chromecasts
File "C:\Program Files (x86)\EventGhost\lib26\site-packages\pychromecast\upnp.py", line 25, in
'ST: {}\r\n'.format(SSDP_ST) +
ValueError: zero length field name in format

After some googling it seems it is because EventGhost runs an old version of python: 2.6.5 Stackless 3.1b3 060516 (release26-maint, Mar 20 2010, 15:26:51) [MSC v.1500 32 bit (Intel)].

Apparently ever since Python 2.7 the field numbers are not needed anymore, but as this is an earlier version they are required. I tried to fix this myself but have very limited knowledge of Python. Any chance you could make this compatible with an older Python or show me how to fix it myself?

Any help would be much appreciated.

Sleep required between calls

This works:

import pychromecast
import time
cast = pychromecast.get_chromecast()
print cast.device
time.sleep(1)
print cast.status

This doesn't, show status of None:

import pychromecast
import time
cast = pychromecast.get_chromecast()
print cast.device
print cast.status

Send local video to chromecast

Is there anyway using pychromecast to stream a file on the local filesystem to the chromecast using pychromecast? If not, which protocol needs to be implemented to do that? Because the chromecast is capable of doing this.

This would enable my cast command line tool to do:

cast send file:///home/user/videos/holyvideosbatman.mp4

Which would be awesome!

Stream Website or Picture

Hello,
is it also possible to stream a website (html document or link) or a picture (jpeg, png, whatever) to chromecast with this tool?

I would like to create an info screen that is displayed at certain times and triggered from a server.

Is this possible with your tool?

External subtitles?

Is it possible to add an external subtitle track, e.g. from a URL containing an .srt file? If so, how?

ImportError: No module named 'google'

When I run the example.py file with python3.4 example.py I got a strange error:

Traceback (most recent call last):
  File "example.py", line 10, in <module>
    import pychromecast
  File "/home/robert-jan/Documents/pychromecast/pychromecast/__init__.py", line 11, in <module>
    from . import socket_client
  File "/home/robert-jan/Documents/pychromecast/pychromecast/socket_client.py", line 20, in <module>
    from . import cast_channel_pb2
  File "/home/robert-jan/Documents/pychromecast/pychromecast/cast_channel_pb2.py", line 6, in <module>
    from google.protobuf.internal import enum_type_wrapper
ImportError: No module named 'google'

How can I make this work correctly?

Keep up the good work!

Error handling

It seems rather impossible to handle errors elegantly with the current API. You can't make things like the new volume controls wait_for_response, for example. I took a shot at making a patch to pass along those args, but even if I do and we lose connection to the chromecast, it errors in the background and hangs waiting for the response. I have no way of catching a connection error.

If we can't catch connection errors, we should add some reconnection logic.

Thoughts?

Feature: Start Youtube Video at Specific Time

Feature idea: Allow youtube's start at specific time embed.

For example,
pc.play_youtube_video("jcnMiRCVL18?t=1m27s", cast=cast)
... note the t=1m27s, doesn't seem to work. Unless this method allows for another parameter?

Netflix namespace problem

Great work on this package. I'm trying to get "pause" to work with Netflix and understand I need to add my own namespace. Here's my object:

class MyController(BaseController):
    def __init__(self):
        super(MediaController, self).__init__("urn:x-cast:mdx-netflix-com")
    def receive_message(self, message, data):
        print("Wow, I received this message: {}".format(data))
        return True
    def do_pause(self):
        self.send_message("PAUSE", inc_session_id=True)

Which I instantiate and register. But when I try to use it I get an error:

>>> cast.status
CastStatus(is_active_input=True, is_stand_by=False, volume_level=1.0, volume_muted=False, app_id=u'REMOVED', display_name=u'Netflix', namespaces=[u'urn:x-cast:mdx-netflix-com:service:target:2'], session_id=u'REMOVEDFORTHISPOST', transport_id=u'web-2', status_text='')
>>> netflix = MediaController()
>>> cast.register_handler(netflix)
>>> netflix.do_pause()

Traceback (most recent call last):
  File "<pyshell#84>", line 1, in <module>
    netflix.do_pause()
  File "<pyshell#52>", line 8, in do_pause
    self.send_message("PAUSE", inc_session_id=True)
  File "/usr/local/lib/python2.7/dist-packages/PyChromecast-0.6-py2.7.egg/pychromecast/controllers/__init__.py", line 77, in send_message
    "application.").format(self.namespace))
UnsupportedNamespace: Namespace urn:x-cast:mdx-netflix-com is not supported by runningapplication.

Any idea where I'm going wrong?

Log spamming.

I get these in my logs every 5th second:

 ERROR (Thread-16) [pychromecast.socket_client] Failed to connect, retrying in 5s
Traceback (most recent call last):
  File "/home/stefan/.homeassistant/lib/pychromecast/socket_client.py", line 160, in initialize_connection
    self.socket.connect((self.host, 8009))
  File "/usr/lib/python3.4/ssl.py", line 846, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python3.4/ssl.py", line 837, in _real_connect
    self.do_handshake()
  File "/usr/lib/python3.4/ssl.py", line 810, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 104] Connection reset by peer

I think it would be enough with an INFO level log instead?

Casting a URL to rooted (Eureka ROM) fails

[parker@geesixty pychromecast]$ python
Python 3.4.1 (default, May 19 2014, 17:23:49) 
[GCC 4.9.0 20140507 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> import pychromecast
>>> devices = pychromecast.get_chromecasts_as_dict()
>>> print(devices)
{'Chrast': Chromecast(10.0.1.12, Chrast, Eureka Dongle, Google Inc., api=1.0)}
>>> devices['Chrast'].crd_open_url("http://withg.org/parkerlreed/a5bf63b848d31285874fb807635ee573.mp4")
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 516, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 308, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 146, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 125, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 87, in create_connection
    raise err
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 78, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/parker/build/pychromecast/pychromecast/__init__.py", line 225, in crd_open_url
    return crd_open_url(self.host, url)
  File "/home/parker/build/pychromecast/pychromecast/remotedebug.py", line 26, in crd_open_url
    resp = requests.get(FORMAT_DEBUG_URL.format(host))
  File "/usr/lib/python3.4/site-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python3.4/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 448, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 554, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.4/site-packages/requests/adapters.py", line 359, in send
    timeout=timeout
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
    _pool=self, _stacktrace=stacktrace)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/util/retry.py", line 245, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/packages/six.py", line 309, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 516, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 308, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 146, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 125, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 87, in create_connection
    raise err
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 78, in create_connection
    sock.connect(sa)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))

I'm probably just missing a line here but I'm not sure what.

No app attribute

I know it must seem odd that I'm making this literally less than 30 minutes after you merged the v2 branch in, but you must understand that I have been walking this earth with bated breath waiting for the moment you pushed these changes. Nonetheless, it no work for me. Am I doin' something wrong? :)

In [1]: import pychromecast

In [2]: cast = pychromecast.get_chromecast(friendly_name="Curvy")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-9c5c58869402> in <module>()
----> 1 cast = pychromecast.get_chromecast(friendly_name="Curvy")

/Users/Anthony/code/pychromecast/pychromecast/__init__.pyc in get_chromecast(strict, **filters)
     94     # If no filters given and not strict just use the first dicsovered one.
     95     if filters or strict:
---> 96         results = get_chromecasts(**filters)
     97     else:
     98         results = [Chromecast(ip) for ip in discover_chromecasts(1)]

/Users/Anthony/code/pychromecast/pychromecast/__init__.pyc in get_chromecasts(**filters)
     63     for key, val in filters.items():
     64         for chromecast in cc_list:
---> 65             for tup in [chromecast.device, chromecast.app]:
     66                 if hasattr(tup, key) and val != getattr(tup, key):
     67                     excluded_cc.add(chromecast)

AttributeError: 'Chromecast' object has no attribute 'app'

get_chromecast is rather slow.

The get_chromecast method is pretty slow when it performs the initial discovery. I have a stateless script that runs anew every time it is called, but is there something I can serialize and deserialize to make the discovery process quicker? I'll only ever use one Chromecast at a time, so it would be nice if I could save its address and other info to a file and just load that rather than do the complete discovery again.

How can that be done? Can it be added to the docs?

How to Stream a Website?

Hello, I would like to send a website about pythonscript and not Google Chrome. It's about an information screen which is in operation 24/7.
Unfortunately, the Chromecast function of Google Chrome breaks off again and again.
Is this possible?

ConnectionError name errors

There's a simply typo in the pychromecast.__init__.py file, which I'm guessing (without having looked at the git history) arose at some point when ChromecastConnectionError was created.

playlist support for youtube

it would be very useful to add an option to play playlists from youtube, or add multiple songs at the same time. would that be possible?

remotedebug?

According to this article there should be a remotedebug.py that gives access to .crd_open_url() What happened to that? Is there anyway to mimic this functionality?

Events are not sent to listener when pausing video

I have added a listener with media_controller.register_status_listener()

It seems that it is not called when I pause a movie, when I start playing (from scratch, or from pause state) I get an event..

I see it both using netflix, youtube and viaplay (Danish/Swedish streaming provider) and others, so it's not streaming application specific.

Unable to resolve local hostname to IP

Python is not able on all platforms to resolve a local hostname to an IP address.

@DanOBrien wrote about this in #38:

Here's what I've added to the init.py

    # Resolve host to IP address (line 150)
    print(host)
    host = host[0]
    print(host)
    self.host = socket.gethostbyname(host)

And here's the output:

~/pychromecast-master$ python example.py
(u'Living room.local.', 8009)
Living room.local.
Traceback (most recent call last):
  File "example.py", line 16, in <module>
    cast = pychromecast.get_chromecast()
  File "/home/dobrien/pychromecast-master/pychromecast/__init__.py", line 121, in get_chromecast
    for ip in discover_chromecasts(1)]
  File "/home/dobrien/pychromecast-master/pychromecast/__init__.py", line 154, in __init__
    self.host = socket.gethostbyname(host)
socket.gaierror: [Errno -2] Name or service not known
Exception AttributeError: "'Chromecast' object has no attribute 'socket_client'" in  ignored

Error when getting active chromecast

Hi! I'm getting this error every time I try to get the active chromecasts. I worked perfectly in previous versions. Any help?

Python 2.7.8 (default, Oct 19 2014, 16:02:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

from future import print_function
import time
import pychromecast
pychromecast.get_chromecasts_as_dict().keys()
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/site-packages/zeroconf.py", line 1020, in run
event(self.zc)
File "/usr/local/lib/python2.7/site-packages/zeroconf.py", line 985, in
self.type, record.alias)
File "pychromecast/discovery.py", line 26, in add_service
self.services[name] = (service.server, service.port)
AttributeError: 'NoneType' object has no attribute 'server'

[]

cast=pchr.get_chromecast()
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/site-packages/zeroconf.py", line 1020, in run
event(self.zc)
File "/usr/local/lib/python2.7/site-packages/zeroconf.py", line 985, in
self.type, record.alias)
File "pychromecast/discovery.py", line 26, in add_service
self.services[name] = (service.server, service.port)
AttributeError: 'NoneType' object has no attribute 'server'

Move pychromecast.play_youtube_video and pychromecast.play_youtube_playlist

Although it is very convenient to have these functions, i don't think the pychromecast root is the best place to keep them. Maybe these could be moved to a new module like pychromecast.youtube. Then, every time more helper functions like these are created to control apps on the chromecast, a new module can be created to contain them. That way the API will stay nice and tidy, IMHO.

What do you think?

"SyntaxError: invalid syntax" with Python 2.6.6

$ sudo pip install -r requirements.txt 
Requirement already satisfied (use --upgrade to upgrade): requests>=2.0 in /usr/lib/python2.6/site-packages/requests-2.1.0-py2.6.egg (from -r requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): protobuf>=2.5.0 in /usr/lib/python2.6/site-packages (from -r requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/lib/python2.6/site-packages (from protobuf>=2.5.0->-r requirements.txt (line 2))
Cleaning up...

$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> import time
>>> import pychromecast
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pychromecast/__init__.py", line 79
    return {cc.device.friendly_name: cc for cc in get_chromecasts(**filters)}
                                          ^
SyntaxError: invalid syntax

Exception when getting media_controller

Thanks for pychromecast. I started toying with it, but I hit a problem pretty fast (just replaying the "How to Use" section in the README:

Python 2.7.8 (default, Sep 24 2014, 18:26:21) 
[GCC 4.9.1 20140903 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pychromecast
>>> pychromecast.get_chromecasts_as_dict().keys()
['Chromecast']
>>> cast = pychromecast.get_chromecast(friendly_name="Chromecast")
>>> print(cast.device)
DeviceStatus(friendly_name='Chromecast', model_name='Eureka Dongle', manufacturer='Google Inc.', api_version=(1, 0))
>>> print(cast.app)
None
>>> mc = cast.media_controller
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Chromecast' object has no attribute 'media_controller'
>>> 

This happened when there was something playing on the device using PyChromecast (0.5.1.1) from PyPi.

MediaController should handle load error

2015-07-30 14:40:01,890 - pychromecast.socket_client - WARNING - Message unhandled: Message urn:x-cast:com.google.cast.media from web-25 to sender-0: {u'type': u'LOAD_FAILED', u'requestId': 1538}

Easily reproducable by sending a URL that is non existing. It would be nice to be able to listen for these in the standard controller.

Media controller doesn't set title

The title kwarg in MediaController.play_media() doesn't seem to set the title:

$ python -i
>>> import pychromecast
>>> chromecast = pychromecast.Chromecast('10.0.0.5')
>>> media_controller = chromecast.media_controller
>>> media_controller.play_media('http://10.0.0.3:3000/cast/fury.2014.1080p.mp4', 'video/mp4', title='fury.2014.1080p.mp4')
>>> media_controller.title
>>> print media_controller.title
None

'Chromecast' object has no attribute 'socket_client'

When trying to access a Chromecast that isn't plugged in via
pychromecast.Chromecast(ip) i'm getting an AttributeError:

Exception AttributeError: "'Chromecast' object has no attribute 'socket_client'" in <bound method Chromecast.__del__ of Chromecast('10.0.0.5', port=8009, device=None)> ignored

Can't import pychromecast 0.6.4 on Python 2.7.9

In my test, Python 3.4.3 works fine.
But fail to import on Python 2.7.9.

Install pychromecast through pip install pychromecast
pip list -> pychromecast (0.6.4)

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pychromecast
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pychromecast\__init__.py", line 11, in <mo
dule>
    from . import socket_client
  File "C:\Python27\lib\site-packages\pychromecast\socket_client.py", line 20, i
n <module>
    from . import cast_channel_pb2
  File "C:\Python27\lib\site-packages\pychromecast\cast_channel_pb2.py", line 23
, in <module>
    serialized_pb=_b('\n\x12\x63\x61st_channel.proto\x12 extensions.core_api.cas
t_channel\"\xed\x02\n\x0b\x43\x61stMessage\x12W\n\x10protocol_version\x18\x01 \x
02(\x0e\x32=.extensions.core_api.cast_channel.CastMessage.ProtocolVersion\x12\x1
1\n\tsource_id\x18\x02 \x02(\t\x12\x16\n\x0e\x64\x65stination_id\x18\x03 \x02(\t
\x12\x11\n\tnamespace\x18\x04 \x02(\t\x12O\n\x0cpayload_type\x18\x05 \x02(\x0e\x
32\x39.extensions.core_api.cast_channel.CastMessage.PayloadType\x12\x14\n\x0cpay
load_utf8\x18\x06 \x01(\t\x12\x16\n\x0epayload_binary\x18\x07 \x01(\x0c\"!\n\x0f
ProtocolVersion\x12\x0e\n\nCASTV2_1_0\x10\x00\"%\n\x0bPayloadType\x12\n\n\x06STR
ING\x10\x00\x12\n\n\x06\x42INARY\x10\x01\"s\n\rAuthChallenge\x12\x62\n\x13signat
ure_algorithm\x18\x01 \x01(\x0e\x32\x34.extensions.core_api.cast_channel.Signatu
reAlgorithm:\x0fRSASSA_PKCS1v15\"\xc8\x01\n\x0c\x41uthResponse\x12\x11\n\tsignat
ure\x18\x01 \x02(\x0c\x12\x1f\n\x17\x63lient_auth_certificate\x18\x02 \x02(\x0c\
x12 \n\x18intermediate_certificate\x18\x03 \x03(\x0c\x12\x62\n\x13signature_algo
rithm\x18\x04 \x01(\x0e\x32\x34.extensions.core_api.cast_channel.SignatureAlgori
thm:\x0fRSASSA_PKCS1v15\"\xa8\x01\n\tAuthError\x12I\n\nerror_type\x18\x01 \x02(\
x0e\x32\x35.extensions.core_api.cast_channel.AuthError.ErrorType\"P\n\tErrorType
\x12\x12\n\x0eINTERNAL_ERROR\x10\x00\x12\n\n\x06NO_TLS\x10\x01\x12#\n\x1fSIGNATU
RE_ALGORITHM_UNAVAILABLE\x10\x02\"\xd5\x01\n\x11\x44\x65viceAuthMessage\x12\x42\
n\tchallenge\x18\x01 \x01(\x0b\x32/.extensions.core_api.cast_channel.AuthChallen
ge\x12@\n\x08response\x18\x02 \x01(\x0b\x32..extensions.core_api.cast_channel.Au
thResponse\x12:\n\x05\x65rror\x18\x03 \x01(\x0b\x32+.extensions.core_api.cast_ch
annel.AuthError*J\n\x12SignatureAlgorithm\x12\x0f\n\x0bUNSPECIFIED\x10\x00\x12\x
13\n\x0fRSASSA_PKCS1v15\x10\x01\x12\x0e\n\nRSASSA_PSS\x10\x02\x42\x02H\x03')
TypeError: __init__() got an unexpected keyword argument 'syntax'
>>>

casting mkv file to chrome

Hi,

I am very pleased to have pychromecast. But I want to report some more feature on pychromecast for it's additional feature.

My scenario is like this.

  1. I have no chrome browser but I can install some module in the server
  2. I have some media file which is various format such as (.mkv, .avi)

Problem.
I want to cast my mkv and avi file with out trascoding.
If it's not possible, I would like to cast during transcording.

Can I do this?

is_active_input problems

I have been trying to debug some issues with Home Assistant and I traced it back down to the is_active_input parameter in the settings. I am not entirely sure what this value is supposed to represent, but I am assuming that it is intended to report if the Chromecast is on the TV's selected input.

For me, it appears that the value reported from the Chromecast is changing at random for systems that I believe to support CEC. Sometimes it works, other times it doesn't. For systems that I know do not support CEC, it appears to not be provided.

This value eventually propagates down to the is_idle property. That value is then used inside of Home Assistant for the Cast's status. When this value is not properly functioning, and an unsupported application (Netflix) is playing, HA will report Off instead of Unknown.

I don't know what anyone else's experience is with this parameter, but, assuming I have the proper understanding of its purpose, it seems buggy for me. I would contend that maybe this parameter should not be considered when calculating is_idle since maybe this parameter should only answer the question of is the Chromecast itself idle. I'm not sure it would be best to have this parameter indicate the status of other devices it is connected to.

Then again, I may not be correctly interpreting the purpose of this value.

unable to get the example.py script to work

When I run the example script, I get the following:

~/pychromecast-master$ python example.py
Traceback (most recent call last):
File "example.py", line 16, in
cast = pychromecast.get_chromecast()
File "/home/dobrien/pychromecast-master/pychromecast/init.py", line 121, in get_chromecast
for ip in discover_chromecasts(1)]
File "/home/dobrien/pychromecast-master/pychromecast/init.py", line 151, in init
self.host = socket.gethostbyname(host)
TypeError: must be string, not tuple
Exception AttributeError: "'Chromecast' object has no attribute 'socket_client'" in ignored

I'm using Python 2.7.3
~/pychromecast-master$ python --version
Python 2.7.3

Trying to add title errors out with a KeyError

In the play_media function I'm getting an error when trying to pass a title value. It appears to be how it adds the new title to the 'msg' dictionary. I'm not sure what the API is looking for in terms of structure but this is what I believe it should be.

msg['customData']['payload'] = {'title':title}

That may or may not be correct but it's just my 2 cents.

Nice work though, helped me a ton!

ramp returns "None,None" for time while playing

Ramp output while youtube video is playing:

RampSubprotocol(The Best Robin Williams Moments | Mashable, None/None, playing)

Ramp output while paused:

RampSubprotocol(The Best Robin Williams Moments | Mashable, 87.053/None, stopped)

readme shows this working correctly but it seems like I get None/None as ramp output for any playing video.
from readme:

ramp
RampSubprotocol(Epic sax guy 10 hours, 810.4/36001, playing)

Logging in pychromecast module

The pychromecast module sets the logging level to logging.INFO, globally.
I am currently making a CLI program using pychromecast and everytime i do a play or pause there are these lines of logging I really don't want to see.

Best solution IMO would be to create a singleton logger instance and set the level to logging.INFO on that. That way i can import the logger and set it's level to logging.ERROR for example, so i don't have to look at all the info when i just want to play or pause :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.