From 7db22135c601ca13e90b040aef98d7c9605485d8 Mon Sep 17 00:00:00 2001
From: Loxbie <ole@freirad.at>
Date: Mon, 5 Aug 2024 12:13:52 +0200
Subject: [PATCH] Chore: replace old configs with new yaml config object

---
 src/events.liq          |  5 ++---
 src/functions.liq       | 11 +++++++----
 src/in_stream.liq       |  9 ++++-----
 src/out_stream.liq      |  2 +-
 src/serverfunctions.liq |  6 ------
 src/settings.liq        | 20 +++-----------------
 6 files changed, 17 insertions(+), 36 deletions(-)

diff --git a/src/events.liq b/src/events.liq
index 728d6a0..9f5c160 100644
--- a/src/events.liq
+++ b/src/events.liq
@@ -67,7 +67,7 @@ def on_metadata_notification(meta) =
       ("track_album", track_album),
       ("track_artist", track_artist),
       ("track_num", playlist_track_num),
-      ("log_source", engine_id)
+      ("log_source", config.general.engine_id)
     ]
   if
     playlog["show_id"] == ""
@@ -78,7 +78,6 @@ def on_metadata_notification(meta) =
       "Skip posting playlog because of missing show ID!"
     )
   else
-    # FIXME: should we run this in a thread? Because if this breaks, the playout stops
-    post_playlog(engine_api_playlog, playlog)
+    thread.run({post_playlog(config.general.api_url_playlog, playlog)})
   end
 end
diff --git a/src/functions.liq b/src/functions.liq
index 571f58e..2b53382 100644
--- a/src/functions.liq
+++ b/src/functions.liq
@@ -60,12 +60,13 @@ end
 
 # Checks for the existence of show-specific metadata
 def has_show_meta(meta) =
-  list.assoc.mem(engine_meta_key_show_id, meta) ? true : false
+  list.assoc.mem(config.general.meta_key_show_id, meta) ? true : false
 end
 
 # Checks if the show ID in two metadata objects matches
 def is_same_show(last_meta, current_meta) =
-  last_meta[engine_meta_key_show_id] == current_meta[engine_meta_key_show_id]
+  last_meta[config.general.meta_key_show_id] ==
+    current_meta[config.general.meta_key_show_id]
   ? true : false
 end
 
@@ -266,7 +267,9 @@ def eval_track_type(meta_track_type, meta_source) =
     ]
 
   track_type =
-    list.assoc(default=engine_default_track_type, meta_source, type_mapping)
+    list.assoc(
+      default=config.general.default_track_type, meta_source, type_mapping
+    )
 
   if
     meta_track_type != ""
@@ -274,6 +277,6 @@ def eval_track_type(meta_track_type, meta_source) =
     meta_track_type
   elsif track_type != "" then track_type
   else
-    engine_default_track_type
+    config.general.default_track_type
   end
 end
diff --git a/src/in_stream.liq b/src/in_stream.liq
index 2140df2..e514d6a 100644
--- a/src/in_stream.liq
+++ b/src/in_stream.liq
@@ -18,7 +18,6 @@
 
 # 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               #
@@ -28,8 +27,8 @@
 input_stream_0 =
   input.http(
     id="in_stream_0",
-    max_buffer=input_stream_max_buffer,
-    timeout=input_stream_timeout,
+    max_buffer=config.general.input_stream_max_buffer,
+    timeout=config.general.input_stream_timeout,
     start=false,
     ""
   )
@@ -57,8 +56,8 @@ input_stream_0 =
 input_stream_1 =
   input.http(
     id="in_stream_1",
-    max_buffer=input_stream_max_buffer,
-    timeout=input_stream_timeout,
+    max_buffer=config.general.input_stream_max_buffer,
+    timeout=config.general.input_stream_timeout,
     start=false,
     ""
   )
diff --git a/src/out_stream.liq b/src/out_stream.liq
index 97dee8d..a76feb1 100644
--- a/src/out_stream.liq
+++ b/src/out_stream.liq
@@ -47,7 +47,7 @@ def create_stream(stream) =
     )
   end
 
-  # FIXME: make enc more flexible, read bitrate etc from settings
+  # TODO: make enc more flexible, read bitrate etc from settings
   enc = ref(%vorbis(stereo = true))
 
   # set icy_metadata according to the encoder (enc) to send
diff --git a/src/serverfunctions.liq b/src/serverfunctions.liq
index 6fff37a..39ba615 100644
--- a/src/serverfunctions.liq
+++ b/src/serverfunctions.liq
@@ -179,10 +179,6 @@ server.register(
     end
 )
 
-#
-# Namespace: misc #TODO: refactor
-#
-
 def fadeTo(source_number) =
   if
     source_number == ""
@@ -210,8 +206,6 @@ server.register(
   fadeTo
 )
 
-# TODO: reimplement this as list based approach
-
 def icy_update(v) =
   # Parse the argument
   l = string.split(separator=",", v)
diff --git a/src/settings.liq b/src/settings.liq
index 4adc316..da1ab78 100644
--- a/src/settings.liq
+++ b/src/settings.liq
@@ -389,16 +389,11 @@ log(
   "\nStream Settings:"
 )
 
-# TODO: replace variable by config
-input_stream_max_buffer = config.general.input_stream_max_buffer
-
-# TODO: replace variable by config
-input_stream_timeout = config.general.input_stream_timeout
 log(
-  "\tInput stream max buffer: #{input_stream_max_buffer}"
+  "\tInput stream max buffer: #{config.general.input_stream_max_buffer}"
 )
 log(
-  "\tInput stream timeout: #{input_stream_timeout}"
+  "\tInput stream timeout: #{config.general.input_stream_timeout}"
 )
 
 # OUTPUT STREAM
@@ -421,17 +416,13 @@ log(
   "\nOther Settings:"
 )
 
-# AUDIO AND PLAYLIST SOURCES
-# TODO: replace variable with config option
-audio_playlist_folder = config.general.playlist_folder
-
 # FALLBACK SETTINGS
 fallback_show_name = ref(config.fallback.show_name)
 fallback_show_id = ref(config.fallback.show_id)
 fallback_type = config.fallback.type
 fallback_station_playlist_name = config.fallback.music_playlist
 fallback_station_playlist_path =
-  "#{audio_playlist_folder}/#{fallback_station_playlist_name}"
+  "#{config.general.playlist_folder}/#{fallback_station_playlist_name}"
 fallback_station_dir = config.fallback.music_folder
 fallback_station_dir_reload = int_of_float(config.fallback.music_folder_reload)
 fallback_max_blank = config.fallback.max_blank
@@ -445,13 +436,8 @@ log(
 )
 
 # Metadata Configuration
-# TODO: replace variable with config
 engine_meta_key_show_id = config.general.meta_key_show_id
 
-# TODO: replace variable with config
-engine_default_track_type = config.general.default_track_type
-engine_api_playlog = config.general.api_url_playlog
-engine_id = config.general.engine_id
 log(
   "\n######################################################################################"
 )
-- 
GitLab