Git Product home page Git Product logo

embed's Introduction

Embed

Build Status Scrutinizer Code Quality

PHP library to get info and embed any web page (using oembed, opengraph, twitter-cards, etc). It's compatible with any web service (youtube, vimeo, flickr, instagram, etc). Has adapters to some webpages like (archive.org, github, deviantart, etc).

Requirements:

  • PHP 5.3+
  • Curl library installed
  • A PSR-0 compatible autoloader class

Usage:

//Load library (if you don't have composer or any psr-0 compatible loader):
include('Embed/autoloader.php');

//Load any url:
$info = Embed\Embed::create('https://www.youtube.com/watch?v=PP1xn5wHtxE');

//Get content info

$info->title; //The page title
$info->description; //The page description
$info->url; //The canonical url
$info->type; //The page type (link, video, image, rich)

$info->images; //List of all images found in the page
$info->image; //The image choosen as main image
$info->imageWidth; //The with of the main image
$info->imageHeight; //The height  of the main image

$info->code; //The code to embed the image, video, etc
$info->width; //The with of the embed code
$info->height; //The height of the embed code
$info->aspectRatio; //The aspect ratio (width/height)

$info->authorName; //The (video/article/image/whatever) author 
$info->authorUrl; //The author url

$info->providerName; //The provider name of the page (youtube, twitter, instagram, etc)
$info->providerUrl; //The provider url
$info->providerIcons; //All provider icons found in the page
$info->providerIcon; //The icon choosen as main icon

Available options

  • minImageWidth (int): Minimal image width used to choose the main image
  • minImageHeight (int): Minimal image height used to choose the main image
  • getBiggerImage (bool): Returns the bigger image as the main image (instead the first found). This can make the request slower because it need to check the size of all images.
  • getBiggerIcon (bool): The same than getBiggerImage but used to choose the main icon
  • facebookAccessToken (string): Used to get info from facebook pages when these pages are not public and a access token is required
  • soundcloudClientId (string): Used to get info of links from soundcloud. By default, it uses "YOUR_CLIENT_ID" that its a valid client id :P
  • embedlyKey (string): If it's defined, get info from embedly service (only for know supported services and if the page doesn't have its own oembed service)
  • oembedParameters (array): Extra GET parameters to the oembed requests.
  • facebookProvider (bool): If it's true, the facebook provider will be used to get the page information, that uses the facebook scrapping. By default is false because reduce the number of requests and facebook scrapping not always returns right results.
$options = array(
	'getBiggerImage' => true
);

$info = Embed\Embed::create('https://www.youtube.com/watch?v=PP1xn5wHtxE', $options);

Customize the request

Embed provides a RequestResolvers\Curl class to resolve all requests using the curl library. You can create your own request resolver class creating a class implementing the RequestResolverInterface.

//Set your own request resolver class:
Embed\Request::setDefaultResolver('MyCustomResolverClass');

You can configure also the following options of the default request resolver:

  • userAgent: User agent used in all requests. By default is "Embed PHP Library"
  • maxRedirections: The maximum amount of HTTP redirections to follow. By default is 20
  • connectionTimeout: The number of seconds to wait while trying to connect. Use 0 to wait indefinitely. By default is 10
  • timeout: The maximum number of seconds to allow execute the request. By default is 10

To set a new configuration:

Embed\Request::setResolverConfig(array(
	'userAgent' => 'My spider',
	'connectionTimeout' => 0
));

Or you can set your custom resolver class and the configuration at the same time:

Embed\Request::setDefaultResolver('MyCustomResolverClass', array(
	'userAgent' => 'My spider',
	'connectionTimeout' => 0
));

Online demo

http://oscarotero.com/embed/demo

Do you need help?

I can help you in HackHands: https://hackhands.com/oscarotero

Contributors

embed's People

Contributors

damienalexandre avatar jasny avatar michmich avatar oscarotero avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.