2017 © Pedro PelĂĄez
 

library essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

image

essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  • Thursday, June 14, 2018
  • by fg
  • Repository
  • 37 Watchers
  • 648 Stars
  • 104,445 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 67 Forks
  • 17 Open issues
  • 32 Versions
  • 9 % Grown

The README.md

Essence, (*1)

Build status Scrutinizer Code Quality Code Coverage Total downloads, (*2)

Essence is a simple PHP library to extract media information from websites, like youtube videos, twitter statuses or blog articles., (*3)

If you were already using Essence 2.x.x, you should take a look at the migration guide., (*4)

Installation

composer require essence/essence

Example

Essence is designed to be really easy to use. Using the main class of the library, you can retrieve information in just those few lines:, (*5)

$Essence = new Essence\Essence();
$Media = $Essence->extract('http://www.youtube.com/watch?v=39e3KYAmXK4');

if ($Media) {
    // That's all, you're good to go !
}

Then, just do anything you want with the data:, (*6)

```html+php

title; ?>

By authorName; ?>, (*8)

, (*7)

<div class="player">
    <?php echo $Media->html; ?>
</div>

, (*9)


What you get ------------ Using Essence, you will mainly interact with Media objects. Media is a simple container for all the information that are fetched from an URL. Here are the default properties it provides: * type * version * url * title * description * authorName * authorUrl * providerName * providerUrl * cacheAge * thumbnailUrl * thumbnailWidth * thumbnailHeight * html * width * height These properties were gathered from the OEmbed and OpenGraph specifications, and merged together in a united interface. Based on such standards, these properties should be a solid starting point. However, "non-standard" properties can and will also be setted. Here is how you can manipulate the Media properties: ```php // through dedicated methods if (!$Media->has('foo')) { $Media->set('foo', 'bar'); } $value = $Media->get('foo'); // or directly like a class attribute $Media->customValue = 12;

Note that Essence will always try to fill the html property when it is not available., (*10)

Advanced usage

The Essence class provides some useful utility functions to ensure you will get some information., (*11)

Extracting URLs

The crawl() and crawlUrl() methods let you crawl extractable URLs from a web page, either directly from its source, or from its URL (in which case Essence will take care of fetching the source)., (*12)

For example, here is how you could get the URL of all videos in a blog post:, (*13)

$urls = $Essence->crawlUrl('http://www.blog.com/article');
array(2) {
    [0] => 'http://www.youtube.com/watch?v=123456',
    [1] => 'http://www.dailymotion.com/video/a1b2c_lolcat-fun'
}



You can then get information from all the extracted URLs: ```php $medias = $Essence->extractAll($urls);

array(2) { ['http://www.youtube.com/watch?v=123456'] => object(Media) {} ['http://www.dailymotion.com/video/a1b2c_lolcat-fun'] => object(Media) {} }, (*14)


### Replacing URLs in text Essence can replace any extractable URL in a text by information about it. By default, any URL will be replaced by the `html` property of the found Media. ```php echo $Essence->replace('Look at this: http://www.youtube.com/watch?v=123456');

```html Look at this: , (*15)


But you can do more by passing a callback to control which information will replace the URL: ```php echo $Essence->replace($text, function($Media) { return <<<HTML <p class="title">$Media->title</p> <div class="player">$Media->html</div> HTML; });

```html Look at this: , (*16)

Video title, (*17)


This makes it easy to build rich templates or even to integrate a templating engine: ```php echo $Essence->replace($text, function($Media) use ($TwigTemplate) { return $TwigTemplate->render($Media->properties()); });

Configuring providers

It is possible to pass some options to the providers., (*18)

For example, OEmbed providers accepts the maxwidth and maxheight parameters, as specified in the OEmbed spec., (*19)

$options = [
    'maxwidth' => 800,
    'maxheight' => 600
];

$Media = $Essence->extract($url, $options);
$medias = $Essence->extractAll($urls, $options);
$text = $Essence->replace($text, null, $options);

Other providers will just ignore the options they don't handle., (*20)

Configuration

Essence currently supports 68 specialized providers:, (*21)

23hq                Deviantart          Kickstarter         Sketchfab
Animoto             Dipity              Meetup              SlideShare
Aol                 Dotsub              Mixcloud            SoundCloud
App.net             Edocr               Mobypicture         SpeakerDeck
Bambuser            Flickr              Nfb                 Spotify
Bandcamp            FunnyOrDie          Official.fm         Ted
Blip.tv             Gist                Polldaddy           Twitter
Cacoo               Gmep                PollEverywhere      Ustream
CanalPlus           HowCast             Prezi               Vhx
Chirb.it            Huffduffer          Qik                 Viddler
CircuitLab          Hulu                Rdio                Videojug
Clikthrough         Ifixit              Revision3           Vimeo
CollegeHumor        Ifttt               Roomshare           Vine
Coub                Imgur               Sapo                Wistia
CrowdRanking        Instagram           Screenr             WordPress
DailyMile           Jest                Scribd              Yfrog
Dailymotion         Justin.tv           Shoudio             Youtube

Plus the OEmbed and OpenGraph providers, which can be used to extract any URL., (*22)

You can configure these providers on instanciation:, (*23)

$Essence = new Essence\Essence([
    // the SoundCloud provider is an OEmbed provider with a specific endpoint
    'SoundCloud' => Essence\Di\Container::unique(function($C) {
        return $C->get('OEmbedProvider')->setEndpoint(
            'http://soundcloud.com/oembed?format=json&url=:url'
        );
    }),

    'filters' => [
        // the SoundCloud provider will be used for URLs that matches this pattern
        'SoundCloud' => '~soundcloud\.com/[a-zA-Z0-9-_]+/[a-zA-Z0-9-]+~i'
    ]
]);

You can also disable the default ones:, (*24)

$Essence = new Essence\Essence([
    'filters' => [
        'SoundCloud' => false
    ]
]);

You will find the default configuration in the standard DI container of Essence (see the following part)., (*25)

Customization

Almost everything in Essence can be configured through dependency injection. Under the hoods, the constructor uses a dependency injection container to return a fully configured instance of Essence., (*26)

To customize the Essence behavior, the easiest way is to configure injection settings when building Essence:, (*27)

$Essence = new Essence\Essence([
    // the container will return a unique instance of CustomHttpClient
    // each time an HTTP client is needed
    'Http' => Essence\Di\Container::unique(function() {
        return new CustomHttpClient();
    })
]);

The default injection settings are defined in the Standard container class., (*28)

Try it out

Once you've installed essence, you should try to run ./cli/essence.php in a terminal. This script allows you to test Essence quickly:, (*29)

# will fetch and print information about the video
./cli/essence.php extract http://www.youtube.com/watch?v=4S_NHY9c8uM

# will fetch and print all extractable URLs found at the given HTML page
./cli/essence.php crawl http://www.youtube.com/watch?v=4S_NHY9c8uM

Third-party libraries

If you're interested in embedding videos, you should take a look at the Multiplayer lib. It allows you to build customizable embed codes painlessly:, (*30)

$Multiplayer = new Multiplayer\Multiplayer();

if ($Media->type === 'video') {
    echo $Multiplayer->html($Media->url, [
        'autoPlay' => true,
        'highlightColor' => 'BADA55'
    ]);
}

The Versions

14/06 2018

dev-master

9999999-dev http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

14/06 2018

3.5.2

3.5.2.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

15/10 2017

3.5.1

3.5.1.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

28/09 2017

3.5.0

3.5.0.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

03/06 2017

3.4.0

3.4.0.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

20/09 2016

3.3.0

3.3.0.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

17/08 2016

2.0.x-dev

2.0.9999999.9999999-dev http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

17/08 2016

2.6.1

2.6.1.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

27/07 2016

3.2.0

3.2.0.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

14/02 2016

3.1.1

3.1.1.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

03/10 2015

3.1.0

3.1.0.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

09/08 2015

3.0.0

3.0.0.0 http://github.com/essence/essence

Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

05/04 2015

dev-version-3.0.0

dev-version-3.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

 

media oembed opengraph embed

25/10 2014

2.5.2

2.5.2.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

20/10 2014

2.5.1

2.5.1.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

29/03 2014

2.4.0

2.4.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

08/03 2014

2.3.0

2.3.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

22/02 2014

2.2.1

2.2.1.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

23/11 2013

2.2.0

2.2.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

27/08 2013

2.1.0

2.1.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

25/08 2013

2.0.1

2.0.1.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

03/08 2013

2.0.0

2.0.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-curl *

 

media oembed opengraph embed

25/06 2013

1.4.1

1.4.1.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0
  • ext-curl *

 

media oembed opengraph embed

14/04 2013

1.4.0

1.4.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

26/03 2013

1.3.3

1.3.3.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

24/03 2013

1.3.2

1.3.2.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

24/03 2013

1.3.1

1.3.1.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

18/03 2013

1.3.0

1.3.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

15/03 2013

1.2.0

1.2.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

13/03 2013

1.1.0

1.1.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

08/03 2013

1.0.1

1.0.1.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed

03/03 2013

1.0.0

1.0.0.0 http://github.com/felixgirault/essence

Extracts informations about medias on the web, like youtube videos, twitter statuses or blog articles.

  Sources   Download

The Requires

  • php >=5.3.0

 

media oembed opengraph embed