diff --git a/libraries/database/broadcasts.py b/libraries/database/broadcasts.py index 1f6aad43471bad93286f6380cb8df7e84cf41271..d3de8a6e2d3ea5e5f0fdbdc4091e2c5f08b4f6ae 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 c8ab8cbaf5dd6c88ea4b424523661282a1fdaf53..6d563e8cec6b96972b6f25b1704abbe3e062abdb 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 90a4c7f411453915c7c69bc11994f68810d5b6a0..832af4d3a7ce5bc68ce3fc0d83cf203bb9f26abd 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. """