Update Kodi to no longer use protected methods (#40788)

* Replace protected methods

* Fix method name

* Bump PyKodi version to 0.2.1

* Reuse variable
pull/41171/head
cgtobi 2020-10-03 22:12:18 +02:00 committed by GitHub
parent b281e85c80
commit f9f17dc718
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 53 deletions

View File

@ -67,95 +67,101 @@ async def build_item_response(media_library, payload):
title = None
media = None
query = {"properties": ["thumbnail"]}
# pylint: disable=protected-access
properties = ["thumbnail"]
if search_type == MEDIA_TYPE_ALBUM:
if search_id:
query.update({"filter": {"albumid": int(search_id)}})
query["properties"].extend(
["albumid", "artist", "duration", "album", "track"]
)
album = await media_library._server.AudioLibrary.GetAlbumDetails(
{"albumid": int(search_id), "properties": ["thumbnail"]}
album = await media_library.get_album_details(
album_id=int(search_id), properties=properties
)
thumbnail = media_library.thumbnail_url(
album["albumdetails"].get("thumbnail")
)
title = album["albumdetails"]["label"]
media = await media_library._server.AudioLibrary.GetSongs(query)
media = await media_library.get_songs(
album_id=int(search_id),
properties=[
"albumid",
"artist",
"duration",
"album",
"thumbnail",
"track",
],
)
media = media.get("songs")
else:
media = await media_library._server.AudioLibrary.GetAlbums(query)
media = await media_library.get_albums(properties=properties)
media = media.get("albums")
title = "Albums"
elif search_type == MEDIA_TYPE_ARTIST:
if search_id:
query.update({"filter": {"artistid": int(search_id)}})
media = await media_library._server.AudioLibrary.GetAlbums(query)
media = await media_library.get_albums(
artist_id=int(search_id), properties=properties
)
media = media.get("albums")
artist = await media_library._server.AudioLibrary.GetArtistDetails(
{"artistid": int(search_id), "properties": ["thumbnail"]}
artist = await media_library.get_artist_details(
artist_id=int(search_id), properties=properties
)
thumbnail = media_library.thumbnail_url(
artist["artistdetails"].get("thumbnail")
)
title = artist["artistdetails"]["label"]
else:
media = await media_library._server.AudioLibrary.GetArtists(query)
media = await media_library.get_artists(properties)
media = media.get("artists")
title = "Artists"
elif search_type == "library_music":
library = {MEDIA_TYPE_ALBUM: "Albums", MEDIA_TYPE_ARTIST: "Artists"}
media = [{"label": name, "type": type_} for type_, name in library.items()]
title = "Music Library"
elif search_type == MEDIA_TYPE_MOVIE:
media = await media_library._server.VideoLibrary.GetMovies(query)
media = await media_library.get_movies(properties)
media = media.get("movies")
title = "Movies"
elif search_type == MEDIA_TYPE_TVSHOW:
if search_id:
media = await media_library._server.VideoLibrary.GetSeasons(
{
"tvshowid": int(search_id),
"properties": ["thumbnail", "season", "tvshowid"],
}
media = await media_library.get_seasons(
tv_show_id=int(search_id),
properties=["thumbnail", "season", "tvshowid"],
)
media = media.get("seasons")
tvshow = await media_library._server.VideoLibrary.GetTVShowDetails(
{"tvshowid": int(search_id), "properties": ["thumbnail"]}
tvshow = await media_library.get_tv_show_details(
tv_show_id=int(search_id), properties=properties
)
thumbnail = media_library.thumbnail_url(
tvshow["tvshowdetails"].get("thumbnail")
)
title = tvshow["tvshowdetails"]["label"]
else:
media = await media_library._server.VideoLibrary.GetTVShows(query)
media = await media_library.get_tv_shows(properties)
media = media.get("tvshows")
title = "TV Shows"
elif search_type == MEDIA_TYPE_SEASON:
tv_show_id, season_id = search_id.split("/", 1)
media = await media_library._server.VideoLibrary.GetEpisodes(
{
"tvshowid": int(tv_show_id),
"season": int(season_id),
"properties": ["thumbnail", "tvshowid", "seasonid"],
}
media = await media_library.get_episodes(
tv_show_id=int(tv_show_id),
season_id=int(season_id),
properties=["thumbnail", "tvshowid", "seasonid"],
)
media = media.get("episodes")
if media:
season = await media_library._server.VideoLibrary.GetSeasonDetails(
{"seasonid": int(media[0]["seasonid"]), "properties": ["thumbnail"]}
season = await media_library.get_season_details(
season_id=int(media[0]["seasonid"]), properties=properties
)
thumbnail = media_library.thumbnail_url(
season["seasondetails"].get("thumbnail")
)
title = season["seasondetails"]["label"]
elif search_type == MEDIA_TYPE_CHANNEL:
media = await media_library._server.PVR.GetChannels(
{
"channelgroupid": "alltv",
"properties": ["thumbnail", "channeltype", "channel", "broadcastnow"],
}
media = await media_library.get_channels(
channel_group_id="alltv",
properties=["thumbnail", "channeltype", "channel", "broadcastnow"],
)
media = media.get("channels")
title = "Channels"

View File

@ -2,11 +2,15 @@
"domain": "kodi",
"name": "Kodi",
"documentation": "https://www.home-assistant.io/integrations/kodi",
"requirements": ["pykodi==0.2.0"],
"requirements": [
"pykodi==0.2.1"
],
"codeowners": [
"@OnFreund",
"@cgtobi"
],
"zeroconf": ["_xbmc-jsonrpc-h._tcp.local."],
"zeroconf": [
"_xbmc-jsonrpc-h._tcp.local."
],
"config_flow": true
}
}

View File

@ -677,17 +677,10 @@ class KodiEntity(MediaPlayerEntity):
elif media_type_lower in [
MEDIA_TYPE_ARTIST,
MEDIA_TYPE_ALBUM,
MEDIA_TYPE_TRACK,
]:
await self.async_clear_playlist()
params = {"playlistid": 0, "item": {f"{media_type}id": int(media_id)}}
# pylint: disable=protected-access
await self._kodi._server.Playlist.Add(params)
await self._kodi.play_playlist(0)
elif media_type_lower == MEDIA_TYPE_TRACK:
await self._kodi.clear_playlist()
params = {"playlistid": 0, "item": {"songid": int(media_id)}}
# pylint: disable=protected-access
await self._kodi._server.Playlist.Add(params)
await self.async_add_to_playlist(media_type_lower, media_id)
await self._kodi.play_playlist(0)
elif media_type_lower in [
MEDIA_TYPE_MOVIE,
@ -695,8 +688,7 @@ class KodiEntity(MediaPlayerEntity):
MEDIA_TYPE_SEASON,
MEDIA_TYPE_TVSHOW,
]:
# pylint: disable=protected-access
await self._kodi._play_item(
await self._kodi.play_item(
{MAP_KODI_MEDIA_TYPES[media_type_lower]: int(media_id)}
)
else:
@ -751,6 +743,15 @@ class KodiEntity(MediaPlayerEntity):
"""Clear default playlist (i.e. playlistid=0)."""
await self._kodi.clear_playlist()
async def async_add_to_playlist(self, media_type, media_id):
"""Add media item to default playlist (i.e. playlistid=0)."""
if media_type == MEDIA_TYPE_ARTIST:
await self._kodi.add_artist_to_playlist(int(media_id))
elif media_type == MEDIA_TYPE_ALBUM:
await self._kodi.add_album_to_playlist(int(media_id))
elif media_type == MEDIA_TYPE_TRACK:
await self._kodi.add_song_to_playlist(int(media_id))
async def async_add_media_to_playlist(
self, media_type, media_id=None, media_name="ALL", artist_name=""
):

View File

@ -1446,7 +1446,7 @@ pyitachip2ir==0.0.7
pykira==0.1.1
# homeassistant.components.kodi
pykodi==0.2.0
pykodi==0.2.1
# homeassistant.components.kwb
pykwb==0.0.8

View File

@ -704,7 +704,7 @@ pyisy==2.0.2
pykira==0.1.1
# homeassistant.components.kodi
pykodi==0.2.0
pykodi==0.2.1
# homeassistant.components.lastfm
pylast==3.3.0