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

* Replace protected methods

* Fix method name

* Bump PyKodi version to 0.2.1

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

View File

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

View File

@ -677,17 +677,10 @@ class KodiEntity(MediaPlayerEntity):
elif media_type_lower in [ elif media_type_lower in [
MEDIA_TYPE_ARTIST, MEDIA_TYPE_ARTIST,
MEDIA_TYPE_ALBUM, MEDIA_TYPE_ALBUM,
MEDIA_TYPE_TRACK,
]: ]:
await self.async_clear_playlist() await self.async_clear_playlist()
params = {"playlistid": 0, "item": {f"{media_type}id": int(media_id)}} await self.async_add_to_playlist(media_type_lower, 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._kodi.play_playlist(0) await self._kodi.play_playlist(0)
elif media_type_lower in [ elif media_type_lower in [
MEDIA_TYPE_MOVIE, MEDIA_TYPE_MOVIE,
@ -695,8 +688,7 @@ class KodiEntity(MediaPlayerEntity):
MEDIA_TYPE_SEASON, MEDIA_TYPE_SEASON,
MEDIA_TYPE_TVSHOW, 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)} {MAP_KODI_MEDIA_TYPES[media_type_lower]: int(media_id)}
) )
else: else:
@ -751,6 +743,15 @@ class KodiEntity(MediaPlayerEntity):
"""Clear default playlist (i.e. playlistid=0).""" """Clear default playlist (i.e. playlistid=0)."""
await self._kodi.clear_playlist() 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( async def async_add_media_to_playlist(
self, media_type, media_id=None, media_name="ALL", artist_name="" 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 pykira==0.1.1
# homeassistant.components.kodi # homeassistant.components.kodi
pykodi==0.2.0 pykodi==0.2.1
# homeassistant.components.kwb # homeassistant.components.kwb
pykwb==0.0.8 pykwb==0.0.8

View File

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