2019-04-03 15:40:03 +00:00
|
|
|
"""Support to interface with the Plex API."""
|
2018-09-09 12:26:06 +00:00
|
|
|
from datetime import timedelta
|
2015-10-25 17:00:54 +00:00
|
|
|
import json
|
|
|
|
import logging
|
2019-10-07 04:02:58 +00:00
|
|
|
from xml.etree.ElementTree import ParseError
|
2019-09-09 21:28:20 +00:00
|
|
|
|
|
|
|
import plexapi.exceptions
|
2019-09-05 17:50:26 +00:00
|
|
|
import requests.exceptions
|
2017-04-24 03:41:09 +00:00
|
|
|
|
2019-09-09 21:28:20 +00:00
|
|
|
from homeassistant.components.media_player import MediaPlayerDevice
|
2019-02-08 22:18:18 +00:00
|
|
|
from homeassistant.components.media_player.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
MEDIA_TYPE_MOVIE,
|
|
|
|
MEDIA_TYPE_MUSIC,
|
|
|
|
MEDIA_TYPE_TVSHOW,
|
|
|
|
SUPPORT_NEXT_TRACK,
|
|
|
|
SUPPORT_PAUSE,
|
|
|
|
SUPPORT_PLAY,
|
2019-10-07 04:02:58 +00:00
|
|
|
SUPPORT_PLAY_MEDIA,
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_PREVIOUS_TRACK,
|
|
|
|
SUPPORT_STOP,
|
|
|
|
SUPPORT_TURN_OFF,
|
|
|
|
SUPPORT_VOLUME_MUTE,
|
|
|
|
SUPPORT_VOLUME_SET,
|
|
|
|
)
|
2015-09-19 17:48:45 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
DEVICE_DEFAULT_NAME,
|
|
|
|
STATE_IDLE,
|
|
|
|
STATE_OFF,
|
|
|
|
STATE_PAUSED,
|
|
|
|
STATE_PLAYING,
|
|
|
|
)
|
2019-05-27 04:39:50 +00:00
|
|
|
from homeassistant.helpers.event import track_time_interval
|
2018-03-19 21:15:21 +00:00
|
|
|
from homeassistant.util import dt as dt_util
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2019-09-05 17:50:26 +00:00
|
|
|
from .const import (
|
2019-09-19 21:29:26 +00:00
|
|
|
CONF_SERVER_IDENTIFIER,
|
2019-09-05 17:50:26 +00:00
|
|
|
DOMAIN as PLEX_DOMAIN,
|
|
|
|
NAME_FORMAT,
|
2019-09-22 21:47:41 +00:00
|
|
|
REFRESH_LISTENERS,
|
2019-09-09 21:28:20 +00:00
|
|
|
SERVERS,
|
2019-09-05 17:50:26 +00:00
|
|
|
)
|
2017-04-24 03:41:09 +00:00
|
|
|
|
2019-09-05 17:50:26 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2015-10-25 17:00:54 +00:00
|
|
|
|
2019-09-19 21:29:26 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
|
|
|
"""Set up the Plex media_player platform.
|
|
|
|
|
|
|
|
Deprecated.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up Plex media_player from a config entry."""
|
|
|
|
|
|
|
|
def add_entities(entities, update_before_add=False):
|
|
|
|
"""Sync version of async add entities."""
|
|
|
|
hass.add_job(async_add_entities, entities, update_before_add)
|
|
|
|
|
|
|
|
hass.async_add_executor_job(_setup_platform, hass, config_entry, add_entities)
|
|
|
|
|
2018-03-01 01:53:51 +00:00
|
|
|
|
2019-09-19 21:29:26 +00:00
|
|
|
def _setup_platform(hass, config_entry, add_entities_callback):
|
|
|
|
"""Set up the Plex media_player platform."""
|
|
|
|
server_id = config_entry.data[CONF_SERVER_IDENTIFIER]
|
|
|
|
plexserver = hass.data[PLEX_DOMAIN][SERVERS][server_id]
|
2019-09-05 17:50:26 +00:00
|
|
|
plex_clients = {}
|
2015-09-29 19:50:07 +00:00
|
|
|
plex_sessions = {}
|
2019-09-22 21:47:41 +00:00
|
|
|
hass.data[PLEX_DOMAIN][REFRESH_LISTENERS][server_id] = track_time_interval(
|
|
|
|
hass, lambda now: update_devices(), timedelta(seconds=10)
|
|
|
|
)
|
2015-09-29 19:50:07 +00:00
|
|
|
|
|
|
|
def update_devices():
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Update the devices objects."""
|
2015-09-29 19:50:07 +00:00
|
|
|
try:
|
2015-10-13 21:59:13 +00:00
|
|
|
devices = plexserver.clients()
|
2015-10-25 10:45:15 +00:00
|
|
|
except plexapi.exceptions.BadRequest:
|
2017-05-02 16:18:47 +00:00
|
|
|
_LOGGER.exception("Error listing plex devices")
|
2016-07-05 17:50:43 +00:00
|
|
|
return
|
2017-07-13 15:01:12 +00:00
|
|
|
except requests.exceptions.RequestException as ex:
|
2018-12-05 14:58:46 +00:00
|
|
|
_LOGGER.warning(
|
2019-09-09 21:28:20 +00:00
|
|
|
"Could not connect to Plex server: %s (%s)",
|
|
|
|
plexserver.friendly_name,
|
|
|
|
ex,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2015-09-29 19:50:07 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
new_plex_clients = []
|
2018-03-09 16:50:21 +00:00
|
|
|
available_client_ids = []
|
2015-09-29 19:50:07 +00:00
|
|
|
for device in devices:
|
2015-10-13 21:59:13 +00:00
|
|
|
# For now, let's allow all deviceClass types
|
2019-07-31 19:25:30 +00:00
|
|
|
if device.deviceClass in ["badClient"]:
|
2015-09-29 19:50:07 +00:00
|
|
|
continue
|
|
|
|
|
2018-03-09 16:50:21 +00:00
|
|
|
available_client_ids.append(device.machineIdentifier)
|
|
|
|
|
2015-10-13 21:59:13 +00:00
|
|
|
if device.machineIdentifier not in plex_clients:
|
2018-09-09 12:26:06 +00:00
|
|
|
new_client = PlexClient(
|
2019-09-26 09:10:20 +00:00
|
|
|
plexserver, device, None, plex_sessions, update_devices
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2015-10-13 21:59:13 +00:00
|
|
|
plex_clients[device.machineIdentifier] = new_client
|
2019-03-22 02:41:41 +00:00
|
|
|
_LOGGER.debug("New device: %s", device.machineIdentifier)
|
2015-09-29 19:50:07 +00:00
|
|
|
new_plex_clients.append(new_client)
|
|
|
|
else:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Refreshing device: %s", device.machineIdentifier)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
plex_clients[device.machineIdentifier].refresh(device, None)
|
|
|
|
|
|
|
|
# add devices with a session and no client (ex. PlexConnect Apple TV's)
|
2019-05-23 12:00:41 +00:00
|
|
|
try:
|
|
|
|
sessions = plexserver.sessions()
|
|
|
|
except plexapi.exceptions.BadRequest:
|
|
|
|
_LOGGER.exception("Error listing plex sessions")
|
|
|
|
return
|
|
|
|
except requests.exceptions.RequestException as ex:
|
|
|
|
_LOGGER.warning(
|
2019-09-09 21:28:20 +00:00
|
|
|
"Could not connect to Plex server: %s (%s)",
|
|
|
|
plexserver.friendly_name,
|
|
|
|
ex,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-05-23 12:00:41 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
plex_sessions.clear()
|
|
|
|
for session in sessions:
|
|
|
|
for player in session.players:
|
|
|
|
plex_sessions[player.machineIdentifier] = session, player
|
|
|
|
|
|
|
|
for machine_identifier, (session, player) in plex_sessions.items():
|
|
|
|
if machine_identifier in available_client_ids:
|
|
|
|
# Avoid using session if already added as a device.
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Skipping session, device exists: %s", machine_identifier)
|
2019-05-23 12:00:41 +00:00
|
|
|
continue
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
if (
|
|
|
|
machine_identifier not in plex_clients
|
|
|
|
and machine_identifier is not None
|
|
|
|
):
|
2019-05-23 12:00:41 +00:00
|
|
|
new_client = PlexClient(
|
2019-09-26 09:10:20 +00:00
|
|
|
plexserver, player, session, plex_sessions, update_devices
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-05-23 12:00:41 +00:00
|
|
|
plex_clients[machine_identifier] = new_client
|
|
|
|
_LOGGER.debug("New session: %s", machine_identifier)
|
|
|
|
new_plex_clients.append(new_client)
|
|
|
|
else:
|
|
|
|
_LOGGER.debug("Refreshing session: %s", machine_identifier)
|
|
|
|
plex_clients[machine_identifier].refresh(None, session)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2018-01-30 22:44:05 +00:00
|
|
|
for client in plex_clients.values():
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# force devices to idle that do not have a valid session
|
|
|
|
if client.session is None:
|
|
|
|
client.force_idle()
|
2015-09-29 19:50:07 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
client.set_availability(
|
|
|
|
client.machine_identifier in available_client_ids
|
|
|
|
or client.machine_identifier in plex_sessions
|
|
|
|
)
|
2018-03-09 16:50:21 +00:00
|
|
|
|
2019-05-27 04:39:50 +00:00
|
|
|
if client not in new_plex_clients:
|
|
|
|
client.schedule_update_ha_state()
|
|
|
|
|
2015-09-29 19:50:07 +00:00
|
|
|
if new_plex_clients:
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities_callback(new_plex_clients)
|
2015-09-29 19:50:07 +00:00
|
|
|
|
2015-09-20 20:13:26 +00:00
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
class PlexClient(MediaPlayerDevice):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Representation of a Plex device."""
|
2015-09-19 17:48:45 +00:00
|
|
|
|
2019-09-26 09:10:20 +00:00
|
|
|
def __init__(self, plex_server, device, session, plex_sessions, update_devices):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Initialize the Plex device."""
|
2019-07-31 19:25:30 +00:00
|
|
|
self._app_name = ""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._device = None
|
2018-03-09 16:50:21 +00:00
|
|
|
self._available = False
|
2018-03-19 21:15:21 +00:00
|
|
|
self._marked_unavailable = None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._device_protocol_capabilities = None
|
|
|
|
self._is_player_active = False
|
|
|
|
self._is_player_available = False
|
2017-10-25 09:42:13 +00:00
|
|
|
self._player = None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._machine_identifier = None
|
2019-07-31 19:25:30 +00:00
|
|
|
self._make = ""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._name = None
|
2019-07-31 19:25:30 +00:00
|
|
|
self._player_state = "idle"
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._previous_volume_level = 1 # Used in fake muting
|
|
|
|
self._session = None
|
|
|
|
self._session_type = None
|
2017-04-01 02:36:37 +00:00
|
|
|
self._session_username = None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._state = STATE_IDLE
|
|
|
|
self._volume_level = 1 # since we can't retrieve remotely
|
|
|
|
self._volume_muted = False # since we can't retrieve remotely
|
2019-09-26 09:10:20 +00:00
|
|
|
self.plex_server = plex_server
|
2015-09-29 19:50:07 +00:00
|
|
|
self.plex_sessions = plex_sessions
|
|
|
|
self.update_devices = update_devices
|
2017-12-24 16:18:31 +00:00
|
|
|
# General
|
|
|
|
self._media_content_id = None
|
|
|
|
self._media_content_rating = None
|
|
|
|
self._media_content_type = None
|
|
|
|
self._media_duration = None
|
|
|
|
self._media_image_url = None
|
|
|
|
self._media_title = None
|
|
|
|
self._media_position = None
|
2019-03-22 20:00:13 +00:00
|
|
|
self._media_position_updated_at = None
|
2017-12-24 16:18:31 +00:00
|
|
|
# Music
|
|
|
|
self._media_album_artist = None
|
|
|
|
self._media_album_name = None
|
|
|
|
self._media_artist = None
|
|
|
|
self._media_track = None
|
|
|
|
# TV Show
|
|
|
|
self._media_episode = None
|
|
|
|
self._media_season = None
|
|
|
|
self._media_series_title = None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
self.refresh(device, session)
|
|
|
|
|
2017-12-24 16:18:31 +00:00
|
|
|
def _clear_media_details(self):
|
2017-10-07 19:31:01 +00:00
|
|
|
"""Set all Media Items to None."""
|
|
|
|
# General
|
|
|
|
self._media_content_id = None
|
|
|
|
self._media_content_rating = None
|
|
|
|
self._media_content_type = None
|
|
|
|
self._media_duration = None
|
|
|
|
self._media_image_url = None
|
|
|
|
self._media_title = None
|
|
|
|
# Music
|
|
|
|
self._media_album_artist = None
|
|
|
|
self._media_album_name = None
|
|
|
|
self._media_artist = None
|
|
|
|
self._media_track = None
|
|
|
|
# TV Show
|
|
|
|
self._media_episode = None
|
|
|
|
self._media_season = None
|
|
|
|
self._media_series_title = None
|
|
|
|
|
2017-12-24 16:18:31 +00:00
|
|
|
# Clear library Name
|
2019-07-31 19:25:30 +00:00
|
|
|
self._app_name = ""
|
2017-12-24 16:18:31 +00:00
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
def refresh(self, device, session):
|
|
|
|
"""Refresh key device data."""
|
2017-12-24 16:18:31 +00:00
|
|
|
self._clear_media_details()
|
2017-10-07 19:31:01 +00:00
|
|
|
|
|
|
|
if session: # Not being triggered by Chrome or FireTablet Plex App
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._session = session
|
|
|
|
if device:
|
|
|
|
self._device = device
|
2019-01-29 08:15:42 +00:00
|
|
|
try:
|
|
|
|
device_url = self._device.url("/")
|
|
|
|
except plexapi.exceptions.BadRequest:
|
2019-07-31 19:25:30 +00:00
|
|
|
device_url = "127.0.0.1"
|
2019-01-29 08:15:42 +00:00
|
|
|
if "127.0.0.1" in device_url:
|
2017-10-25 09:42:13 +00:00
|
|
|
self._device.proxyThroughServer()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._session = None
|
2017-10-25 09:42:13 +00:00
|
|
|
self._machine_identifier = self._device.machineIdentifier
|
2019-07-31 19:25:30 +00:00
|
|
|
self._name = NAME_FORMAT.format(self._device.title or DEVICE_DEFAULT_NAME)
|
|
|
|
self._device_protocol_capabilities = self._device.protocolCapabilities
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2017-10-25 09:42:13 +00:00
|
|
|
# set valid session, preferring device session
|
2019-01-29 08:15:42 +00:00
|
|
|
if self._device.machineIdentifier in self.plex_sessions:
|
2017-10-25 09:42:13 +00:00
|
|
|
self._session = self.plex_sessions.get(
|
2019-07-31 19:25:30 +00:00
|
|
|
self._device.machineIdentifier, [None, None]
|
|
|
|
)[0]
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
if self._session:
|
2019-07-31 19:25:30 +00:00
|
|
|
if (
|
|
|
|
self._device is not None
|
|
|
|
and self._device.machineIdentifier is not None
|
|
|
|
and self._session.players
|
|
|
|
):
|
2017-10-25 09:42:13 +00:00
|
|
|
self._is_player_available = True
|
2019-07-31 19:25:30 +00:00
|
|
|
self._player = [
|
|
|
|
p
|
|
|
|
for p in self._session.players
|
|
|
|
if p.machineIdentifier == self._device.machineIdentifier
|
|
|
|
][0]
|
2019-05-26 10:28:29 +00:00
|
|
|
self._name = NAME_FORMAT.format(self._player.title)
|
2017-10-25 09:42:13 +00:00
|
|
|
self._player_state = self._player.state
|
|
|
|
self._session_username = self._session.usernames[0]
|
|
|
|
self._make = self._player.device
|
|
|
|
else:
|
|
|
|
self._is_player_available = False
|
2019-03-22 20:00:13 +00:00
|
|
|
|
|
|
|
# Calculate throttled position for proper progress display.
|
|
|
|
position = int(self._session.viewOffset / 1000)
|
|
|
|
now = dt_util.utcnow()
|
|
|
|
if self._media_position is not None:
|
2019-07-31 19:25:30 +00:00
|
|
|
pos_diff = position - self._media_position
|
2019-03-22 20:00:13 +00:00
|
|
|
time_diff = now - self._media_position_updated_at
|
2019-07-31 19:25:30 +00:00
|
|
|
if pos_diff != 0 and abs(time_diff.total_seconds() - pos_diff) > 5:
|
2019-03-22 20:00:13 +00:00
|
|
|
self._media_position_updated_at = now
|
|
|
|
self._media_position = position
|
|
|
|
else:
|
|
|
|
self._media_position_updated_at = now
|
|
|
|
self._media_position = position
|
|
|
|
|
2017-10-25 09:42:13 +00:00
|
|
|
self._media_content_id = self._session.ratingKey
|
2019-07-31 19:25:30 +00:00
|
|
|
self._media_content_rating = getattr(self._session, "contentRating", None)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2017-12-24 16:18:31 +00:00
|
|
|
self._set_player_state()
|
|
|
|
|
|
|
|
if self._is_player_active and self._session is not None:
|
|
|
|
self._session_type = self._session.type
|
2019-03-22 20:00:13 +00:00
|
|
|
self._media_duration = int(self._session.duration / 1000)
|
2017-12-24 16:18:31 +00:00
|
|
|
# title (movie name, tv episode name, music song name)
|
|
|
|
self._media_title = self._session.title
|
|
|
|
# media type
|
|
|
|
self._set_media_type()
|
2019-07-31 19:25:30 +00:00
|
|
|
self._app_name = (
|
|
|
|
self._session.section().title
|
|
|
|
if self._session.section() is not None
|
|
|
|
else ""
|
|
|
|
)
|
2017-12-24 16:18:31 +00:00
|
|
|
self._set_media_image()
|
|
|
|
else:
|
|
|
|
self._session_type = None
|
|
|
|
|
|
|
|
def _set_media_image(self):
|
|
|
|
thumb_url = self._session.thumbUrl
|
2019-09-26 09:10:20 +00:00
|
|
|
if (
|
|
|
|
self.media_content_type is MEDIA_TYPE_TVSHOW
|
|
|
|
and not self.plex_server.use_episode_art
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2018-01-03 18:28:43 +00:00
|
|
|
thumb_url = self._session.url(self._session.grandparentThumb)
|
2017-12-24 16:18:31 +00:00
|
|
|
|
|
|
|
if thumb_url is None:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug(
|
|
|
|
"Using media art because media thumb " "was not found: %s",
|
|
|
|
self.entity_id,
|
|
|
|
)
|
2018-01-03 18:28:43 +00:00
|
|
|
thumb_url = self.session.url(self._session.art)
|
2017-12-24 16:18:31 +00:00
|
|
|
|
|
|
|
self._media_image_url = thumb_url
|
|
|
|
|
2018-03-09 16:50:21 +00:00
|
|
|
def set_availability(self, available):
|
|
|
|
"""Set the device as available/unavailable noting time."""
|
|
|
|
if not available:
|
|
|
|
self._clear_media_details()
|
2018-03-19 21:15:21 +00:00
|
|
|
if self._marked_unavailable is None:
|
|
|
|
self._marked_unavailable = dt_util.utcnow()
|
|
|
|
else:
|
|
|
|
self._marked_unavailable = None
|
|
|
|
|
2018-03-09 16:50:21 +00:00
|
|
|
self._available = available
|
|
|
|
|
2017-12-24 16:18:31 +00:00
|
|
|
def _set_player_state(self):
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._player_state == "playing":
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._is_player_active = True
|
|
|
|
self._state = STATE_PLAYING
|
2019-07-31 19:25:30 +00:00
|
|
|
elif self._player_state == "paused":
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._is_player_active = True
|
|
|
|
self._state = STATE_PAUSED
|
2018-08-26 19:25:39 +00:00
|
|
|
elif self.device:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._is_player_active = False
|
|
|
|
self._state = STATE_IDLE
|
|
|
|
else:
|
|
|
|
self._is_player_active = False
|
|
|
|
self._state = STATE_OFF
|
|
|
|
|
2017-12-24 16:18:31 +00:00
|
|
|
def _set_media_type(self):
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._session_type in ["clip", "episode"]:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_content_type = MEDIA_TYPE_TVSHOW
|
|
|
|
|
|
|
|
# season number (00)
|
2018-01-03 18:28:43 +00:00
|
|
|
if callable(self._session.season):
|
2019-07-31 19:25:30 +00:00
|
|
|
self._media_season = str((self._session.season()).index).zfill(2)
|
2017-10-25 09:42:13 +00:00
|
|
|
elif self._session.parentIndex is not None:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_season = self._session.parentIndex.zfill(2)
|
|
|
|
else:
|
|
|
|
self._media_season = None
|
|
|
|
# show name
|
2017-10-25 09:42:13 +00:00
|
|
|
self._media_series_title = self._session.grandparentTitle
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# episode number (00)
|
2017-10-25 09:42:13 +00:00
|
|
|
if self._session.index is not None:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_episode = str(self._session.index).zfill(2)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
elif self._session_type == "movie":
|
2018-04-05 16:44:38 +00:00
|
|
|
self._media_content_type = MEDIA_TYPE_MOVIE
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._session.year is not None and self._media_title is not None:
|
|
|
|
self._media_title += " (" + str(self._session.year) + ")"
|
2017-12-24 16:18:31 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
elif self._session_type == "track":
|
2017-12-24 16:18:31 +00:00
|
|
|
self._media_content_type = MEDIA_TYPE_MUSIC
|
2017-10-25 09:42:13 +00:00
|
|
|
self._media_album_name = self._session.parentTitle
|
|
|
|
self._media_album_artist = self._session.grandparentTitle
|
|
|
|
self._media_track = self._session.index
|
|
|
|
self._media_artist = self._session.originalTitle
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# use album artist if track artist is missing
|
|
|
|
if self._media_artist is None:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug(
|
|
|
|
"Using album artist because track artist " "was not found: %s",
|
|
|
|
self.entity_id,
|
|
|
|
)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_artist = self._media_album_artist
|
|
|
|
|
|
|
|
def force_idle(self):
|
|
|
|
"""Force client to idle."""
|
|
|
|
self._state = STATE_IDLE
|
|
|
|
self._session = None
|
2017-12-24 16:18:31 +00:00
|
|
|
self._clear_media_details()
|
2015-09-29 19:50:07 +00:00
|
|
|
|
2019-05-27 04:39:50 +00:00
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""Return True if entity has to be polled for state."""
|
|
|
|
return False
|
|
|
|
|
2015-10-25 10:45:15 +00:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the id of this plex client."""
|
2018-01-30 09:39:39 +00:00
|
|
|
return self.machine_identifier
|
2015-10-25 10:45:15 +00:00
|
|
|
|
2018-03-09 16:50:21 +00:00
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return the availability of the client."""
|
|
|
|
return self._available
|
|
|
|
|
2015-10-25 10:45:15 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the name of the device."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def machine_identifier(self):
|
|
|
|
"""Return the machine identifier of the device."""
|
|
|
|
return self._machine_identifier
|
|
|
|
|
|
|
|
@property
|
|
|
|
def app_name(self):
|
|
|
|
"""Return the library name of playing media."""
|
|
|
|
return self._app_name
|
|
|
|
|
2018-08-26 19:25:39 +00:00
|
|
|
@property
|
|
|
|
def device(self):
|
|
|
|
"""Return the device, if any."""
|
2018-08-29 08:07:32 +00:00
|
|
|
return self._device
|
2018-08-26 19:25:39 +00:00
|
|
|
|
2018-03-19 21:15:21 +00:00
|
|
|
@property
|
|
|
|
def marked_unavailable(self):
|
|
|
|
"""Return time device was marked unavailable."""
|
|
|
|
return self._marked_unavailable
|
|
|
|
|
2015-09-29 19:50:07 +00:00
|
|
|
@property
|
|
|
|
def session(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the session, if any."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._session
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the state of the device."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._state
|
2015-09-19 17:48:45 +00:00
|
|
|
|
2016-08-08 15:55:58 +00:00
|
|
|
@property
|
|
|
|
def _active_media_plexapi_type(self):
|
|
|
|
"""Get the active media type required by PlexAPI commands."""
|
|
|
|
if self.media_content_type is MEDIA_TYPE_MUSIC:
|
2019-07-31 19:25:30 +00:00
|
|
|
return "music"
|
2017-07-06 06:30:01 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
return "video"
|
2016-08-08 15:55:58 +00:00
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
@property
|
|
|
|
def media_content_id(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the content ID of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_content_id
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_content_type(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the content type of current playing media."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._session_type == "clip":
|
|
|
|
_LOGGER.debug(
|
|
|
|
"Clip content type detected, " "compatibility may vary: %s",
|
|
|
|
self.entity_id,
|
|
|
|
)
|
2015-09-21 14:44:24 +00:00
|
|
|
return MEDIA_TYPE_TVSHOW
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._session_type == "episode":
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return MEDIA_TYPE_TVSHOW
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._session_type == "movie":
|
2018-04-05 16:44:38 +00:00
|
|
|
return MEDIA_TYPE_MOVIE
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._session_type == "track":
|
2016-08-08 15:55:58 +00:00
|
|
|
return MEDIA_TYPE_MUSIC
|
2017-07-06 06:30:01 +00:00
|
|
|
|
|
|
|
return None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_artist(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the artist of current playing media, music track only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_artist
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_album_name(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the album name of current playing media, music track only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_album_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_album_artist(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the album artist of current playing media, music only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_album_artist
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_track(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the track number of current playing media, music only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_track
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_duration(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the duration of current playing media in seconds."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_duration
|
2015-09-19 17:48:45 +00:00
|
|
|
|
2019-03-22 20:00:13 +00:00
|
|
|
@property
|
|
|
|
def media_position(self):
|
|
|
|
"""Return the duration of current playing media in seconds."""
|
|
|
|
return self._media_position
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_position_updated_at(self):
|
|
|
|
"""When was the position of the current playing media valid."""
|
|
|
|
return self._media_position_updated_at
|
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
@property
|
|
|
|
def media_image_url(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the image URL of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_image_url
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_title(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the title of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_title
|
2015-09-20 20:13:26 +00:00
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
@property
|
|
|
|
def media_season(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the season of current playing media (TV Show only)."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_season
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_series_title(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the title of the series of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_series_title
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_episode(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the episode of current playing media (TV Show only)."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_episode
|
|
|
|
|
|
|
|
@property
|
|
|
|
def make(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the make of the device (ex. SHIELD Android TV)."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._make
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
2017-02-08 04:42:45 +00:00
|
|
|
def supported_features(self):
|
|
|
|
"""Flag media player features that are supported."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# force show all controls
|
2019-09-26 09:10:20 +00:00
|
|
|
if self.plex_server.show_all_controls:
|
2019-07-31 19:25:30 +00:00
|
|
|
return (
|
|
|
|
SUPPORT_PAUSE
|
|
|
|
| SUPPORT_PREVIOUS_TRACK
|
|
|
|
| SUPPORT_NEXT_TRACK
|
|
|
|
| SUPPORT_STOP
|
|
|
|
| SUPPORT_VOLUME_SET
|
|
|
|
| SUPPORT_PLAY
|
2019-10-07 04:02:58 +00:00
|
|
|
| SUPPORT_PLAY_MEDIA
|
2019-07-31 19:25:30 +00:00
|
|
|
| SUPPORT_TURN_OFF
|
|
|
|
| SUPPORT_VOLUME_MUTE
|
|
|
|
)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
# no mute support
|
2018-07-23 08:16:05 +00:00
|
|
|
if self.make.lower() == "shield android tv":
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
_LOGGER.debug(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Shield Android TV client detected, disabling mute " "controls: %s",
|
|
|
|
self.entity_id,
|
|
|
|
)
|
|
|
|
return (
|
|
|
|
SUPPORT_PAUSE
|
|
|
|
| SUPPORT_PREVIOUS_TRACK
|
|
|
|
| SUPPORT_NEXT_TRACK
|
|
|
|
| SUPPORT_STOP
|
|
|
|
| SUPPORT_VOLUME_SET
|
|
|
|
| SUPPORT_PLAY
|
2019-10-07 04:02:58 +00:00
|
|
|
| SUPPORT_PLAY_MEDIA
|
2019-07-31 19:25:30 +00:00
|
|
|
| SUPPORT_TURN_OFF
|
|
|
|
)
|
2019-10-07 04:02:58 +00:00
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# Only supports play,pause,stop (and off which really is stop)
|
2018-07-23 08:16:05 +00:00
|
|
|
if self.make.lower().startswith("tivo"):
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
_LOGGER.debug(
|
2017-04-24 03:41:09 +00:00
|
|
|
"Tivo client detected, only enabling pause, play, "
|
2019-07-31 19:25:30 +00:00
|
|
|
"stop, and off controls: %s",
|
|
|
|
self.entity_id,
|
|
|
|
)
|
|
|
|
return SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_STOP | SUPPORT_TURN_OFF
|
2019-10-07 04:02:58 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.device and "playback" in self._device_protocol_capabilities:
|
|
|
|
return (
|
|
|
|
SUPPORT_PAUSE
|
|
|
|
| SUPPORT_PREVIOUS_TRACK
|
|
|
|
| SUPPORT_NEXT_TRACK
|
|
|
|
| SUPPORT_STOP
|
|
|
|
| SUPPORT_VOLUME_SET
|
|
|
|
| SUPPORT_PLAY
|
2019-10-07 04:02:58 +00:00
|
|
|
| SUPPORT_PLAY_MEDIA
|
2019-07-31 19:25:30 +00:00
|
|
|
| SUPPORT_TURN_OFF
|
|
|
|
| SUPPORT_VOLUME_MUTE
|
|
|
|
)
|
2017-07-06 06:30:01 +00:00
|
|
|
|
2019-04-19 23:56:34 +00:00
|
|
|
return 0
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2016-08-08 15:55:58 +00:00
|
|
|
def set_volume_level(self, volume):
|
|
|
|
"""Set volume level, range 0..1."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.device and "playback" in self._device_protocol_capabilities:
|
|
|
|
self.device.setVolume(int(volume * 100), self._active_media_plexapi_type)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._volume_level = volume # store since we can't retrieve
|
2019-05-27 04:39:50 +00:00
|
|
|
self.update_devices()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def volume_level(self):
|
|
|
|
"""Return the volume level of the client (0..1)."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if (
|
|
|
|
self._is_player_active
|
|
|
|
and self.device
|
|
|
|
and "playback" in self._device_protocol_capabilities
|
|
|
|
):
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._volume_level
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_volume_muted(self):
|
|
|
|
"""Return boolean if volume is currently muted."""
|
2018-08-26 19:25:39 +00:00
|
|
|
if self._is_player_active and self.device:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._volume_muted
|
|
|
|
|
|
|
|
def mute_volume(self, mute):
|
|
|
|
"""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
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
if not (self.device and "playback" in self._device_protocol_capabilities):
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
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)
|
2016-08-08 15:55:58 +00:00
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
def media_play(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send play command."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.device and "playback" in self._device_protocol_capabilities:
|
2018-08-26 19:25:39 +00:00
|
|
|
self.device.play(self._active_media_plexapi_type)
|
2019-05-27 04:39:50 +00:00
|
|
|
self.update_devices()
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
def media_pause(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send pause command."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.device and "playback" in self._device_protocol_capabilities:
|
2018-08-26 19:25:39 +00:00
|
|
|
self.device.pause(self._active_media_plexapi_type)
|
2019-05-27 04:39:50 +00:00
|
|
|
self.update_devices()
|
2016-08-08 15:55:58 +00:00
|
|
|
|
|
|
|
def media_stop(self):
|
|
|
|
"""Send stop command."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.device and "playback" in self._device_protocol_capabilities:
|
2018-08-26 19:25:39 +00:00
|
|
|
self.device.stop(self._active_media_plexapi_type)
|
2019-05-27 04:39:50 +00:00
|
|
|
self.update_devices()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
def turn_off(self):
|
|
|
|
"""Turn the client off."""
|
|
|
|
# Fake it since we can't turn the client off
|
|
|
|
self.media_stop()
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
def media_next_track(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send next track command."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.device and "playback" in self._device_protocol_capabilities:
|
2018-08-26 19:25:39 +00:00
|
|
|
self.device.skipNext(self._active_media_plexapi_type)
|
2019-05-27 04:39:50 +00:00
|
|
|
self.update_devices()
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
def media_previous_track(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send previous track command."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.device and "playback" in self._device_protocol_capabilities:
|
2018-08-26 19:25:39 +00:00
|
|
|
self.device.skipPrevious(self._active_media_plexapi_type)
|
2019-05-27 04:39:50 +00:00
|
|
|
self.update_devices()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
def play_media(self, media_type, media_id, **kwargs):
|
|
|
|
"""Play a piece of media."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if not (self.device and "playback" in self._device_protocol_capabilities):
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
src = json.loads(media_id)
|
2019-10-07 04:02:58 +00:00
|
|
|
library = src.get("library_name")
|
|
|
|
shuffle = src.get("shuffle", 0)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
media = None
|
2019-10-07 04:02:58 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
if media_type == "MUSIC":
|
2019-10-07 04:02:58 +00:00
|
|
|
media = self._get_music_media(library, src)
|
2019-07-31 19:25:30 +00:00
|
|
|
elif media_type == "EPISODE":
|
2019-10-07 04:02:58 +00:00
|
|
|
media = self._get_tv_media(library, src)
|
2019-07-31 19:25:30 +00:00
|
|
|
elif media_type == "PLAYLIST":
|
2019-10-07 04:02:58 +00:00
|
|
|
media = self.plex_server.playlist(src["playlist_name"])
|
2019-07-31 19:25:30 +00:00
|
|
|
elif media_type == "VIDEO":
|
2019-10-07 04:02:58 +00:00
|
|
|
media = self.plex_server.library.section(library).get(src["video_name"])
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2019-10-07 04:02:58 +00:00
|
|
|
if media is None:
|
|
|
|
_LOGGER.error("Media could not be found: %s", media_id)
|
|
|
|
return
|
|
|
|
|
|
|
|
playqueue = self.plex_server.create_playqueue(media, shuffle=shuffle)
|
|
|
|
try:
|
|
|
|
self.device.playMedia(playqueue)
|
|
|
|
except ParseError:
|
|
|
|
# Temporary workaround for Plexamp / plexapi issue
|
|
|
|
pass
|
|
|
|
except requests.exceptions.ConnectTimeout:
|
|
|
|
_LOGGER.error("Timed out playing on %s", self.name)
|
|
|
|
|
|
|
|
self.update_devices()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2019-10-07 04:02:58 +00:00
|
|
|
def _get_music_media(self, library_name, src):
|
|
|
|
"""Find music media and return a Plex media object."""
|
|
|
|
artist_name = src["artist_name"]
|
|
|
|
album_name = src.get("album_name")
|
|
|
|
track_name = src.get("track_name")
|
|
|
|
track_number = src.get("track_number")
|
|
|
|
|
|
|
|
artist = self.plex_server.library.section(library_name).get(artist_name)
|
|
|
|
|
|
|
|
if album_name:
|
|
|
|
album = artist.album(album_name)
|
|
|
|
|
|
|
|
if track_name:
|
|
|
|
return album.track(track_name)
|
|
|
|
|
|
|
|
if track_number:
|
|
|
|
for track in album.tracks():
|
|
|
|
if int(track.index) == int(track_number):
|
|
|
|
return track
|
|
|
|
return None
|
|
|
|
|
|
|
|
return album
|
|
|
|
|
|
|
|
if track_name:
|
|
|
|
return artist.searchTracks(track_name, maxresults=1)
|
|
|
|
return artist
|
|
|
|
|
|
|
|
def _get_tv_media(self, library_name, src):
|
2017-04-01 02:19:04 +00:00
|
|
|
"""Find TV media and return a Plex media object."""
|
2019-10-07 04:02:58 +00:00
|
|
|
show_name = src["show_name"]
|
|
|
|
season_number = src.get("season_number")
|
|
|
|
episode_number = src.get("episode_number")
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
target_season = None
|
|
|
|
target_episode = None
|
|
|
|
|
2019-10-07 04:02:58 +00:00
|
|
|
show = self.plex_server.library.section(library_name).get(show_name)
|
2017-04-01 02:19:04 +00:00
|
|
|
|
|
|
|
if not season_number:
|
2019-10-07 04:02:58 +00:00
|
|
|
return show
|
2017-04-01 02:19:04 +00:00
|
|
|
|
|
|
|
for season in show.seasons():
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if int(season.seasonNumber) == int(season_number):
|
|
|
|
target_season = season
|
|
|
|
break
|
|
|
|
|
|
|
|
if target_season is None:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.error(
|
|
|
|
"Season not found: %s\\%s - S%sE%s",
|
|
|
|
library_name,
|
|
|
|
show_name,
|
|
|
|
str(season_number).zfill(2),
|
|
|
|
str(episode_number).zfill(2),
|
|
|
|
)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
else:
|
2017-04-01 02:19:04 +00:00
|
|
|
if not episode_number:
|
2019-10-07 04:02:58 +00:00
|
|
|
return target_season
|
2017-04-01 02:19:04 +00:00
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
for episode in target_season.episodes():
|
|
|
|
if int(episode.index) == int(episode_number):
|
|
|
|
target_episode = episode
|
|
|
|
break
|
|
|
|
|
|
|
|
if target_episode is None:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.error(
|
|
|
|
"Episode not found: %s\\%s - S%sE%s",
|
|
|
|
library_name,
|
|
|
|
show_name,
|
|
|
|
str(season_number).zfill(2),
|
|
|
|
str(episode_number).zfill(2),
|
|
|
|
)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
return target_episode
|
|
|
|
|
2017-04-01 02:19:04 +00:00
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the scene state attributes."""
|
2017-12-24 16:18:31 +00:00
|
|
|
attr = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"media_content_rating": self._media_content_rating,
|
|
|
|
"session_username": self._session_username,
|
|
|
|
"media_library_name": self._app_name,
|
2017-12-24 16:18:31 +00:00
|
|
|
}
|
2017-04-01 02:19:04 +00:00
|
|
|
|
|
|
|
return attr
|