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

Moved to specific classes. #44

parent 711f09ac
No related branches found
No related tags found
No related merge requests found
......@@ -21,123 +21,8 @@ import datetime
import time
from enum import Enum
from modules.core.channels import ChannelType
from modules.scheduling.types import PlaylistType
class EngineUtil:
"""
A class for Engine utilities.
"""
@staticmethod
def get_channel_type(uri):
"""
Returns the channel type, depending on the passed URI and source.
Args:
uri (String): The URI of the source
"""
if uri.startswith("https"):
return ChannelType.HTTPS
if uri.startswith("http"):
return ChannelType.HTTP
if uri.startswith("pool") or uri.startswith("playlist") or uri.startswith("file"):
return ChannelType.FILESYSTEM
if uri.startswith("line://"):
return ChannelType.LIVE
@staticmethod
def uri_to_filepath(base_dir, uri):
"""
Converts a file-system URI to an actual, absolute path to the file.
Args:
basi_dir (String): The location of the audio store.
uri (String): The URI of the file
Returns:
path (String): Absolute file path
"""
return base_dir + "/" + uri[7:] + ".flac"
@staticmethod
def get_playlist_type(fallback_id):
"""
Converts an playlist type ID to the playlist type object.
Args:
id (String): playlist type ID
Returns:
type (PlaylistType): The type
"""
if fallback_id == 0:
return PlaylistType.DEFAULT
elif fallback_id == 1:
return PlaylistType.SHOW
elif fallback_id == 2:
return PlaylistType.TIMESLOT
else:
return PlaylistType.STATION
@staticmethod
def get_entries_string(entries):
"""
Returns a list of entries as String for logging purposes.
"""
s = ""
if isinstance(entries, list):
for entry in entries:
s += str(entry)
if entry != entries[-1]: s += ", "
else:
s = str(entries)
return s
@staticmethod
def lqs_annotate_cuein(uri, cue_in):
"""
Wraps the given URI with a Liquidsoap Cue In annotation.
Args:
uri (String): The path to the audio source
cue_in (Float): The value in seconds wher the cue in should start
Returns:
(String): The annotated URI
"""
if cue_in > 0.0:
uri = "annotate:liq_cue_in=\"%s\":%s" % (str(cue_in), uri)
return uri
@staticmethod
def engine_info(component, version):
"""
Prints the engine logo and version info.
"""
return """\n
█████╗ ██╗ ██╗██████╗ █████╗ ███████╗███╗ ██╗ ██████╗ ██╗███╗ ██╗███████╗
██╔══██╗██║ ██║██╔══██╗██╔══██╗ ██╔════╝████╗ ██║██╔════╝ ██║████╗ ██║██╔════╝
███████║██║ ██║██████╔╝███████║ █████╗ ██╔██╗ ██║██║ ███╗██║██╔██╗ ██║█████╗
██╔══██║██║ ██║██╔══██╗██╔══██║ ██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██╔══╝
██║ ██║╚██████╔╝██║ ██║██║ ██║ ███████╗██║ ╚████║╚██████╔╝██║██║ ╚████║███████╗
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝
%s v%s - Ready to play!
\n""" % (component, version)
class SimpleUtil:
"""
......
#
# 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/>.
from enum import Enum
class PlaylistType(Enum):
"""
Types of playlists.
"""
DEFAULT = { "id": 0, "name": "default" } # Default play mode
SHOW = { "id": 1, "name": "show" } # The first played when some default playlist fails
TIMESLOT = { "id": 2, "name": "timeslot" } # The second played when the timeslot fallback fails
STATION = { "id": 3, "name": "station" } # The last played when everything else fails
@property
def id(self):
return self.value["id"]
def __str__(self):
return str(self.value["name"])
# class TimerType(Enum):
# """
# Types of queue timers.
# """
# SWITCH = "switch"
# FADEIN = "fadein"
# FADEOUT = "fadeout"
class EntryQueueState(Enum):
"""
Types of playlist entrie behaviours.
"""
OKAY = "ok"
CUT = "cut"
OUT_OF_SCHEDULE = "oos"
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