Skip to content
Snippets Groups Projects
in_stream.liq 4.20 KiB
#
# 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/>.


# Pre-population of stream input sources, as Liquidsoap needs it to initialize this input.
# This is overwritten as soon as some other Stream is scheduled.
# #TODO Check if this is still required for Liquidsoap 2



#####################################
#             SOURCES               #
#####################################

# STREAM 1
input_http_0 = input.http(
    id="in_http_0",
    max_buffer=input_stream_max_buffer,
    timeout=input_stream_timeout,
    start=false,
    ""
)

# Enable metadata insertion and store callbacks
input_http_0 = insert_metadata(id="in_http_0", input_http_0)
in_stream_insert_meta_0 = input_http_0.insert_metadata
in_stream_last_meta_0 = input_http_0.last_metadata

# Map metadata
def on_stream_meta_0(meta) =
    lm = (in_stream_last_meta_0() ?? [])
    merge_meta(lm, meta)
end
input_http_0 = metadata.map(id="in_http_0", on_stream_meta_0, input_http_0)

# Old Liquidsoap approach:
# input_http_0.on_metadata(on_metadata_notification)

# New Liquidsoap 2.1 approach, which should not trigger when inactive,
# but actually does trigger before stream is ready:
input_http_0 = source.on_metadata(id="in_http_0", input_http_0, on_metadata_notification)

#####################################

# STREAM 2
input_http_1 = input.http(
    id="in_http_1",
    max_buffer=input_stream_max_buffer,
    timeout=input_stream_timeout,
    start=false,
    ""
)

# Enable metadata insertion and store callbacks
input_http_1 = insert_metadata(id="in_http_1", input_http_1)
in_stream_insert_meta_1 = input_http_1.insert_metadata
in_stream_last_meta_1 = input_http_1.last_metadata

# Old approach:
# input_http_1.on_metadata(on_metadata_notification)

# New Liquidsoap 2.1 approach, which should not trigger when inactive,
# but actually does trigger before stream is ready:
input_http_1 = source.on_metadata(id="in_http_1", input_http_1, on_metadata_notification)


#####################################
#          SERVER FUNCTIONS         #
#####################################

usage_set_track_metadata = "set_track_metadata { \
        \"show_name\": \"Laser Music 2000\", \
        \"show_id\": 123, \
        \"timeslot_id\": 123, \
        \"playlist_id\": 123, \
        \"playlist_item\": \"\", \
        \"track_type\": 1, \
        \"track_start\": \"2022/02/22 22:02:22\", \
        \"track_duration\": 303, \
        \"track_title\": \"Bar\", \
        \"track_album\": \"\", \
        \"track_artist\": \"Foo\" \
    }"

# Set current track metadata for "input_http_0"
server.register(namespace=source.id(input_http_0),
    description="Sets the current track metadata for a channel",
    usage=usage_set_track_metadata,
    "set_track_metadata",

    fun (json_string) -> begin
        log("Received JSON to set track metadata on channel \
            '#{source.id(input_http_0)}' to:\n #{json_string}")
        metadata = build_metadata(json_string)
        do_meta_insert(in_stream_last_meta_0, in_stream_insert_meta_0, metadata)
        "OK"
    end
)

# Set current track metadata for "input_http_1"
server.register(namespace=source.id(input_http_1),
    description="Sets the current track metadata for a channel",
    usage=usage_set_track_metadata,
    "set_track_metadata",

    fun (json_string) -> begin
        log("Received JSON to set track metadata on channel \
            '#{source.id(input_http_1)}' to:\n #{json_string}")
        metadata = build_metadata(json_string)
        do_meta_insert(in_stream_last_meta_1, in_stream_insert_meta_1, metadata)
        "OK"
    end
)