Parsing the server’s JSON-formatted user-data did, indeed, work for me. I arbitrarily assigned the F-key a couple of functions and tossed those into nowPlaying.lua:
f - Show the filename and full filepath of the playing video, and return them to other script functions: filename,filepath = nowFile()
F - Show descriptive metadata for the video, and return them to other script functions: title,rating,year,release,summary,show,s00e00,episode = nowPlaying()
Caveats:
- I use Windows PMS, with UNC paths to NAS media, and tried to accomodate others, but you may need to tweak.
- If a match does not occur, the value will contain the entire playing-media json.
- “f” is pretty ugly unformatted, and “F” provides a formatted example. Among other apporoaches, OSD settings can be added to the mpv.conf (e.g.,
–osd-font-size=24,–osd-color=“#FFEBAF00”,–osd-border-size=“0.5” - I only started scripting with Lua when I read this post (lots of room for improvement), and I have even less idea how to correctly post a script here.
function nowFile()
local media, filepath, filename
media = mp.get_property("user-data/plex/playing-media")
filepath=".+\"file\":\"(.-[%w%s%p])\".+$"
filepath=string.gsub(media,filepath,"%1")
if string.match(filepath, "\\") then --## Windows?
filepath=string.gsub(filepath,"[\\][\\]","\\")
filename=string.gsub(filepath,".+\\(.-[%w%p])","%1")
elseif string.match(filepath, "/") then --## Linux, etc.?
filename=string.gsub(filepath,".+/(.-[%w%p])","%1")
end
mp.osd_message("Filename: "..filename.."\n\nFilepath: "..filepath, 4)
return filename, filepath
end
function nowPlaying()
local media, title, episode, rating, release, year, summary, show, s00e00, msg
local format="{\\a6\\fs12\\bord0.25\\c&H00AFEB&}" --## ASS formatting
--## Create patterns and gsub media to collect values
media = mp.get_property("user-data/plex/playing-media")
title=".+\"summary\":\".-\"title\":\"(.-[%w%s%p])\".+$"
title=string.gsub(media,title,"%1")
episode=title
title="{\\fscx120\\fscy120\\b1}"..title.."{\\b0}\\h"
episode="{\\fscx90\\fscy90\\b1}\\h·\\h"..episode.."\\h·\\h{\\b0}"
rating=".+\"contentRating\":\"(.-[%w%s%p])\".+$"
rating=string.gsub(media,rating,"%1")
rating="{\\fscx70\\fscy70}\\h\\h["..rating.."]"
release=".+\"originallyAvailableAt\":\"(.-[%w%s%p])\".+$"
release=string.gsub(media,release,"%1")
year=string.sub(release, 1, 4)
release="{\\fscx70\\fscy70}("..release..")"
year="{\\fscx70\\fscy70}("..year..")"
summary=".+\"summary\":\"(.-[%w%s%p])\",\".-[^tagline][^thumb].+$"
summary=string.gsub(media,summary,"%1")
summary = string.gsub(summary,"[\\]([\"])","%1") --## fix escaped quote marks
summary="{\\fscx60\\fscy60\\q0}"..summary.."\n"
--## Spit out the formatted message
if string.match(media, "\"type\":\"episode\"") then
--## Parse for some tv-only fields
show=".+\"grandparentTitle\":\"(.-[%w%s%p])\".+$"
show=string.gsub(media,show,"%1")
show="{\\fscx120\\fscy120\\b1}"..show.."{\\b0}"
s00e00=".+\"file\":\".-([Ss][0-9][0-9][Ee][0-9][0-9]).+$"
s00e00=string.gsub(media,s00e00,"%1")
s00e00="{\\fscx70\\fscy70}("..s00e00..")"
msg=format..show..rating.."\n"
msg=msg..format..s00e00..episode..release.."\n"
title=nil
elseif string.match(media, "\"type\":\"movie\"") then
episode=nil
msg=format..title..year..rating.."\n"
end --## Comment out the line below to prevent display of summaries
msg=msg..format..summary
mp.osd_message(mp.get_property_osd("osd-ass-cc/0")..msg..mp.get_property_osd("osd-ass-cc/1"), 4)
return title, rating, year, release, summary, show, s00e00, episode
end
mp.add_forced_key_binding("f", "nowFile", nowFile)
mp.add_forced_key_binding("Shift+F", "nowPlaying", nowPlaying)
