Example #1
0
 /**
  *	Fetches embed information from the given URL.
  *
  *	@param string $url URL to fetch informations from.
  *	@param array $options Custom options to be interpreted by the provider.
  *	@return Media|null Embed informations, or null if nothing could be
  *		fetched.
  */
 public final function embed($url, array $options = [])
 {
     $Media = null;
     if (is_callable($this->prepare)) {
         $url = call_user_func($this->prepare, $url, $options);
     }
     try {
         $Media = $this->_embed($url, $options);
         $Media->setDefault('url', $url);
         if ($this->_Preparator) {
             $this->_Preparator->complete($Media, $options);
         }
     } catch (Exception $Exception) {
         $this->_Logger->log(Logger::notice, "Unable to embed {$url}", ['exception' => $Exception]);
     }
     return $Media;
 }
Example #2
0
 /**
  *	Extracts URLs from an HTML source.
  *
  *	@param string $html The HTML source to extract URLs from.
  *	@return array Extracted URLs.
  */
 protected function _extractUrls($html)
 {
     $options = ['a' => 'href', 'embed' => 'src', 'iframe' => 'src'];
     try {
         $attributes = $this->_Dom->extractAttributes($html, $options);
     } catch (Exception $Exception) {
         $this->_Logger->log(Logger::notice, 'Error parsing HTML source', ['exception' => $Exception, 'html' => $html]);
         return [];
     }
     $urls = [];
     foreach ($options as $tagName => $attributeName) {
         foreach ($attributes[$tagName] as $tag) {
             $urls[] = $tag[$attributeName];
         }
     }
     return $urls;
 }