mpv metadata (Song title)

For discussions about programming and projects not necessarily associated with Porteus.
Posts: 615
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

mpv metadata (Song title)

Post#1 by Kulle » 07 Apr 2024, 11:40

For example, this command
mpv "${URL}" --term-status-msg="icy-title: ${metadata/icy-title}" | grep -oP "icy-title: \K.*"

returns these two lines:
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:

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

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?

User avatar
DEV Team
DEV Team
Posts: 3972
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia

mpv metadata (Song title)

Post#2 by ncmprhnsbl » 09 Apr 2024, 09:06

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
Forum Rules :

Post Reply