[vlc-devel] [PATCH 2/3] vimeo.lua: Improve URL probe function
Wilawar
chrcnt7 at swift-mail.com
Thu Nov 3 10:36:37 CET 2016
Because formatting screwed me twice again, I did it myself in Code::Blocks, line length limited to 112 chars.
Why don’t you just include 'www.' into the match strings, instead of gsub-ing away four characters?
Rather inefficient (not that it’d matter much at this point).
Also, your script would allow 'www.player.vimeo.com[…]' to pass although this domain does not exist,
as far as I could tell: I’ve searched, using Google, for 'www.player.vimeo.com', for the same with the
'inurl:' qualifier prepended, tried to go to this URL (which failed with the message 'Server nicht gefunden'
('Server not found')) and, to confirm the apparent name resolution failure, I ran these two queries:
'https://dnsquery.org/whois/www.player.vimeo.com', 'https://dnsquery.org/dnsquery/www.player.vimeo.com/ANY',
which yielded the authoritative result that this domain is, indeed, not registered. :)
(Yes, I did try hard not to fail, this time. ;) )
Then, string.match is overkill here, string.find would do the same job.
I do wonder why non-greedy expansion was chosen for the '/channels/' pattern. I changed it for good measure.
Doing a plain string search for the 'player' pattern can probably be argued about. It would skip the ugly
machinery that handles patterns, but it’s not a given that it’ll be faster for rejecting long URLs, as it
would run to the end instead of cutting it after the first few or maybe eight to nine characters.
Unfortunately, at least Lua 5.1.5 doesn’t seem to offer any function to efficiently search only subseqs.
After some hard deliberation, I decided not to put it into the patch, but here it is to copy and paste:
» ( sfind( path, "player.vimeo.com", 1, true ) == 1 ) « (this would replace the call to sfind there)
Last but not least, string.match should probably be put into a 'local' for a shard of the purest
micro-optimization glory one could attain in non-LuaJIT Lua. ;)
So, this is the changed code diff I propose, of course untested:
-- Probe function.
function probe()
+ local path = vlc.path
+ local sfind = string.find
return ( vlc.access == "http" or vlc.access == "https" )
- and ( string.match( vlc.path, "vimeo%.com/%d+$" )
- or string.match( vlc.path, "vimeo%.com/channels/(.-)/%d+$" )
- or string.match( vlc.path, "player%.vimeo%.com" ) )
+ and ( sfind( path, "^www%.vimeo%.com/%d+$", 1, false )
+ or sfind( path, "^www%.vimeo%.com/channels/(.+)/%d+$", 1, false )
+ or sfind( path, "^player%.vimeo%.com", 1, false ) )
-- do not match other addresses,
-- else we'll also try to decode the actual video url
end
--
http://www.fastmail.com - Access all of your messages and folders
wherever you are
More information about the vlc-devel
mailing list