Exemplo n.º 1
0
 def stop(self):
     self._before_stop()
     try:
         cast = pycastv2.MediaPlayerController(self.ip, self.port,
                                               self.REQUEST_TIMEOUT)
         self.state = self.IDLE
         cast.disconnect_application()
         return 200, None
     except pycastv2.ChannelClosedException:
         message = 'Connection was closed. I guess another ' \
                   'client is attached to it.'
         return 423, message
     except pycastv2.TimeoutException:
         message = 'STOP command - Could no connect to "{device}". ' \
                   'Connection timeout.'.format(device=self.label)
         return 408, message
     except socket.error as e:
         if e.errno == 111:
             message = 'The chromecast refused the connection. ' \
                       'Perhaps it does not support the castv2 ' \
                       'protocol.'
             return 403, message
         else:
             traceback.print_exc()
         return 500, None
     finally:
         self._after_stop()
         cast.cleanup()
Exemplo n.º 2
0
 def _get_media_player(self):
     try:
         return pycastv2.MediaPlayerController(self.ip)
     except socket.error as e:
         if e.errno == 111:
             logger.info(
                 'The chromecast refused the connection. Perhaps it '
                 'does not support the castv2 protocol.')
         else:
             traceback.print_exc()
         return None
Exemplo n.º 3
0
 def play(self, url=None, codec=None, artist=None, title=None, thumb=None):
     self._before_play()
     url = url or self.get_stream_url()
     try:
         cast = pycastv2.MediaPlayerController(
             self.ip, self.port, self.REQUEST_TIMEOUT)
         cast.load(
             url,
             mime_type=self.codec.mime_type,
             artist=artist,
             title=title,
             thumb=thumb)
         self.state = self.STATE_PLAYING
         return 200, None
     except pycastv2.LaunchErrorException:
         message = 'The media player could not be launched. ' \
                   'Maybe the chromecast is still closing a ' \
                   'running player instance. Try again in 30 seconds.'
         return 503, message
     except pycastv2.ChannelClosedException:
         message = 'Connection was closed. I guess another ' \
                   'client is attached to it.'
         return 423, message
     except pycastv2.TimeoutException:
         message = 'PLAY command - Could no connect to "{device}". ' \
                   'Connection timeout.'.format(device=self.label)
         return 408, message
     except socket.error as e:
         if e.errno == 111:
             message = 'The chromecast refused the connection. ' \
                       'Perhaps it does not support the castv2 ' \
                       'protocol.'
             return 403, message
         else:
             traceback.print_exc()
         return 500, None
     except (pulseaudio_dlna.plugins.renderer.NoEncoderFoundException,
             pulseaudio_dlna.plugins.renderer.NoSuitableHostFoundException)\
             as e:
         return 500, e
     except Exception:
         traceback.print_exc()
         return 500, 'Unknown exception.'
     finally:
         self._after_play()
         cast.cleanup()