/**
  *	Fetches informations about the given URL.
  *
  *	@todo Error reporting.
  *	@param string $url URL to fetch informations from.
  *	@param array $options Custom options to be interpreted by a provider.
  *	@return Essence\Media Embed informations.
  */
 public function extract($url, array $options = [])
 {
     $providers = $this->_Collection->providers($url);
     foreach ($providers as $Provider) {
         try {
             return $Provider->extract($url, $options);
         } catch (Exception $Exception) {
             // ...
         }
     }
     return null;
 }
 /**
  *	Filters the given URLs to return only the extractable ones.
  *
  *	@param array $urls URLs to filter.
  *	@return array Filtered URLs.
  */
 protected function _filterUrls(array $urls)
 {
     $urls = array_filter($urls, function ($url) {
         return $this->_Collection->hasProvider($url);
     });
     return array_values($urls);
 }
Beispiel #3
0
 /**
  *	Sets the default properties.
  */
 public function __construct(array $properties = [])
 {
     $this->_properties = $properties + ['providers' => ESSENCE_DEFAULT_PROVIDERS, 'Cache' => Container::unique(function () {
         return new VolatileCacheEngine();
     }), 'HttpUserAgent' => 'Essence', 'Http' => Container::unique(function ($C) {
         $Http = function_exists('curl_init') ? new CurlHttpClient() : new NativeHttpClient();
         $Http->setUserAgent($C->get('HttpUserAgent'));
         return $Http;
     }), 'Dom' => Container::unique(function () {
         return new NativeDomParser();
     }), 'Log' => Container::unique(function () {
         return new NullLogger();
     }), 'Preparator' => Container::unique(function () {
         return new Preparator();
     }), 'OEmbed' => function ($C) {
         return new OEmbed($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('Preparator'));
     }, 'Vimeo' => function ($C) {
         return new Vimeo($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('Preparator'));
     }, 'YoutubePreparator' => Container::unique(function () {
         return new YoutubePreparator();
     }), 'Youtube' => function ($C) {
         return new Youtube($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('YoutubePreparator'));
     }, 'OpenGraph' => function ($C) {
         return new OpenGraph($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('Preparator'));
     }, 'BandcampPreparator' => Container::unique(function () {
         return new BandcampPreparator();
     }), 'Bandcamp' => function ($C) {
         return new OpenGraph($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('BandcampPreparator'));
     }, 'VinePreparator' => Container::unique(function () {
         return new VinePreparator();
     }), 'Vine' => function ($C) {
         return new OpenGraph($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('VinePreparator'));
     }, 'Collection' => function ($C) {
         $Collection = new Collection($C);
         $Collection->load($C->get('providers'));
         return $Collection;
     }, 'Essence' => function ($C) {
         return new Essence($C->get('Collection'), $C->get('Cache'), $C->get('Http'), $C->get('Dom'), $C->get('Log'));
     }];
 }
Beispiel #4
0
 /**
  *	Configures the providers collection.
  */
 protected function _setupCollection()
 {
     $this->configure(['Collection.providers' => dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'providers.json', 'Collection' => Container::unique(function ($C) {
         $Collection = new Collection($C);
         $Collection->load($C->get('Collection.providers'));
         return $Collection;
     })]);
 }