Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve song metadata handling in input.harbor #4244

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 5 additions & 3 deletions tests/streams/harbor_metadata.liq
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
port = 3461

def fn() =
def on_metadata(m) =
if
Expand All @@ -23,7 +25,7 @@ def fn() =
password="testtest",
user="testtest",
host="localhost",
port=9834,
port=port,
mount="test",
[
(
Expand All @@ -46,14 +48,14 @@ def fn() =
password="testtest",
user="testtest",
"test",
port=9834,
port=port,
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()
%mp3, password="testtest", user="testtest", mount="test", port=port, noise()
)
end

Expand Down
66 changes: 66 additions & 0 deletions tests/streams/harbor_metadata_2.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
port = 3464

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=port,
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=port,
on_connect=on_connect
)

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

test.check(fn)
69 changes: 69 additions & 0 deletions tests/streams/harbor_metadata_3.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
port = 3463

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=port,
mount="test",
[
(
"song",
"song title"
),
(
"artist",
"the artist"
),
(
"url",
"metadata url"
)
]
)
}
)
end

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

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

test.check(fn)
Loading