启动mpv
之后,是否有办法从mpv
获取当前播放文件的完整路径?
我看到了this问题,但没有显示如何获取属性,而是如何发送命令。
答案 0 :(得分:1)
试试这个:
echo '{ "command": ["get_property", "playlist"] }' | socat - /tmp/mpvsocket |jq '.data[].filename'
"/mnt/d6/media/vid.mp4"
即
# -- 1
echo '{ "command": ["get_property", "playlist"] }' | socat - /tmp/mpvsocket # |jq . '.data[].filename'
{"data":[{"filename":"/mnt/d6/media/vid.mp4","current":true,"playing":true}],"request_id":0,"error":"success"}
# -- 2
echo '{ "command": ["get_property", "playlist"] }' | socat - /tmp/mpvsocket |jq . # '.data[].filename'
{
"data": [
{
"filename": "/mnt/d6/media/vid.mp4",
"current": true,
"playing": true
}
],
"request_id": 0,
"error": "success"
}
# -- 3
echo '{ "command": ["get_property", "playlist"] }' | socat - /tmp/mpvsocket |jq '.data[].filename'
"/mnt/d6/media/vid.mp4"
# -- 4
enjoy ;)
# -- jq
https://www.baeldung.com/linux/jq-command-json
https://stedolan.github.io/jq/tutorial/
jq is like sed for JSON data :
you can use it to slice and filter and map and transform structured data
with the same ease that sed, awk, grep and
friends let you play with text.
答案 1 :(得分:0)
为此,您必须以mpv
选项开始--input-ipc-server
,或将其放入mpv.conf
文件中。看起来像这样:
--input-ipc-server=/tmp/mpvsocket
或mpv.conf
文件中没有破折号:
input-ipc-server=/tmp/mpvsocket
套接字已连接到使用同一mpv
启动的最新input-ipc-server
实例。
然后,您可以使用以下命令:
echo '{ "command": ["get_property", "<some property>"] }' | socat - /tmp/mpvsocket
例如:
$ echo '{ "command": ["get_property", "path"] }' | socat - /tmp/mpvsocket
{"data":"01 - Don't Know Why.mp3","request_id":0,"error":"success"}
您可以通过执行mpv --list-properties
要获取完整路径,请组合working-directory
和path
属性。可以使用jq
来解析响应,因此对于所需的输出:
#!/bin/sh
SOCKET='/tmp/mpvsocket'
# pass the property as the first argument
mpv_communicate() {
printf '{ "command": ["get_property", "%s"] }\n' "$1" | socat - "${SOCKET}" | jq -r ".data"
}
WORKING_DIR="$(mpv_communicate "working-directory")"
FILEPATH="$(mpv_communicate "path")"
printf "%s/%s\n" "$WORKING_DIR" "$FILEPATH"
答案 2 :(得分:0)
把它放在你的 mpv 配置文件中以在打开时显示完整路径
osd-playing-msg=${path}