16 from mimetypes
import guess_type
27 Audio backend for playback on chromecast. Using the default media 28 playback controller included in pychromecast. 31 LOG.info(
'Trying to connect to chromecast')
32 casts = pychromecast.get_chromecasts()
33 if self.
config is None or 'identifier' not in self.
config:
34 LOG.error(
"Chromecast identifier not found!")
37 identifier = self.
config[
'identifier']
39 if c.name == identifier:
43 LOG.info(
'Couldn\'t find chromecast ' + identifier)
46 self.bus.emit(
Message(
'ChromecastServiceConnect'))
49 def __init__(self, config, bus, name='chromecast', cast=None):
50 super(ChromecastService, self).
__init__(config, bus)
62 self.bus.on(
'ChromecastServiceConnect', self.
_connect)
63 self.bus.emit(
Message(
'ChromecastServiceConnect'))
66 """ Return supported uris of chromecast. """ 67 LOG.info(
"Chromecasts found: " + str(self.
cast))
69 return [
'http',
'https']
74 """ Clear tracklist. """ 79 Add list of tracks to chromecast playlist. 82 tracks (list): list media to add to playlist. 87 def play(self, repeat=False):
90 TODO: add playlist support and repeat 98 LOG.debug(
'track: {}, type: {}'.format(track, guess_type(track)))
99 mime = guess_type(track)[0]
or 'audio/mp3' 100 self.cast.play_media(track, mime)
103 """ Stop playback and quit app. """ 104 if self.cast.media_controller.is_playing:
105 self.cast.media_controller.stop()
112 """ Pause current playback. """ 113 if not self.cast.media_controller.is_paused:
114 self.cast.media_controller.pause()
117 if self.cast.media_controller.is_paused:
118 self.cast.media_controller.play()
121 """ Skip current track. (Not implemented) """ 125 """ Return to previous track. (Not implemented) """ 137 """ Return info about currently playing track. """ 140 ret[
'name'] = info.get(
'name',
'')
142 ret[
'artist'] = info[
'album'][
'artists'][0][
'name']
143 ret[
'album'] = info[
'album'].
get(
'name',
'')
150 """ Disconnect from the device. """ 151 self.cast.disconnect()
156 Autodetect chromecasts on the network and create backends for each 158 casts = pychromecast.get_chromecasts(timeout=5, tries=2, retry_wait=2)
161 LOG.info(c.name +
" found.")
def autodetect(config, bus)
def play(self, repeat=False)
def _connect(self, message)
def __init__(self, config, bus, name='chromecast', cast=None)
def add_list(self, tracks)
def get(phrase, lang=None, context=None)