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

Test: Cases on ID and metadata triggering

parent 709cd4a8
Branches
Tags
1 merge request!3Liquidsoap 2 migration
#!/usr/bin/env liquidsoap
#
# Aura Engine (https://gitlab.servus.at/aura/engine)
#
# Copyright (C) 2017-now() - 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/>.
%include "base_config.liq"
url = "https://orf-live.ors-shoutcast.at/oe1-q2a"
input_stream = input.http(id="input_stream", url, start=true)
def handle_meta1(meta) =
print("Called metadata handler1 and got: #{meta}")
end
def handle_meta2(meta) =
print("Called metadata handler2 and got: #{meta}")
end
### SOURCE ID ###
# Test retrieving ID via getter
id = input_stream.id()
print("Source ID: #{id}")
assertEquals(id, "input_stream")
# Test retrieving ID via `source.id`
id = source.id(input_stream)
print("Source ID: #{id}")
assertEquals(id, "input_stream")
### ON_METADATA ###
# Two variants of metadata event handling
# See https://github.com/savonet/liquidsoap/discussions/2509
# Variant A.) Attach `on_metadata` handler directly: handlers registered
# directly using the source method will be called whenever the source is being consumed
input_stream.on_metadata(handle_meta1)
print("Source ID: #{input_stream.id()}")
assertEquals(id, "input_stream")
# Variant B.) Source returned by `on_metadata`: Handlers are only called
# when the returned source is being used
input_stream = source.on_metadata(id="input_stream", input_stream, handle_meta2)
print("Source ID: #{input_stream.id()}")
assertEquals(id, "input_stream")
# IMPORTANT: If this is commented out, only "handle_meta1" will be called
output.alsa(device="default", mksafe(mixer), bufferize=true)
# The same is true for a mixer i.e. when the source is not selected/not audible:
# mixer = mix(id="mixer", [input_stream])
# output.alsa(device="default", mksafe(mixer), bufferize=true)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment