Skip to content

Commit

Permalink
Disable song metadata when either artist or title are passed. Add
Browse files Browse the repository at this point in the history
configuration to allow to pass all metadata verbatim.
  • Loading branch information
toots committed Dec 7, 2024
1 parent 47842fb commit 11cf06d
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Changed:

- Make alsa I/O work with buffer size different than
liquidsoap internal frame (#4236)
- Make `"song"` metadata mapping to `"title"` metadata in
`input.harbord` disabled when either `"artist"` or `"title"`
is also passed. Add a configuration key to disable this mechanism.
(#4235, #2676)

Changed:

Expand Down
15 changes: 9 additions & 6 deletions src/core/harbor/harbor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,18 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
|> Option.map Charset.of_string
in
(* Recode tags.. *)
let g x = Charset.convert ?source:in_enc x in
let f x y m =
let x =
let add, x =
match x with
| "song" -> "title"
| "url" -> "metadata_url"
| _ -> x
| "song" when not conf_map_song_metadata#get -> (true, "song")
| "song" ->
( not (Hashtbl.mem args "title" || Hashtbl.mem args "artist"),
"title" )
| "url" -> (true, "metadata_url")
| _ -> (true, x)
in
let g x = Charset.convert ?source:in_enc x in
Frame.Metadata.add (g x) (g y) m
if add then Frame.Metadata.add (g x) (g y) m else m
in
let args = Hashtbl.fold f args Frame.Metadata.empty in
s#insert_metadata args;
Expand Down
10 changes: 10 additions & 0 deletions src/core/harbor/harbor_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ let conf_icy_metadata =
]
"Content-type (mime) of formats which allow shout metadata update."

let conf_map_song_metadata =
Dtools.Conf.bool
~p:(conf_harbor#plug "map_song_metadata")
~d:true
"If `true`, `\"song\"` metadata in icecast metadata update is mapped to \
`\"title\"` unless on of: `\"artist\"` or `\"title\"` metadata is also \
passed in which case `\"song\"` metadata is removed as it usually \
contains redundant info that confuses the system. Metadata are passed \
as-is when `false`."

let conf_timeout =
Dtools.Conf.float
~p:(conf_harbor#plug "timeout")
Expand Down
62 changes: 62 additions & 0 deletions tests/streams/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,68 @@
(:run_test ../run_test.exe))
(action (run %{run_test} harbor_metadata.liq liquidsoap %{test_liq} harbor_metadata.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
harbor_metadata_2.liq
./file1.mp3
./file2.mp3
./file3.mp3
./jingle1.mp3
./jingle2.mp3
./jingle3.mp3
./file1.png
./file2.png
./jingles
./playlist
./huge_playlist
./replaygain_track_gain.mp3
./r128_track_gain.mp3
./replaygain_r128_track_gain.mp3
./replaygain_track_gain.opus
./r128_track_gain.opus
./replaygain_r128_track_gain.opus
./without_replaygain_track_gain.mp3
./crossfade-plot.old.txt
./crossfade-plot.new.txt
../../src/bin/liquidsoap.exe
(package liquidsoap)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} harbor_metadata_2.liq liquidsoap %{test_liq} harbor_metadata_2.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
harbor_metadata_3.liq
./file1.mp3
./file2.mp3
./file3.mp3
./jingle1.mp3
./jingle2.mp3
./jingle3.mp3
./file1.png
./file2.png
./jingles
./playlist
./huge_playlist
./replaygain_track_gain.mp3
./r128_track_gain.mp3
./replaygain_r128_track_gain.mp3
./replaygain_track_gain.opus
./r128_track_gain.opus
./replaygain_r128_track_gain.opus
./without_replaygain_track_gain.mp3
./crossfade-plot.old.txt
./crossfade-plot.new.txt
../../src/bin/liquidsoap.exe
(package liquidsoap)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} harbor_metadata_3.liq liquidsoap %{test_liq} harbor_metadata_3.liq)))

(rule
(alias citest)
(package liquidsoap)
Expand Down
64 changes: 64 additions & 0 deletions tests/streams/harbor_metadata_2.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
def fn() =
def on_metadata(m) =
if

m["title"] ==
"the real title"

and

m["metadata_url"] ==
"metadata url"

then
test.pass()
end
end

def on_connect(_) =
thread.run(
delay=1.,
{
icy.update_metadata(
password="testtest",
user="testtest",
host="localhost",
port=9834,
mount="test",
[
(
"song",
"song title"
),
(
"title",
"the real title"
),
(
"url",
"metadata url"
)
]
)
}
)
end

s =
input.harbor(
buffer=0.1,
password="testtest",
user="testtest",
"test",
port=9834,
on_connect=on_connect
)

s.on_metadata(on_metadata)
output.dummy(fallible=true, s)
output.icecast(
%mp3, password="testtest", user="testtest", mount="test", port=9834, noise()
)
end

test.check(fn)
67 changes: 67 additions & 0 deletions tests/streams/harbor_metadata_3.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
def fn() =
def on_metadata(m) =
print(m)
if
m["title"] == ""
and

m["artist"] ==
"the artist"

and

m["metadata_url"] ==
"metadata url"

then
test.pass()
end
end

def on_connect(_) =
thread.run(
delay=1.,
{
icy.update_metadata(
password="testtest",
user="testtest",
host="localhost",
port=9834,
mount="test",
[
(
"song",
"song title"
),
(
"artist",
"the artist"
),
(
"url",
"metadata url"
)
]
)
}
)
end

s =
input.harbor(
buffer=0.1,
password="testtest",
user="testtest",
"test",
port=9834,
on_connect=on_connect
)

s.on_metadata(on_metadata)
output.dummy(fallible=true, s)
output.icecast(
%mp3, password="testtest", user="testtest", mount="test", port=9834, noise()
)
end

test.check(fn)

0 comments on commit 11cf06d

Please sign in to comment.