I guess I should clarify the video discovery process a bit. This happens because the plugin goes through providers one at a time to scan for videos, and stops at the first one it finds.
This means that it looks for the first YouTube video, then the first Vimeo video, then the first Facebook video, and so on. Originally the plugin was only designed for YouTube, but since adding other providers it doesn’t always get the first video. This may be fixed in the future but I want to make sure it doesn’t impact performance.
hi, thx for you reply.
Yes I know how it works, I can read code 🙂
That’s the whole point, currently your $regexes are compared to the $markup in the order you include the files.
First one included is the one for youtube, so if $markup has multiple embeds, let’s say first vimeo and second youtube, it will check first for youtube even if the embed is the last one. When it finds youtube, the match is done and it will stop, skipping the vimeo embed even if it’s the first one in the $markup.
This looks not correct to me, because the “featured” video should always be the first one that editors put in the markup.
Maybe you could try with PREG_OFFSET_CAPTURE and work with offsets but this would mean running all the regexes as first step then find the first offset, hence the performance concern you mentioned.
Meanwhile, you could consider to inform your users stating in your documentation that currently it correctly works just if you have one embed per post.
Btw I really appreciate the effort you made to have so many providers 🙂
Thx, regards
Andrea
That was the solution I was thinking, and it may be ready. Would like a little testing before release, so you can download and try out the dev branch here.
hi, yea seems it works
but you should check how many times the match is run
it seems to me the match is run multiple times, one for each of the 12 set of regexes that’s because you have 12 provider files included, each one with its class and its $regexes
maybe I would try to build a single array of all the regexes and run the match just once
Just released version 2.1 which includes the changes to ensure the video discovered is actually the first video.
great 🙂 upgraded and starred