oscarotero / Embed

Get info from any web service or page
MIT License
2.08k stars 310 forks source link

Add option to fetch OEmbed only #528

Closed nerg4l closed 9 months ago

nerg4l commented 9 months ago

I think it would be a great addition if there would be an option to fetch OEmbed information only. At the moment, there will be a call to the original URL and then when a value of \Embed\OEmbed is accessed, there will be a new HTTP call to fetch the JSON document.

At the moment the only workaround I could find is to do the following:

$url = 'https://www.youtube.com/watch?v=jNQXAC9IVRw';
new OEmbed(new Extractor(new Uri($url), $factory->createRequest("GET", $url), $factory->createResponse(), new Crawler()))

The main problem I think is the coupling with \Embed\Extractor.

If this is something that not planned, that's not a problem.

oscarotero commented 9 months ago

The initial request to the original URL is to resolve redirects, ensure the URL exists and it's valid, etc.

If you only want the OEmbed data, I think your workaround is the only way. Note that there are some extractors adapted to specific sites, so maybe you should use the ExtractorFactory class (https://github.com/oscarotero/Embed/blob/master/src/ExtractorFactory.php).

nerg4l commented 9 months ago

I thought that I didn't need to follow the redirections in my case and that the oEmbed would be enough but I was wrong. It's good as is.