12

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)

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
caseneuve
  • 281

1 Answers1

1

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)