WebDevStudios / Automatic-Featured-Images-from-Videos

If a YouTube or Vimeo video exists in the first few paragraphs of a post, automatically set the post's featured image to that vidoe's thumbnail.
33 stars 24 forks source link

Vimeo videos produce erroneous results (thumbnail from unrelated video is fetched) #45

Closed tnorthcutt closed 6 years ago

tnorthcutt commented 6 years ago

Edit: upon further testing, this is happening with all Vimeo videos for my use case, in my (admittedly limited) testing. Not sure why, but definitely not isolated to private videos.

It seems that in some cases, embedding a private video in a post results in a completely different video used to fetch a thumbnail. The only connection seems to be that the URL for the video used is the same as the private video URL, with the last character of the URL removed.

So on a post with https://vimeo.com/235253177 (note the double 7 at the end) in the content, the video fetched becomes https://vimeo.com/23525317 (note the single 7 at the end).

This of course produces extremely undesirable (though sometimes hilarious) results.

Any suggested strategies for mitigating this problem?

binarygary commented 6 years ago

Quick glance...it looks like https://github.com/WebDevStudios/Automatic-Featured-Images-from-Videos/blob/master/automatic-featured-images-from-videos.php#L192 Is only returning the first 8 characters...

I don't have time to test it this morning, but I think you could replace the conditional in wds_check_for_vimeo with:

if ( preg_match( '\/\/(.+\.)?(vimeo\.com)\/(\d*)', $content, $vimeo_matches ) ) {
        return $vimeo_matches[3] );
    }
tnorthcutt commented 6 years ago

Nice. Turns out it needs a delimiter; I added # like so:

if ( preg_match( '#\/\/(.+\.)?(vimeo\.com)\/(\d*)#', $content, $vimeo_matches ) ) {
    return $vimeo_matches[3];
}
tw2113 commented 6 years ago

Chances are the plugin was coded for a time when vimeo's id values were only 8 characters long, and they have since surpassed. Travis issued a PR with Gary's recommendation. Works for me :D