From 27fbe87851b6ab1a04cbf45ae289ecd3c695bd0b Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Mon, 15 Feb 2021 10:38:04 -0500 Subject: [PATCH] get_media_and_device and find_replace fixes --- .../plex_assistant/process_speech.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/custom_components/plex_assistant/process_speech.py b/custom_components/plex_assistant/process_speech.py index 4f19fe1..58736ce 100644 --- a/custom_components/plex_assistant/process_speech.py +++ b/custom_components/plex_assistant/process_speech.py @@ -106,33 +106,36 @@ def get_media_and_device(self): self.device = self.is_device(self.library["movie_titles"] + self.library["show_titles"], separator) if self.device: split = self.command.split(separator) - media = self.command.replace(separator + split[-1], "") + self.command = self.command.replace(separator + split[-1], "") self.device = split[-1] - self.media = media or self.command + self.find_replace("shows") + self.find_replace("movies") + self.media = self.command def find_replace(self, item, replace=True, replacement=""): item = self.localize[item] - if isinstance(item, str) and item in self.command: + if isinstance(item, str): item = {"keywords": [item]} - elif isinstance(item, list) and any(keyword in self.command for keyword in item): + elif isinstance(item, list): item = {"keywords": item} - if not isinstance(item, dict) or all(keyword not in self.command for keyword in item["keywords"]): + if all(keyword not in self.command for keyword in item["keywords"]): return False if replace: - self.command = f" {self.command} " if replacement: replacement = f" {replacement} " for keyword in item["keywords"]: + self.command = f" {self.command} " for pre in item.get("pre", []): self.command = self.command.replace(f"{pre} {keyword}", replacement) for post in item.get("post", []): self.command = self.command.replace(f"{keyword} {post}", replacement) if keyword in self.command: self.command = self.command.replace(f" {keyword} ", replacement) + self.command = self.command.strip() self.command = " ".join(self.command.split()) return True