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

Basic functionality to merge and insert metadata

parent 87ef126b
No related branches found
No related tags found
1 merge request!3Liquidsoap 2 migration
......@@ -22,6 +22,71 @@
# METADATA
#
# Merge with previous metadata, avoid duplicates
def merge_meta(last_meta, meta) =
log(level=5, label="metadata", "Merge | last metadata: #{last_meta}")
log(level=5, label="metadata", "Merge | current metadata: #{meta}")
merged = ref(last_meta)
def add_meta_entry(entry) =
let (k, _) = entry
if list.assoc.mem(k, !merged) then
log(level=5, label="metadata", "Remove existing entry #{entry}")
merged := list.assoc.remove(k, !merged)
end
merged := list.add(entry, !merged)
end
list.iter(add_meta_entry, (meta))
log(level=5, label="metadata", "Merge | resulting metadata: #{!merged}")
!merged
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
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] ? true : false
end
# Checks if the current show metadata is same as the previous one
def is_same_show(last_meta, current_meta) =
if has_show_meta(last_meta) then
if not has_show_meta(current_meta) then
# No current show meta: handle as same show
true
elsif is_same_show(last_meta, current_meta) then
true
else
# A new show has started
false
end
else
# Last show has no show meta
if not has_show_meta(current_meta) then
# And the current one either: handle as same show
true
else
# Treat missing last show info as the same show
true
end
end
end
# Handles either insert or merge & insert of metadata, depending on the show ID
def do_meta_insert(last_meta_callback, insert_meta_callback, meta) =
lm = (last_meta_callback() ?? [])
if is_same_show(lm, meta) then
lm = (last_meta_callback() ?? [])
merged = merge_meta(lm, meta)
insert_meta_callback(merged)
else
insert_meta_callback(meta)
end
end
# Builds a metadata object from data passed as JSON
def build_metadata(json_string) =
......
......@@ -156,6 +156,7 @@ print("Station Fallback Playlist: '#{fallback_station_playlist_path}'")
print("Station Fallback Directory: '#{fallback_station_dir}'")
# Metadata Configuration
engine_meta_key_show_id = list.assoc(default="show_id", "meta_key_show_id", ini)
engine_default_track_type = list.assoc(default="0", "default_track_type", ini)
engine_fallback_show_name = ref(list.assoc(default="Station Fallback", "fallback_show_name", ini))
engine_fallback_show_id = ref(list.assoc(default="-1", "fallback_show_id", ini))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment