From e161db7caba6c09141e74591e3f3159c1ac128f2 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Wed, 28 Oct 2020 14:29:23 +0100 Subject: [PATCH] Remove obsolte class. #43 #44 --- modules/core/state.py | 120 ------------------------------------------ 1 file changed, 120 deletions(-) delete mode 100644 modules/core/state.py diff --git a/modules/core/state.py b/modules/core/state.py deleted file mode 100644 index b06e13f6..00000000 --- a/modules/core/state.py +++ /dev/null @@ -1,120 +0,0 @@ -# -# Aura Engine (https://gitlab.servus.at/aura/engine) -# -# Copyright (C) 2017-2020 - The Aura Engine Team. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - - -import logging -from collections import deque - -from modules.base.exceptions import NoActiveEntryException -from modules.base.utils import SimpleUtil as SU -from modules.core.resources import ResourceClass, ResourceUtil - - - -class PlayerStateService: - """ - PlayerStateService keeps a short history of currently playing entries. It stores the recent - active entries to a local cache `entry_history` being able to manage concurrently playing entries. - - It also is in charge of resolving relevant meta information of the currently playing entry for - the TrackService plugin. - """ - - config = None - logger = None - entry_history = None - - - - def __init__(self, config): - """ - Constructor - - Args: - config (AuraConfig): Holds the engine configuration - """ - self.config = config - self.logger = logging.getLogger("AuraEngine") - self.entry_history = deque([None, None, None]) - - - # - # PUBLIC METHODS - # - - - def add_to_history(self, entries): - """ - Saves the currently pre-rolled [`Entry`] to the local cache. - """ - self.entry_history.pop() - self.entry_history.appendleft(entries) - - - def get_recent_entries(self): - """ - Retrieves the currently playing [`Entry`] from the local cache. - """ - return self.entry_history[0] - - - def resolve_entry(self, source): - """ - Retrieves the `PlaylistEntry` matching the provied source URI. - - Args: - source (String): The URI of the source playing - Raises: - (NoActiveEntryException) - """ - result = None - entries = self.get_recent_entries() - if not entries: - raise NoActiveEntryException - - for entry in entries: - entry_source = entry.source - - if entry.get_content_type() in ResourceClass.FILE.types: - base_dir = self.config.get("audio_source_folder") - extension = self.config.get("audio_source_extension") - entry_source = ResourceUtil.uri_to_filepath(base_dir, entry.source, extension) - if entry_source == source: - self.logger.info("Resolved '%s' entry '%s' for URI '%s'" % (entry.get_content_type(), entry, source)) - result = entry - break - - if not result: - msg = "Found no entry in the recent history which matches the given source '%s'" % (source) - self.logger.critical(SU.red(msg)) - - return result - - - def print_entry_history(self): - """ - Prints all recents entries of the history. - """ - msg = "Active entry history:\n" - for entries in self.entry_history: - msg += "[" - for e in entries: - msg += "\n" + str(e) - msg += "]" - self.logger.info(msg) - -- GitLab