diff --git a/src/Panorama/Video/Dailymotion.php b/src/Panorama/Video/Dailymotion.php index 6491e34..4a2180d 100644 --- a/src/Panorama/Video/Dailymotion.php +++ b/src/Panorama/Video/Dailymotion.php @@ -106,28 +106,29 @@ public function getEmbedUrl() */ public function getEmbedHTML($options = []) { - if (!isset($this->embedHTML)) { - $defaultOptions = ['width' => 560, 'height' => 349]; - $options = array_merge($defaultOptions, $options); - - // convert options into - $htmlOptions = ''; - if (count($options) > 0) { - foreach ($options as $key => $value) { - if (in_array($key, ['width', 'height'])) { - continue; - } - $htmlOptions .= '&'.$key.'='.$value; + if (isset($this->embedHTML)) { + return $this->embedHTML; + } + $defaultOptions = ['width' => 560, 'height' => 349]; + $options = array_merge($defaultOptions, $options); + + // convert options into + $htmlOptions = ''; + if (count($options) > 0) { + foreach ($options as $key => $value) { + if (in_array($key, ['width', 'height'])) { + continue; } + $htmlOptions .= '&'.$key.'='.$value; } - - $this->embedHTML = ""; } + $this->embedHTML = ""; + return $this->embedHTML; } @@ -169,43 +170,47 @@ public function getService() */ public function getVideoID() { - if (!isset($this->videoId)) { - $urlParts = parse_url($this->url); - $matches = preg_split('@/video/@', $urlParts['path']); - if (count($matches) > 0) { - $this->videoId = $matches[1]; - } else { - throw new \Exception("This url doesn't seem to be a Dailymotion video url"); - } + if (isset($this->videoId)) { + return $this->videoId; + } + + $urlParts = parse_url($this->url); + $matches = preg_split('@/video/@', $urlParts['path']); + if (count($matches) > 0) { + $this->videoId = $matches[1]; + } else { + throw new \Exception("This url doesn't seem to be a Dailymotion video url"); } return $this->videoId; } /* - * Extracts the meta tag from the page + * Extracts the meta property tag from the page * - * @return string the video ID for this video - * @throws Exception if url doesn't seem to be a Dailymotion video url + * @param string $name The property name + * @param string $default The default value to return if the property doesnt exists + * + * @return string The value of the property */ private function getByMetaProperty($name, $default = '') { $matched = preg_match_all('/property\=\"' . $name . '\" content=\"(?.*)\"/i', $this->page, $matches); - // var_export($name); - // var_export($matches); + return $matched ? (string) $matches['part'][0] : $default; } /* * Extracts the meta tag from the page * - * @return string the video ID for this video - * @throws Exception if url doesn't seem to be a Dailymotion video url + * @param string $name The property name + * @param string $default The default value to return if the property doesnt exists + * + * @return string The value of the property */ private function getByMetaName($name, $default = '') { $matched = preg_match_all('/name\=\"' . $name . '\" content=\"(?.*)\"/i', $this->page, $matches); - // var_export($name); - // var_export($matches); + return $matched ? (string) $matches['part'][0] : $default; } }