comparison src/lib/Bbcode.luan @ 30:8ff35379cc89

regex cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 25 Jul 2022 22:10:28 -0600
parents a1db5223ced1
children 298c71e0c854
comparison
equal deleted inserted replaced
29:a1db5223ced1 30:8ff35379cc89
107 %><iframe width="560" height="315" frameborder="0" allowfullscreen src="<%=url%>"></iframe><% 107 %><iframe width="560" height="315" frameborder="0" allowfullscreen src="<%=url%>"></iframe><%
108 end 108 end
109 109
110 local video_handlers = {} 110 local video_handlers = {}
111 do 111 do
112 local ptn1 = regex[[https://youtu.be/([a-zA-Z0-9_-]+)(?:\?t=([0-9]+))?]] 112 local ptn1 = regex[[^\Qhttps://youtu.be/\E([a-zA-Z0-9_-]+)(?:\?t=([0-9]+))?]]
113 local ptn2 = regex[[https://www.youtube.com/watch\?v=([a-zA-Z0-9_-]+)(?:&t=([0-9]+)s)?]] 113 local ptn2 = regex[[^\Qhttps://www.youtube.com/watch?v=\E([a-zA-Z0-9_-]+)(?:&t=([0-9]+)s)?]]
114 function video_handlers.youtube(url) 114 function video_handlers.youtube(url)
115 local id, start = ptn1.match(url) 115 local id, start = ptn1.match(url)
116 if id == nil then 116 if id == nil then
117 id, start = ptn2.match(url) 117 id, start = ptn2.match(url)
118 end 118 end
126 video_iframe(url) 126 video_iframe(url)
127 return true 127 return true
128 end 128 end
129 end 129 end
130 do 130 do
131 local ptn = regex[[https://rumble.com/embed/[a-z0-9]+/\?pub=[a-z0-9]+]] 131 local ptn = regex[[^\Qhttps://rumble.com/embed/\E[a-z0-9]+/\?pub=[a-z0-9]+]]
132 function video_handlers.rumble(url) 132 function video_handlers.rumble(url)
133 if not ptn.matches(url) then 133 if not ptn.matches(url) then
134 return false 134 return false
135 end 135 end
136 video_iframe(url) 136 video_iframe(url)
137 return true 137 return true
138 end 138 end
139 end 139 end
140 do 140 do
141 local ptn = regex[[https://www.bitchute.com/video/([a-zA-Z0-9]+)/]] 141 local ptn = regex[[^\Qhttps://www.bitchute.com/video/\E([a-zA-Z0-9]+)/]]
142 function video_handlers.bitchute(url) 142 function video_handlers.bitchute(url)
143 local id = ptn.match(url) 143 local id = ptn.match(url)
144 if id == nil then 144 if id == nil then
145 return false 145 return false
146 end 146 end
148 video_iframe(url) 148 video_iframe(url)
149 return true 149 return true
150 end 150 end
151 end 151 end
152 do 152 do
153 local ptn = regex[[https://vimeo.com/([0-9]+)]] 153 local ptn = regex[[^\Qhttps://vimeo.com/\E([0-9]+)]]
154 function video_handlers.vimeo(url) 154 function video_handlers.vimeo(url)
155 local id = ptn.match(url) 155 local id = ptn.match(url)
156 if id == nil then 156 if id == nil then
157 return false 157 return false
158 end 158 end
160 video_iframe(url) 160 video_iframe(url)
161 return true 161 return true
162 end 162 end
163 end 163 end
164 do 164 do
165 local ptn = regex[[https://dai.ly/([a-z0-9]+)]] 165 local ptn = regex[[^\Qhttps://dai.ly/\E([a-z0-9]+)]]
166 function video_handlers.dailymotion(url) 166 function video_handlers.dailymotion(url)
167 local id = ptn.match(url) 167 local id = ptn.match(url)
168 if id == nil then 168 if id == nil then
169 return false 169 return false
170 end 170 end
172 video_iframe(url) 172 video_iframe(url)
173 return true 173 return true
174 end 174 end
175 end 175 end
176 do 176 do
177 local ptn = regex[[https://www.tiktok.com/[^/]+/video/([0-9]+)]] 177 local ptn = regex[[^\Qhttps://www.tiktok.com/\E[^/]+/video/([0-9]+)]]
178 function video_handlers.tiktok(url) 178 function video_handlers.tiktok(url)
179 local id = ptn.match(url) 179 local id = ptn.match(url)
180 if id == nil then 180 if id == nil then
181 return false 181 return false
182 end 182 end