dusterio / link-preview

Link preview generator for PHP with Laravel support
MIT License
123 stars 58 forks source link

`getPreviews()` fails with a YouTube or Vimeo URL #9

Closed benwilkins closed 7 years ago

benwilkins commented 7 years ago

When trying to get all previews for a YouTube or Vimeo URL, the request fails. It appears that the error is in Guzzle rather than your script, but perhaps there should be a way in the canParseLink method of the HtmlParser to check to see if it's a YouTube or Vimeo request first before trying to parse it.

Steps to reproduce (in Laravel):

Preview::setUrl('https://www.youtube.com/watch?v=mjMZwaqGPrc');
Preview::getPreviews(); // <-- script just dies without throwing exception.

Tracing this, I found that it is the HtmlParser that is causing the script to fail. Particularly, Guzzle dies when trying to make the request in HttpReader:93. The same thing happens with a Vimeo URL.

dusterio commented 7 years ago

Hmm, I have just tried the same link and it worked for me

Then I added a typo to the URL on purpose to see whether it will throw an exception and it did throw a ConnectionErrorException

LinkPreview catches Guzzle exceptions and throws its own exception, for the sake of convenience

benwilkins commented 7 years ago

That's weird. I wonder if it has to do with my Guzzle version? If I just try to do a GET request with Guzzle for a YouTube link without using this library - in other words just using Guzzle itself - the script just terminates with no exceptions thrown. What version of Guzzle are you using?

dusterio commented 7 years ago

@benwilkins It's in composer.json: "guzzlehttp/guzzle": "^6.1". Maybe your root SSL certificates are missing and your Guzzle cannot make any SSL requests at all? Having said that, it would probably still throw some exception

Also, are you 100% sure you are using the last/current version of link-preview?