From cc55b1fb4f0d6b44bdab6731dc43a30f0fe10056 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Sat, 21 Mar 2020 08:30:20 +0100 Subject: [PATCH] Channel and ChannelType handling. --- libraries/database/broadcasts.py | 59 +++++++++++++----------------- libraries/enum/auraenumerations.py | 17 ++++++++- modules/base/simpleutil.py | 40 +++++++++++++++++++- 3 files changed, 80 insertions(+), 36 deletions(-) diff --git a/libraries/database/broadcasts.py b/libraries/database/broadcasts.py index 1f6aad43..d3de8a6e 100644 --- a/libraries/database/broadcasts.py +++ b/libraries/database/broadcasts.py @@ -38,9 +38,9 @@ from sqlalchemy.orm import relationship from sqlalchemy import create_engine -from libraries.enum.auraenumerations import ScheduleEntryType +from libraries.enum.auraenumerations import Channel, ChannelType from modules.base.config import AuraConfig -from modules.base.simpleutil import SimpleUtil +from modules.base.simpleutil import SimpleUtil, EngineUtil # Init Config @@ -462,23 +462,19 @@ class PlaylistEntry(DB.Model, AuraDatabaseModel): @hybrid_property def type(self): - if self.uri.startswith("http"): - return ScheduleEntryType.STREAM - if self.uri.startswith("pool") or self.uri.startswith("playlist") or self.uri.startswith("file"): - return ScheduleEntryType.FILESYSTEM - if self.uri.startswith("live") or self.uri.startswith("linein"): - if self.cleansource == "0": - return ScheduleEntryType.LIVE_0 - elif self.cleansource == "1": - return ScheduleEntryType.LIVE_1 - elif self.cleansource == "2": - return ScheduleEntryType.LIVE_2 - elif self.cleansource == "3": - return ScheduleEntryType.LIVE_3 - elif self.cleansource == "4": - return ScheduleEntryType.LIVE_4 - + return EngineUtil.get_channel_type(self.uri) + @hybrid_property + def channel(self): + type = EngineUtil.get_channel_type(self.uri) + if type == ChannelType.FILESYSTEM: + return Channel.FILESYSTEM_A + elif type == ChannelType.STREAM: + return Channel.STREAM_A + else: + return "foo:bar" + #FIXME Extend & finalize!! + def get_prev_entries(self): """ Retrieves all previous entries as part of the current entry's playlist. @@ -754,21 +750,18 @@ class SingleEntry(DB.Model, AuraDatabaseModel): @hybrid_property def type(self): - if self.uri.startswith("http"): - return ScheduleEntryType.STREAM - if self.uri.startswith("pool") or self.uri.startswith("playlist") or self.uri.startswith("file"): - return ScheduleEntryType.FILESYSTEM - if self.uri.startswith("live") or self.uri.startswith("linein"): - if self.cleansource == "0": - return ScheduleEntryType.LIVE_0 - elif self.cleansource == "1": - return ScheduleEntryType.LIVE_1 - elif self.cleansource == "2": - return ScheduleEntryType.LIVE_2 - elif self.cleansource == "3": - return ScheduleEntryType.LIVE_3 - elif self.cleansource == "4": - return ScheduleEntryType.LIVE_4 + return EngineUtil.get_channel_type(self.uri) + + @hybrid_property + def channel(self): + type = EngineUtil.get_channel_type(self.uri) + if type == ChannelType.FILESYSTEM: + return Channel.FILESYSTEM_A + elif type == ChannelType.STREAM: + return Channel.STREAM_A + else: + return "foo:bar" + #FIXME Extend & finalize!! def as_dict(self): diff --git a/libraries/enum/auraenumerations.py b/libraries/enum/auraenumerations.py index c8ab8cba..6d563e8c 100644 --- a/libraries/enum/auraenumerations.py +++ b/libraries/enum/auraenumerations.py @@ -61,10 +61,23 @@ class RedisChannel(Enum): SNF_REPLY = "get_next_file_reply" -class ScheduleEntryType(Enum): - # enumeration with names of liquidsoap inputs +class ChannelType(Enum): + """ + Engine channel types mapped to `Entry` source types. + """ FILESYSTEM = "fs" STREAM = "http" + LIVE = "live" + + +class Channel(Enum): + """ + Channel name mappings to the Liqidsoap channel IDs + """ + FILESYSTEM_A = "in_filesystem_0" + FILESYSTEM_B = "in_filesystem_1" + STREAM_A = "http_1" + STREAM_B = "http_2" LIVE_0 = "aura_linein_0" LIVE_1 = "aura_linein_1" LIVE_2 = "aura_linein_2" diff --git a/modules/base/simpleutil.py b/modules/base/simpleutil.py index 90a4c7f4..832af4d3 100644 --- a/modules/base/simpleutil.py +++ b/modules/base/simpleutil.py @@ -33,11 +33,49 @@ __author__ = 'David Trattnig <david.trattnig@subsquare.at>' import datetime import time +from libraries.enum.auraenumerations import Channel, ChannelType + + + +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("http"): + return ChannelType.STREAM + if uri.startswith("pool") or uri.startswith("playlist") or uri.startswith("file"): + return ChannelType.FILESYSTEM + if uri.startswith("live") or uri.startswith("linein"): + return ChannelType.LIVE + + # FIXME Mix of channels and channel-types!!! + # if source == "0": + # return Channel.LIVE_0 + # elif source == "1": + # return Channel.LIVE_1 + # elif source == "2": + # return Channel.LIVE_2 + # elif source == "3": + # return Channel.LIVE_3 + # elif source == "4": + # return Channel.LIVE_4 + class SimpleUtil: """ - A container for simple utility methods. + A container class for simple utility methods. """ -- GitLab