mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Merge pull request #1195 from persandstrom/kodi_thumbnails
kodi thumbnails
This commit is contained in:
commit
b91e4cfb4a
@ -25,24 +25,22 @@ SUPPORT_KODI = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the kodi platform. """
|
||||
|
||||
url = '{}:{}'.format(config.get('host'), config.get('port', '8080'))
|
||||
|
||||
jsonrpc_url = config.get('url') # deprecated
|
||||
if jsonrpc_url:
|
||||
url = jsonrpc_url.rstrip('/jsonrpc')
|
||||
|
||||
add_devices([
|
||||
KodiDevice(
|
||||
config.get('name', 'Kodi'),
|
||||
config.get('url'),
|
||||
url,
|
||||
auth=(
|
||||
config.get('user', ''),
|
||||
config.get('password', ''))),
|
||||
])
|
||||
|
||||
|
||||
def _get_image_url(kodi_url):
|
||||
""" Helper function that parses the thumbnail URLs used by Kodi. """
|
||||
url_components = urllib.parse.urlparse(kodi_url)
|
||||
|
||||
if url_components.scheme == 'image':
|
||||
return urllib.parse.unquote(url_components.netloc)
|
||||
|
||||
|
||||
class KodiDevice(MediaPlayerDevice):
|
||||
""" Represents a XBMC/Kodi device. """
|
||||
|
||||
@ -52,12 +50,13 @@ class KodiDevice(MediaPlayerDevice):
|
||||
import jsonrpc_requests
|
||||
self._name = name
|
||||
self._url = url
|
||||
self._server = jsonrpc_requests.Server(url, auth=auth)
|
||||
self._server = jsonrpc_requests.Server(
|
||||
'{}/jsonrpc'.format(self._url),
|
||||
auth=auth)
|
||||
self._players = None
|
||||
self._properties = None
|
||||
self._item = None
|
||||
self._app_properties = None
|
||||
|
||||
self.update()
|
||||
|
||||
@property
|
||||
@ -155,7 +154,16 @@ class KodiDevice(MediaPlayerDevice):
|
||||
def media_image_url(self):
|
||||
""" Image url of current playing media. """
|
||||
if self._item is not None:
|
||||
return _get_image_url(self._item['thumbnail'])
|
||||
return self._get_image_url()
|
||||
|
||||
def _get_image_url(self):
|
||||
""" Helper function that parses the thumbnail URLs used by Kodi. """
|
||||
url_components = urllib.parse.urlparse(self._item['thumbnail'])
|
||||
|
||||
if url_components.scheme == 'image':
|
||||
return '{}/image/{}'.format(
|
||||
self._url,
|
||||
urllib.parse.quote_plus(self._item['thumbnail']))
|
||||
|
||||
@property
|
||||
def media_title(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user