MPV: how to get information about media being played through command line?
This mpv script stats.lua will show info of currently playing media by pressing i,I,1,2,3 name it stats.lua put in ~/.config/mpv/scripts/stats.lua, it will load each time you start mpv, if always load not desired do
mpv --script=~/.config/mpv/scripts/mynotify.lua /path/to/media.webm
(full path to script might be required)
Related videos on Youtube
caseneuve
Updated on September 18, 2022Comments
-
caseneuve almost 2 years
I want to get output containing info about title, state (playing/paused), current position, total time, etc., of the media currently being played in
mpv
.In
mocp
player for example it's easy:mocp -i
provides output like this:State: PLAY File: /home/piotr/muz/09 Svantetic.mp3 Title: 1 Możdżer - Svantetic (Komeda) Artist: Możdżer SongTitle: Svantetic Album: Komeda TotalTime: 03:35 TimeLeft: 03:22 TotalSec: 215 CurrentTime: 00:13 CurrentSec: 13 Bitrate: 235kbps AvgBitrate: 236kbps Rate: 44kHz
Is it possible to get such information in
mpv
?UPDATE:
Seems it requires some lua scripting. Since I am not familiar with this language I would appreciate any hint. I am interested in a script which will provide info mentioned above when summoned from command line.
UPDATE 2
Apparently to get such an easy info in mpv one has to start mpv socket, and then extract data throug parsing JSON. For now I ended with quick and dirty solution (still can't believe that there is no built in functionality for this...):
mpv <file> --input-ipc-server=/tmp/mpvsocket
and a bash script:
POSITION=$(echo '{ "command": ["get_property_string", "time-pos"] }' | socat - /tmp/mpvsocket | jq .data | tr '"' ' ' | cut -d'.' -f 1) REMAINING=$(echo '{ "command": ["get_property_string", "time-remaining"] }' | socat - /tmp/mpvsocket | jq .data | tr '"' ' ' | cut -d'.' -f 1) METADATA=$(echo '{ "command": ["get_property", "filtered-metadata"] }' | socat - /tmp/mpvsocket | jq ".data.Artist, .data.Album, .data.Title") echo $METADATA printf '%d:%02d:%02d' $(($POSITION/3600)) $(($POSITION%3600/60)) $(($POSITION%60)) printf ' %d:%02d:%02d\n' $(($REMAINING/3600)) $(($REMAINING%3600/60)) $(($REMAINING%60))
Which gives output:
"Nils Frahm" "Felt" "Keep" 0:01:33 0:01:53
(note: METADATA works only for files with tags, to get info from online streaming one has to apply other commands; I use
jq
to parse JSON data from /tmp/mpvsocket) -
rofrol over 2 yearspaste.debian.net - entry not found
-
polemon over 2 yearsIs it perhaps the same as this one: github.com/mpv-player/mpv/blob/master/player/lua/stats.lua If so, I'll update the link.