Generate new op25.liq each time we change the config + mini fixes
This commit is contained in:
34
app/internal/liquidsoap_config_utils.py
Normal file
34
app/internal/liquidsoap_config_utils.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
from internal.op25.liq_template import liquidsoap_config_template
|
||||
from models import IcecastConfig
|
||||
|
||||
def generate_liquid_script(config: IcecastConfig):
|
||||
"""
|
||||
Generates the "*.liq" file that's run by OP25 on startup.
|
||||
|
||||
Placeholders in the template must be formatted as ${VARIABLE_NAME}.
|
||||
|
||||
Args:
|
||||
config (dict): A dictionary of key-value pairs for substitution.
|
||||
Keys should match the variable names in the template (e.g., 'icecast_host').
|
||||
"""
|
||||
try:
|
||||
content = liquidsoap_config_template
|
||||
# Replace variables
|
||||
for key, value in config.items():
|
||||
placeholder = f"${{{key}}}"
|
||||
# Ensure the value is converted to string for replacement
|
||||
content = content.replace(placeholder, str(value))
|
||||
print(f" - Replaced placeholder {placeholder}")
|
||||
|
||||
# Write the processed content to the output path
|
||||
output_path = "/op25/op25/gr-op25_repeater/apps/op25.liq"
|
||||
with open(output_path, 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
print(f"\nSuccessfully wrote processed configuration to: {output_path}")
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Error: Template file not found at {template_path}")
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred: {e}")
|
||||
48
app/internal/op25.liq_template.py
Normal file
48
app/internal/op25.liq_template.py
Normal file
@@ -0,0 +1,48 @@
|
||||
liquidsoap_config_template = """#!/usr/bin/liquidsoap
|
||||
|
||||
# Example liquidsoap streaming from op25 to icecast
|
||||
# (c) 2019-2021 gnorbury@bondcar.com, wllmbecks@gmail.com
|
||||
#
|
||||
|
||||
set("log.stdout", true)
|
||||
set("log.file", false)
|
||||
set("log.level", 1)
|
||||
|
||||
# Make the native sample rate compatible with op25
|
||||
set("frame.audio.samplerate", 8000)
|
||||
set("init.allow_root", true)
|
||||
|
||||
# ==========================================================
|
||||
ICE_HOST = "${icecast_host}"
|
||||
ICE_PORT = ${icecast_port}
|
||||
ICE_MOUNT = "${icecast_mountpoint}"
|
||||
ICE_PASSWORD = "${icecast_password}"
|
||||
ICE_DESCRIPTION = "${icecast_description}"
|
||||
ICE_GENRE = "${icecast_genre}"
|
||||
# ==========================================================
|
||||
|
||||
input = mksafe(input.external(buffer=0.25, channels=2, samplerate=8000, restart_on_error=false, "./audio.py -x 2.5 -s"))
|
||||
# Consider increasing the buffer value on slow systems such as RPi3. e.g. buffer=0.25
|
||||
|
||||
# Compression
|
||||
input = compress(input, attack = 2.0, gain = 0.0, knee = 13.0, ratio = 2.0, release = 12.3, threshold = -18.0)
|
||||
|
||||
# Normalization
|
||||
input = normalize(input, gain_max = 6.0, gain_min = -6.0, target = -16.0, threshold = -65.0)
|
||||
|
||||
# ==========================================================
|
||||
# OUTPUT: Referencing the new variables
|
||||
# ==========================================================
|
||||
output.icecast(
|
||||
%mp3(bitrate=16, samplerate=22050, stereo=false),
|
||||
description=ICE_DESCRIPTION,
|
||||
genre=ICE_GENRE,
|
||||
url="",
|
||||
fallible=false,
|
||||
host=ICE_HOST,
|
||||
port=ICE_PORT,
|
||||
mount=ICE_MOUNT,
|
||||
password=ICE_PASSWORD,
|
||||
mean(input)
|
||||
)
|
||||
"""
|
||||
@@ -17,7 +17,7 @@ def save_talkgroup_tags(talkgroup_tags: List[TalkgroupTag]) -> None:
|
||||
writer = csv.writer(file, delimiter='\t', lineterminator='\n')
|
||||
# Write rows
|
||||
for tag in talkgroup_tags:
|
||||
writer.writerow([tag.talkgroup, tag.tagDec])
|
||||
writer.writerow([tag.tagDec, tag.talkgroup])
|
||||
|
||||
def save_whitelist(talkgroup_tags: List[int]) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user