Page 1 of 1

mpv metadata (Song title)

Posted: 07 Apr 2024, 11:40
by Kulle
For example, this command
mpv "${URL}" --term-status-msg="icy-title: ${metadata/icy-title}" | grep -oP "icy-title: \K.*"

returns these two lines:
icy-title:
Jackie Wilson - Reet Petite

But I want only the second line to be output, so just the title.
How does the mpv command need to be modified?

The AI (chatGPT) suggested:

Mpv supports the use of Lua scripts to customize behavior. One such script could extract and output the song title separately:

Create a file called songtitle.lua with the following content:

lua
local msg = mp.get_property_native("metadata/icy-title")
if msg then
local title = string.match(msg, "icy%-title%: (.*)")
if title then
print(title)
end
end

Start mpv with mpv --script=songtitle.lua "${URL}"

This script directly accesses the "icy-title" metadata and extracts the song title using string.match.

Can the mpv command be modified as desired without using a lua script?

That should be possible.
Does somebody has any idea?

mpv metadata (Song title)

Posted: 09 Apr 2024, 09:06
by ncmprhnsbl
my audio files don't seem to give any of that type of metadata.. but anyway
how about just piping to tail like this:

Code: Select all

mpv "${URL}" --term-status-msg="icy-title: ${metadata/icy-title}" | grep -oP "icy-title: \K.*" | tail -n 1
the output without the grep part might shed some light on why the grep isn't doing what you want