Skip to content

Commit e750ded

Browse files
committed
stream specific properties handling added
1 parent fb6e619 commit e750ded

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

scripts/show-stream-title.lua

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
-- (see mpv doc for more details, lookup playlist/N/current, playlist/N/playing )
77
-- To display correct stream2.title from playlist use this script.
88
--
9+
-- Note: Optional stream specific mpv properties can be set in the second comma separated section.
10+
-- For example to activate subtitles id 1 and audio id 2 for "Film Europe" use playlist line:
11+
-- #EXTINF:0,Film Europe,sid="1" aid="3",0
12+
--
913
-- Note: 'force-media-title' property get updated also with empty value so
1014
-- testing for empty value is required before formatting and OSDing
1115
--
@@ -41,7 +45,7 @@ local cfg = {
4145
-- OSD text format
4246
format = "%N. %t",
4347
-- validate title from playlist (empty for passthrough = valid all)
44-
valid = "^.+,,0$",
48+
valid = "^.+,.*,0$",
4549
-- ignore title matching filename property
4650
ignorefilename = true
4751
}
@@ -50,13 +54,29 @@ local cfg = {
5054
options.read_options(cfg, 'show-stream-title')
5155

5256
-- log active config
53-
mp.msg.verbose('cfg = '..utils.to_string(cfg))
57+
mp.msg.verbose('cfg = '.. utils.to_string(cfg))
5458

5559
-- string v is empty
5660
local function empty(v)
5761
return not v or v == '' or string.find(v, "^%s*$")
5862
end
5963

64+
-- key,val iterator from string key1="val1" key2="val2"
65+
local function key_val_iter(s)
66+
-- start idx
67+
local idx = 0
68+
-- closure
69+
return function()
70+
-- extract key,val from string key="val"
71+
_, idx, key, val = string.find(s, '([%w-]+)="([^"]+)"', idx)
72+
-- return found key/val
73+
if idx then
74+
mp.msg.verbose("found key(".. key ..") = val(".. val ..") at idx:".. idx)
75+
return key, val
76+
end
77+
end
78+
end
79+
6080
-- check if string is valid title by cfg.valid pattern
6181
-- valid: 'CP24,,0', 'TA News,,0'
6282
-- invalid: 'index', 'DVR', 'iptv-streams.m3u8', 'rtmp://ip'
@@ -113,6 +133,12 @@ local function media_title(name, val)
113133
-- SMPlayer playlist val = 'Title,,0'
114134
-- playlist val = 'Title'
115135

136+
-- set custom stream options
137+
for pname,pval in key_val_iter(val) do
138+
mp.msg.info("set_property(".. pname ..", ".. pval ..")")
139+
mp.set_property(pname, pval)
140+
end
141+
116142
-- get comma position or entire length
117143
local compos = string.find(val ..",", ",")
118144
-- strip commas from stream title

0 commit comments

Comments
 (0)