Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions pykodi/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jsonrpc_base
import jsonrpc_async
import jsonrpc_websocket
from rapidfuzz import fuzz, process, utils


def get_kodi_connection(
Expand Down Expand Up @@ -411,6 +412,37 @@ async def get_players(self):
"""Return the active player objects."""
return await self._server.Player.GetActivePlayers()

async def search_media(self, media_type, search_query=None, score_cutoff=80, **kwargs):
""" Filter the original result by the search query. """
result = None
match media_type:
case 'movies':
result = await self.get_movies(**kwargs)
case 'tvshows':
result = await self.get_tv_shows(**kwargs)
case 'episodes':
result = await self.get_episodes(**kwargs)
case _:
return []

media = result.get(media_type, [])

if search_query is None:
return media

media_labels = [i["label"] for i in media]
matching_media_indices = process.extract(
search_query,
media_labels,
scorer=fuzz.WRatio,
processor=utils.default_process,
score_cutoff=score_cutoff
)

filtered_media = [{**media[idx], 'fuzz_score':fuzz_score} for (label, fuzz_score, idx) in matching_media_indices]

return filtered_media

async def send_notification(self, title, message, icon="info", displaytime=10000):
"""Display on-screen message."""
await self._server.GUI.ShowNotification(title, message, icon, displaytime)
Expand Down