def update_viewed(media_id, elapsed=None, delete=False): try: database = Database() try: info = database.select_media(int(media_id)) except Exception: info = {} if info.get("category") in config.getlist("viewed", "no_history"): return "0" if elapsed: database.update_viewed(media_id, elapsed) elif delete: database.delete_viewed(media_id) else: database.insert_viewed(media_id) return "0" except Exception as excp: log.error("Update viewed failed: %s", excp) return "1"