Skip to content

Commit

Permalink
v2.2.1 – Add use_json_metadata switch (default: true)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonbase59 committed Jun 11, 2024
1 parent aff9320 commit 534297b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# autocue changelog

### 2024-06-11 – v2.2.1

- Make JSON override switchable (`settings.autocue.cue_file.use_json_metadata`).
Defaults to `true`.
- Minor code cleanup (thanks @vitoyucepi).

### 2024-06-11 – v2.2.0 (internal, unreleased)

- JSON override tags for cue_file in temp file:
Allows passing annotate/database overrides to cue_file,
to reduce re-analysis runs even more.

### 2024-06-09 – v2.1.0

- Prepare for third-party pre-processing software:
Expand Down
70 changes: 45 additions & 25 deletions autocue.cue_file.liq
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# 2024-06-11 - Moonbase59 - v2.2.0 JSON override tags for cue_file in temp file:
# Allows passing annotate/database overrides to
# cue_file, to reduce re-analysis runs even more.
# 2024-06-11 - Moonbase59 - v2.2.1 Make JSON override switchable

# Lots of debugging output for AzuraCast in this, will be removed eventually.

Expand All @@ -35,7 +36,7 @@ let settings.autocue.cue_file.version =
settings.make(
description=
"Software version of autocue.cue_file. Should coincide with `cue_file`.",
"2.2.0"
"2.2.1"
)

let settings.autocue.cue_file.path =
Expand Down Expand Up @@ -158,6 +159,15 @@ let settings.autocue.cue_file.nice =
false
)

let settings.autocue.cue_file.use_json_metadata =
settings.make(
description=
'Send metadata to `cue_file` as JSON, allowing to override/add to \
autocue-relevant metadata stored in file tags. This can help to avoid \
unnecessary re-analysis runs.',
true
)

stdlib_metadata = metadata

# metadata.json.stringify only exports a limited set, use our own
Expand Down Expand Up @@ -187,6 +197,7 @@ def cue_file(~request_metadata, ~file_metadata, filename) =
force_analysis = settings.autocue.cue_file.force_analysis()
nice = settings.autocue.cue_file.nice()
noclip = settings.autocue.cue_file.noclip()
use_json_metadata = settings.autocue.cue_file.use_json_metadata()

label = "autocue.cue_file"

Expand Down Expand Up @@ -302,44 +313,52 @@ def cue_file(~request_metadata, ~file_metadata, filename) =
if force_analysis then args := list.add('-f', args()) end
if nice then args := list.add('-n', args()) end

# write metadata to temp file for cue_file to pick up
tempfile = file.temp("cue_file", ".json")
json_meta = meta_json_stringify(compact=true, meta)
log(level=4, label=label, "#{tempfile}: #{json_meta}")
file.write(
data=json_meta,
append=true,
tempfile
)
args := ['-j', tempfile, ...args()]
tempfile = ref("")
if use_json_metadata then
# write metadata to temp file for cue_file to pick up
tempfile := file.temp("cue_file", ".json")
json_meta = meta_json_stringify(compact=true, meta)
log(level=4, label=label, "Writing metadata to #{tempfile()}: #{json_meta}")
log(level=3, label=label, "Writing metadata to #{tempfile()}")
file.write(
data=json_meta,
append=true,
tempfile()
)
args := ['-j', tempfile(), ...args()]
end

res = ref("")
try
res :=
res =
try
list.hd(
default="",
process.read.lines(
timeout=timeout,
process.quote.command(settings.autocue.cue_file.path(), args=args())
)
)
catch err do
log(
level=2,
label=label,
'cue_file error: #{err}'
)
res := ""
catch err do
log(
level=2,
label=label,
'cue_file error: #{err}'
)
""
end

if use_json_metadata then
# remove tempfile again
log(level=4, label=label, "Removing #{tempfile()}")
file.remove(tempfile())
end
file.remove(tempfile)

if
res() != ""
res != ""
then
log(
level=3,
label=label,
'cue_file result for "#{filename}": #{res()}'
'cue_file result for "#{filename}": #{res}'
)

let json.parse (
Expand Down Expand Up @@ -380,7 +399,7 @@ def cue_file(~request_metadata, ~file_metadata, filename) =
liq_true_peak: float,
liq_true_peak_db: string
}
) = res()
) = res

# must stringify, because metadata & annotations are strings
result = ref(
Expand Down Expand Up @@ -742,6 +761,7 @@ log(level=2, label="autocue.cue_file",
# settings.autocue.cue_file.write_replaygain := false # write ReplayGain tags back to file
# settings.autocue.cue_file.force_analysis := false # force re-analysis even if tags found
# settings.autocue.cue_file.nice := false # Linux/MacOS only: Use NI=18 for analysis
# settings.autocue.cue_file.use_json_metadata := true # pass metadata to `cue_file` as JSON

# `enable_autocue_metadata()` will autocue ALL files Liquidsoap processes.
# You can disable it for selected sources using 'annotate:liq_cue_file=false'.
Expand Down
3 changes: 2 additions & 1 deletion cue_file
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
# - Add `liq_fade_in` & `liq_fade_out` tags for reading/writing,
# in case a preprocessor needs to set fade durations.
# 2024-06-11 Moonbase59 - v2.2.0 Sync version numver with autocue.cue_file
# 2024-06-11 Moonbase59 - v2.2.1 Sync version number with autocue.cue_file
#
# Originally based on an idea and some code by John Warburton (@Warblefly):
# https://github.com/Warblefly/TrackBoundaries

__author__ = 'Matthias C. Hormann'
__version__ = '2.2.0'
__version__ = '2.2.1'

import os
import tempfile
Expand Down
1 change: 1 addition & 0 deletions test_autocue.cue_file.liq
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ settings.autocue.cue_file.blankskip := true
# settings.autocue.cue_file.write_replaygain := true # testing
# settings.autocue.cue_file.force_analysis := true # testing
settings.autocue.cue_file.nice := true # Linux/MacOS only!
# settings.autocue.cue_file.use_json_metadata := true # pass metadata to `cue_file` as JSON

# `enable_autocue_metadata()` will autocue ALL files Liquidsoap processes.
# You can disable it for selected sources using 'annotate:liq_cue_file=false'.
Expand Down

0 comments on commit 534297b

Please sign in to comment.