Skip to content

Commit

Permalink
Add exlusion list for auto-charset conversion with metadata. Make sur…
Browse files Browse the repository at this point in the history
…e cover art is not converted. Fixes: #3279 (#3302)
  • Loading branch information
toots committed Aug 7, 2023
1 parent b46726d commit 0b53f37
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Fixed:
- Make all HLS file write atomic (#3284)
- Allow seek and cue operators to work with muxed sources
using a single underlying source (#3252)
- Fixed export of cover art metadata (#3279)

---

Expand Down
15 changes: 12 additions & 3 deletions src/core/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ let conf_recode =
~p:(conf_metadata_decoders#plug "recode")
~d:true "Re-encode metadata strings in UTF-8"

let conf_recode_excluded =
Dtools.Conf.list
~d:["apic"; "metadata_block_picture"; "coverart"]
~p:(conf_recode#plug "exclude")
"Exclude these metadata from automatic recording."

(** Sys.file_exists doesn't make a difference between existing files and files
without enough permissions to list their attributes, for example when they
are in a directory without x permission. The two following functions allow a
Expand Down Expand Up @@ -330,16 +336,19 @@ let read_metadata t =
(Lang_string.quote_string name)
else (
let convert =
if conf_recode#get then fun x -> Charset.convert x else fun x -> x
if conf_recode#get then (
let excluded = conf_recode_excluded#get in
fun k v -> if not (List.mem k excluded) then Charset.convert v else v)
else fun _ x -> x
in
List.iter
(fun (_, resolver) ->
try
let ans = resolver ~metadata:indicator.metadata name in
List.iter
(fun (k, v) ->
let k = String.lowercase_ascii (convert k) in
let v = convert v in
let k = String.lowercase_ascii (convert k k) in
let v = convert k v in
if conf_override_metadata#get || get_metadata t k = None then
Hashtbl.replace indicator.metadata k v)
ans;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/metadata.liq
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def metadata.cover(~coverart_mime=null(), m)
end
end

# Obtain cover-art for a file. An empty string is returned in case there is no
# Obtain cover-art for a file. `null` is returned in case there is no
# such information.
# @category Metadata
# @param file File from which the cover should be obtained
Expand Down
58 changes: 57 additions & 1 deletion tests/language/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

(include dune.inc)

(executable
(name gen_dune)
(libraries liquidsoap_build_tools)
(modules gen_dune))

(rule
(alias gendune)
(deps
Expand All @@ -10,9 +15,60 @@
(action
(with-stdout-to
dune.inc.gen
(run ../gen_dune.exe))))
(run ./gen_dune.exe))))

(rule
(alias gendune)
(action
(diff dune.inc dune.inc.gen)))

(rule
(deps
write_cover.liq
../../src/bin/liquidsoap.exe
(package liquidsoap)
(:stdlib ../../src/libs/stdlib.liq))
(target cover.png)
(action
(run ../../src/bin/liquidsoap.exe ./write_cover.liq -- %{target})))

(rule
(alias citest)
(deps cover.png)
(target cover.mp3)
(action
(run
ffmpeg
-hide_banner
-loglevel
error
-f
lavfi
-i
"sine=frequency=220:duration=5"
-ac
2
-i
./cover.png
-map
0
-map
1
-vcodec
copy
%{target})))

(rule
(alias citest)
(package liquidsoap)
(deps
cover.png
cover.mp3
test_cover.liq
../../src/bin/liquidsoap.exe
(package liquidsoap)
(:stdlib ../../src/libs/stdlib.liq)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action
(run %{run_test} test_cover.liq liquidsoap %{test_liq} test_cover.liq)))
49 changes: 49 additions & 0 deletions tests/language/gen_dune.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let excluded_files = ["write_cover.liq"; "test_cover.liq"]

let () =
let location = Sys.getcwd () in
let tests =
List.filter
(fun f ->
Filename.extension f = ".liq" && not (List.mem f excluded_files))
(Build_tools.read_files ~location "")
in
List.iter
(fun test ->
Printf.printf
{|
(rule
(alias citest)
(package liquidsoap)
(deps
%s
../../src/bin/liquidsoap.exe
(package liquidsoap)
(:stdlib ../../src/libs/stdlib.liq)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %%{run_test} %s liquidsoap %%{test_liq} %s)))
|}
test test test)
tests;

let output_tests =
List.filter
(fun f -> Filename.extension f = ".output")
(Array.to_list (Sys.readdir location))
in
List.iter
(fun test ->
Printf.printf
{|
(rule
(alias citest)
(package liquidsoap)
(deps
%s
(:check_output ../check_output.exe)
(:run_test ../run_test.exe))
(action (run %%{run_test} %s %%{check_output})))
|}
test test)
output_tests
8 changes: 8 additions & 0 deletions tests/language/test_cover.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def f() =
cover_png = file.cover("./cover.mp3")
expected_png = file.contents("cover.png")
test.equals("#{cover_png}", expected_png)
test.pass()
end

test.check(f)
9 changes: 9 additions & 0 deletions tests/language/write_cover.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
settings.init.force_start := true

target = argv(1)

png = string.base64.decode("iVBORw0KGgoAAAANSUhEUgAAAIAAAACAEAIAAAAczCrfAAAACXBIWXMAAAAAAAAAAQCEeRdzAAACoklEQVR4nO3E4UYYAACF0StJkiRJkiRJkiRJkiRJkiTJli1btmzZsmXLli3atGnTpk2bNm3atEmSJEmSJEmSJEmSJEmSJEnS9h73Oz+O9N/VFbPvurxg9l0XZ8y+6/yE2XedHTH7rtMDZt91ssfsu453mH3X0Raz7zrcYPZdB2vMvmt/hdl37S0x+67dBWbftTPH7Lu2Z5h919YUs+/anGD2XRtjzL5rfYTZd60NMfuu1QFm37Xyh9l3Lf9i9l1LP5h91+I3Zt+18IXZd81/YvZdcx+YfdfsO2bfNfOG2XdNv2L2XVMtzL5rspnZd000Mfuu8UZm3zXWwOy7RuuZfddIHbPvGq5l9l1DNcy+a7Ca2XcNVDH7rv4KZt/1t4zZd/WVMPuu30XMvqu3gNl3/cxj9l09Ocy+63sWs+/qzmD2XV/TmH1XVwqz7/qcxOy7OhOYfdfHOGbf1RHD7LveRzH7rvYIZt/1NozZd7WFMPuu10HMvqs1gNl3tVwy+64X58y+q/mU2Xc9O2b2XU2HzL7ryT6z72rcZfZdj7aZfVfDJrPverDO7LvqV5l9171lZt9Vt8jsu+7MM/uu2llm33Vrmtl31Uwy+64b48y+q3qU2XddG2b2XVWDzL6rsp/Zd1X0Mfuu8l5m31XWw+y7SruZfVdJF7PvKu5k9l1FHcy+q7Cd2XcVtDH7rvxWZt+V95LZd+U+Z/ZdOU+ZfVf2Y2bflfWQ2Xdl3mf2XRl3mX1X+m1m35V2k9l3pV5n9l0plcy+K7mc2XcllTL7rsRiZt+VUMjsu+LzmX1XXC6z74rNZvZdMZnMvis6ndl3RaUy+67IZGbfFZHI7LvC45l9V1gss+8KjWb2XSGRzL4rOJzZdwWFMvuuwGBm3xUQyOw7YOsfJwPDsnrI0ewAAAAASUVORK5CYII=")

file.write(data=png, target)

exit(0)

0 comments on commit 0b53f37

Please sign in to comment.