Skip to content
Snippets Groups Projects
Commit e161db7c authored by David Trattnig's avatar David Trattnig
Browse files

Remove obsolte class. #43 #44

parent 462d707c
No related branches found
No related tags found
No related merge requests found
#
# 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment