Skip to content

Commit fb6e619

Browse files
committed
better val=nil handling, optional conf file
1 parent 713123d commit fb6e619

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

scripts/show-stream-title.lua

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
-- %t ... iPTV channel name (user friendly stream title)
3434
-- %T ... iPTV channel name in uppercase
3535

36+
local options = require("mp.options")
37+
local utils = require("mp.utils")
38+
3639
-- defaults
3740
local cfg = {
3841
-- OSD text format
@@ -43,12 +46,25 @@ local cfg = {
4346
ignorefilename = true
4447
}
4548

49+
-- read lua-settings/show-stream-title.conf
50+
options.read_options(cfg, 'show-stream-title')
51+
52+
-- log active config
53+
mp.msg.verbose('cfg = '..utils.to_string(cfg))
54+
55+
-- string v is empty
56+
local function empty(v)
57+
return not v or v == '' or string.find(v, "^%s*$")
58+
end
59+
4660
-- check if string is valid title by cfg.valid pattern
4761
-- valid: 'CP24,,0', 'TA News,,0'
4862
-- invalid: 'index', 'DVR', 'iptv-streams.m3u8', 'rtmp://ip'
4963
local function is_valid_title(s)
5064
-- everything is valid (passthrough) if validation pattern is missing
5165
if not cfg.valid then return true end
66+
-- empty (nil) is invalid
67+
if empty(s) then return false end
5268
-- validate with pattern
5369
return string.match(s, cfg.valid)
5470
end
@@ -66,11 +82,6 @@ end
6682
-- [show_stream_title] property 'media-title' changed to 'index'
6783
--
6884

69-
-- string v is empty
70-
local function empty(v)
71-
return not v or v == '' or string.find(v, "^%s*$")
72-
end
73-
7485
-- format and show OSD forced media title val if not empty
7586
local function force_media_title(name, val)
7687
-- currently played filename
@@ -93,9 +104,9 @@ local function force_media_title(name, val)
93104
end
94105

95106
-- pass as force media title if media title val is valid
96-
local function media_title(name , val)
107+
local function media_title(name, val)
97108
-- log
98-
mp.msg.info("media_title(name:".. name ..", val:".. val ..")")
109+
mp.msg.info("media_title(name:".. name ..", val:".. utils.to_string(val) ..")")
99110
-- val can be url (redirects ?)
100111
if not is_valid_title(val) then return end
101112

0 commit comments

Comments
 (0)