desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return the id of this plex client.'
@property def unique_id(self):
return '{}.{}'.format(self.__class__, (self.machine_identifier or self.name))
'Return the name of the device.'
@property def name(self):
return self._name
'Return the machine identifier of the device.'
@property def machine_identifier(self):
return self._machine_identifier
'Return the library name of playing media.'
@property def app_name(self):
return self._app_name
'Return the device, if any.'
@property def device(self):
return self._device
'Return the session, if any.'
@property def session(self):
return self._session
'Return the state of the device.'
@property def state(self):
return self._state
'Get the latest details.'
def update(self):
self.update_devices(no_throttle=True) self.update_sessions(no_throttle=True)
'Convert PlexAPI _NA() instances to None.'
def _convert_na_to_none(self, value):
if (value is self.na_type): return None return value
'Get the active media type required by PlexAPI commands.'
@property def _active_media_plexapi_type(self):
if (self.media_content_type is MEDIA_TYPE_MUSIC): return 'music' return 'video'
'Return the content ID of current playing media.'
@property def media_content_id(self):
return self._media_content_id
'Return the content type of current playing media.'
@property def media_content_type(self):
if (self._session_type == 'clip'): _LOGGER.debug('Clip content type detected, compatibility may vary: %s', self.entity_id) return MEDIA_TYPE_TVSHOW elif (self._session_type == 'episode'): return MEDIA_TYPE_TVSHOW elif (self._session_type == 'movie'): retu...
'Return the artist of current playing media, music track only.'
@property def media_artist(self):
return self._media_artist
'Return the album name of current playing media, music track only.'
@property def media_album_name(self):
return self._media_album_name
'Return the album artist of current playing media, music only.'
@property def media_album_artist(self):
return self._media_album_artist
'Return the track number of current playing media, music only.'
@property def media_track(self):
return self._media_track
'Return the duration of current playing media in seconds.'
@property def media_duration(self):
return self._media_duration
'Return the image URL of current playing media.'
@property def media_image_url(self):
return self._media_image_url
'Return the title of current playing media.'
@property def media_title(self):
return self._media_title
'Return the season of current playing media (TV Show only).'
@property def media_season(self):
return self._media_season
'Return the title of the series of current playing media.'
@property def media_series_title(self):
return self._media_series_title
'Return the episode of current playing media (TV Show only).'
@property def media_episode(self):
return self._media_episode
'Return the make of the device (ex. SHIELD Android TV).'
@property def make(self):
return self._make
'Flag media player features that are supported.'
@property def supported_features(self):
if (not self._is_player_active): return None if self.config.get(CONF_SHOW_ALL_CONTROLS): return (((((((SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK) | SUPPORT_NEXT_TRACK) | SUPPORT_STOP) | SUPPORT_VOLUME_SET) | SUPPORT_PLAY) | SUPPORT_TURN_OFF) | SUPPORT_VOLUME_MUTE) if (not self._make): r...
'Detect if local client and adjust url to allow control.'
def _local_client_control_fix(self):
if (self.device is None): return for client in self.device.server.clients(): if (('127.0.0.1' in client.baseurl) and (client.machineIdentifier == self.device.machineIdentifier)): _LOGGER.debug('Local client detected, redirecting controls to Plex server: %s', s...
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
if (self.device and ('playback' in self._device_protocol_capabilities)): self._local_client_control_fix() self.device.setVolume(int((volume * 100)), self._active_media_plexapi_type) self._volume_level = volume
'Return the volume level of the client (0..1).'
@property def volume_level(self):
if (self._is_player_active and self.device and ('playback' in self._device_protocol_capabilities)): return self._volume_level
'Return boolean if volume is currently muted.'
@property def is_volume_muted(self):
if (self._is_player_active and self.device): return self._volume_muted
'Mute the volume. Since we can\'t actually mute, we\'ll: - On mute, store volume and set volume to 0 - On unmute, set volume to previously stored volume'
def mute_volume(self, mute):
if (not (self.device and ('playback' in self._device_protocol_capabilities))): return self._volume_muted = mute if mute: self._previous_volume_level = self._volume_level self.set_volume_level(0) else: self.set_volume_level(self._previous_volume_level)
'Send play command.'
def media_play(self):
if (self.device and ('playback' in self._device_protocol_capabilities)): self._local_client_control_fix() self.device.play(self._active_media_plexapi_type)
'Send pause command.'
def media_pause(self):
if (self.device and ('playback' in self._device_protocol_capabilities)): self._local_client_control_fix() self.device.pause(self._active_media_plexapi_type)
'Send stop command.'
def media_stop(self):
if (self.device and ('playback' in self._device_protocol_capabilities)): self._local_client_control_fix() self.device.stop(self._active_media_plexapi_type)
'Turn the client off.'
def turn_off(self):
self.media_stop()
'Send next track command.'
def media_next_track(self):
if (self.device and ('playback' in self._device_protocol_capabilities)): self._local_client_control_fix() self.device.skipNext(self._active_media_plexapi_type)
'Send previous track command.'
def media_previous_track(self):
if (self.device and ('playback' in self._device_protocol_capabilities)): self._local_client_control_fix() self.device.skipPrevious(self._active_media_plexapi_type)
'Play a piece of media.'
def play_media(self, media_type, media_id, **kwargs):
if (not (self.device and ('playback' in self._device_protocol_capabilities))): return src = json.loads(media_id) media = None if (media_type == 'MUSIC'): media = self.device.server.library.section(src['library_name']).get(src['artist_name']).album(src['album_name']).get(src['track_name']...
'Find TV media and return a Plex media object.'
def _get_tv_media(self, library_name, show_name, season_number, episode_number):
target_season = None target_episode = None show = self.device.server.library.section(library_name).get(show_name) if (not season_number): playlist_name = '{} - {} Episodes'.format(self.entity_id, show_name) return self.device.server.createPlaylist(playlist_name, show.episodes())...
'Instruct Plex client to play a piece of media.'
def _client_play_media(self, media, delete=False, **params):
if (not (self.device and ('playback' in self._device_protocol_capabilities))): _LOGGER.error('Client cannot play media: %s', self.entity_id) return import plexapi.playqueue playqueue = plexapi.playqueue.PlayQueue.create(self.device.server, media, **params) if delete: ...
'Return the scene state attributes.'
@property def device_state_attributes(self):
attr = {} attr['media_content_rating'] = self._media_content_rating attr['session_username'] = self._session_username attr['media_library_name'] = self._app_name return attr
'Initialize the Clementine device.'
def __init__(self, client, name):
self._client = client self._name = name self._muted = False self._volume = 0.0 self._track_id = 0 self._last_track_id = 0 self._track_name = '' self._track_artist = '' self._track_album_name = '' self._state = STATE_UNKNOWN
'Retrieve the latest data from the Clementine Player.'
def update(self):
try: client = self._client if (client.state == 'Playing'): self._state = STATE_PLAYING elif (client.state == 'Paused'): self._state = STATE_PAUSED elif (client.state == 'Disconnected'): self._state = STATE_OFF else: self._state ...
'Return the name of the device.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self._state
'Volume level of the media player (0..1).'
@property def volume_level(self):
return (self._volume / 100.0)
'Return current source name.'
@property def source(self):
source_name = 'Unknown' client = self._client if (client.active_playlist_id in client.playlists): source_name = client.playlists[client.active_playlist_id]['name'] return source_name
'List of available input sources.'
@property def source_list(self):
source_names = [s['name'] for s in self._client.playlists.values()] return source_names
'Select input source.'
def select_source(self, source):
client = self._client sources = [s for s in client.playlists.values() if (s['name'] == source)] if (len(sources) == 1): client.change_song(sources[0]['id'], 0)
'Content type of current playing media.'
@property def media_content_type(self):
return MEDIA_TYPE_MUSIC
'Title of current playing media.'
@property def media_title(self):
return self._track_name
'Artist of current playing media, music track only.'
@property def media_artist(self):
return self._track_artist
'Album name of current playing media, music track only.'
@property def media_album_name(self):
return self._track_album_name
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_CLEMENTINE
'Hash value for media image.'
@property def media_image_hash(self):
if self._client.current_track: return self._client.current_track['track_id'] return None
'Fetch media image of current playing image.'
@asyncio.coroutine def async_get_media_image(self):
if self._client.current_track: image = bytes(self._client.current_track['art']) return (image, 'image/png') return (None, None)
'Volume up the media player.'
def volume_up(self):
newvolume = min((self._client.volume + 4), 100) self._client.set_volume(newvolume)
'Volume down media player.'
def volume_down(self):
newvolume = max((self._client.volume - 4), 0) self._client.set_volume(newvolume)
'Send mute command.'
def mute_volume(self, mute):
self._client.set_volume(0)
'Set volume level.'
def set_volume_level(self, volume):
self._client.set_volume(int((100 * volume)))
'Simulate play pause media player.'
def media_play_pause(self):
if (self._state == STATE_PLAYING): self.media_pause() else: self.media_play()
'Send play command.'
def media_play(self):
self._state = STATE_PLAYING self._client.play()
'Send media pause command to media player.'
def media_pause(self):
self._state = STATE_PAUSED self._client.pause()
'Send next track command.'
def media_next_track(self):
self._client.next()
'Send the previous track command.'
def media_previous_track(self):
self._client.previous()
'Initialize the Sony Bravia device.'
def __init__(self, host, mac, name, pin):
from braviarc import braviarc self._pin = pin self._braviarc = braviarc.BraviaRC(host, mac) self._name = name self._state = STATE_OFF self._muted = False self._program_name = None self._channel_name = None self._channel_number = None self._source = None self._source_list = []...
'Update TV info.'
def update(self):
if (not self._braviarc.is_connected()): if (self._braviarc.get_power_status() != 'off'): self._braviarc.connect(self._pin, CLIENTID_PREFIX, NICKNAME) if (not self._braviarc.is_connected()): return try: if (self._state == STATE_ON): self._refresh_volume...
'Refresh volume information.'
def _refresh_volume(self):
volume_info = self._braviarc.get_volume_info() if (volume_info is not None): self._volume = volume_info.get('volume') self._min_volume = volume_info.get('minVolume') self._max_volume = volume_info.get('maxVolume') self._muted = volume_info.get('mute')
'Return the name of the device.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self._state
'Return the current input source.'
@property def source(self):
return self._source
'List of available input sources.'
@property def source_list(self):
return self._source_list
'Volume level of the media player (0..1).'
@property def volume_level(self):
if (self._volume is not None): return (self._volume / 100) return None
'Boolean if volume is currently muted.'
@property def is_volume_muted(self):
return self._muted
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_BRAVIA
'Title of current playing media.'
@property def media_title(self):
return_value = None if (self._channel_name is not None): return_value = self._channel_name if (self._program_name is not None): return_value = ((return_value + ': ') + self._program_name) return return_value
'Content ID of current playing media.'
@property def media_content_id(self):
return self._channel_name
'Duration of current playing media in seconds.'
@property def media_duration(self):
return self._duration
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
self._braviarc.set_volume_level(volume)
'Turn the media player on.'
def turn_on(self):
self._braviarc.turn_on()
'Turn off media player.'
def turn_off(self):
self._braviarc.turn_off()
'Volume up the media player.'
def volume_up(self):
self._braviarc.volume_up()
'Volume down media player.'
def volume_down(self):
self._braviarc.volume_down()
'Send mute command.'
def mute_volume(self, mute):
self._braviarc.mute_volume(mute)
'Set the input source.'
def select_source(self, source):
if (source in self._content_mapping): uri = self._content_mapping[source] self._braviarc.play_content(uri)
'Simulate play pause media player.'
def media_play_pause(self):
if self._playing: self.media_pause() else: self.media_play()
'Send play command.'
def media_play(self):
self._playing = True self._braviarc.media_play()
'Send media pause command to media player.'
def media_pause(self):
self._playing = False self._braviarc.media_pause()
'Send next track command.'
def media_next_track(self):
self._braviarc.media_next_track()
'Send the previous track command.'
def media_previous_track(self):
self._braviarc.media_previous_track()
'Initialize the webos device.'
def __init__(self, host, mac, name, customize, config):
from pylgtv import WebOsClient from wakeonlan import wol self._client = WebOsClient(host, config) self._wol = wol self._mac = mac self._customize = customize self._name = name self._muted = False self._playing = True self._volume = 0 self._current_source = None self._curr...
'Retrieve the latest data.'
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS) def update(self):
from websockets.exceptions import ConnectionClosed try: current_input = self._client.get_input() if (current_input is not None): self._current_source_id = current_input if (self._state in (STATE_UNKNOWN, STATE_OFF)): self._state = STATE_PLAYING els...
'Return the name of the device.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self._state
'Boolean if volume is currently muted.'
@property def is_volume_muted(self):
return self._muted
'Volume level of the media player (0..1).'
@property def volume_level(self):
return (self._volume / 100.0)
'Return the current input source.'
@property def source(self):
return self._current_source
'List of available input sources.'
@property def source_list(self):
return sorted(self._source_list.keys())
'Content type of current playing media.'
@property def media_content_type(self):
return MEDIA_TYPE_CHANNEL
'Image url of current playing media.'
@property def media_image_url(self):
if (self._current_source_id in self._app_list): icon = self._app_list[self._current_source_id]['largeIcon'] if (not icon.startswith('http')): icon = self._app_list[self._current_source_id]['icon'] return icon return None
'Flag media player features that are supported.'
@property def supported_features(self):
if self._mac: return (SUPPORT_WEBOSTV | SUPPORT_TURN_ON) return SUPPORT_WEBOSTV
'Turn off media player.'
def turn_off(self):
from websockets.exceptions import ConnectionClosed self._state = STATE_OFF try: self._client.power_off() except (OSError, ConnectionClosed, TypeError, asyncio.TimeoutError): pass