def notify(body, title=APP_NAME, timeout=5, stdout=False, category="misc"): if stdout: print(body) if category not in enabled_categories: return if sys.platform == 'win32': toaster.show_toast(title, body, duration=timeout, threaded=True) elif sys.platform == 'darwin': osa_cmd = f'display notification "{body}" with title "{title}"' sp.run(["osascript", "-e", osa_cmd], check=False) elif notifier is not None: dbus_notify(title, body, timeout * 1000) else: try: sp.run([ "notify-send", "-a", title, "-i", 'dialog-information', "-t", str(timeout * 1000), title, body ], check=False) except FileNotFoundError: logger.exception("Unable to send notification") # disable all future notifications until app restart enabled_categories.clear()
def __init__(self, scrobble_queue): try: self.URL = self.URL.format(**self.config) except KeyError: logger.exception(f'Check config for correct {self.name} params.') return super().__init__(scrobble_queue)
def update_status(self): try: return self._update_status() except KeyError: logger.exception("Weird key error in plex. Resetting status.") self.status = {} return
def __new__(cls, *args, **kwargs): try: cls.config = cls.autoload_cfg() except AutoloadError as e: logger.debug(str(e)) logger.error(f"Config value autoload failed for {cls.name}.") except Exception: logger.exception(f"Config value autoload failed for {cls.name}.") else: return super().__new__(cls)
def __init__(self, scrobble_queue): try: web_pwd = self.config['password'] self.URL = self.URL.format(**self.config) except KeyError: logger.exception('Check config for correct VLC params.') return super().__init__(scrobble_queue) self.sess.auth = ('', web_pwd) self.status_url = self.URL + '/requests/status.json' self.playlist_url = self.URL + '/requests/playlist.json'
def use_guessit(file_path: str): try: return guessit.guessit(file_path) except guessit.api.GuessitException: # lazy import the notifier module # This codepath will not be executed 99.99% of the time, and importing notify # in the outer scope is expensive due to the categories parsing # It is unneeded when using the "trakts whitelist" command from trakt_scrobbler.notifier import notify logger.exception("Encountered guessit error.") notify("Encountered guessit error. File a bug report!", category="exception") return {}
def __init__(self, scrobble_queue): try: self.ipc_path = self.config['ipc_path'] except KeyError: logger.exception('Check config for correct MPV params.') return super().__init__(scrobble_queue) self.buffer = '' self.lock = threading.Lock() self.poll_timer = None self.write_queue = Queue() self.sent_commands = {} self.command_counter = 1 self.vars = {}
def __new__(cls, *args, **kwargs): try: cls.inject_base_config() cls.config = cls.autoload_cfg() except AutoloadError as e: logger.debug(str(e)) logger.error(f"Config value autoload failed for {cls.name}.") notify(f"Check log file. {e!s}", category="exception") except Exception: msg = f"Config value autoload failed for {cls.name}." logger.exception(msg) notify(f"{msg} Check log file.", category="exception") else: return super().__new__(cls)
def __init__(self, scrobble_queue): try: self.token = get_token() self.URL = self.URL.format(**self.config) except KeyError: logger.exception("Check config for correct Plex params.") return if not self.token: logger.error("Unable to retrieve plex token.") return super().__init__(scrobble_queue) self.sess.headers["Accept"] = "application/json" self.sess.headers["X-Plex-Token"] = self.token self.session_url = self.URL + "/status/sessions" self.media_info_cache = {}
def notify(body, title=APP_NAME, timeout=5, stdout=False): global enable_notifs if stdout or not enable_notifs: print(body) if not enable_notifs: return if sys.platform == 'win32': toaster.show_toast(title, body, duration=timeout, threaded=True) elif sys.platform == 'darwin': osa_cmd = f'display notification "{body}" with title "{title}"' sp.run(["osascript", "-e", osa_cmd]) else: try: sp.run( ["notify-send", "-a", title, "-t", str(timeout * 1000), body]) except FileNotFoundError: logger.exception("Unable to send notification") enable_notifs = False # disable all future notifications until app restart
def get_data(self, url): resp = safe_request("get", {"url": url}, self.sess) if resp is None: return # TODO: If we get a 401, clear token and restart plex auth flow resp.raise_for_status() try: data = resp.json()["MediaContainer"] except JSONDecodeError: logger.exception("Error with decoding") logger.debug(resp.text) return None if data["size"] <= 0: return None # no user filter if not self.config["scrobble_user"] or "User" not in data["Metadata"][ 0]: return data["Metadata"][0] for metadata in data["Metadata"]: if metadata["User"]["title"] == self.config["scrobble_user"]: return metadata
def error_logger(*exc_info): logger.exception('Unhandled exception', exc_info=exc_info)