-
-
Save djonatanb/2346246 to your computer and use it in GitHub Desktop.
Save with time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function beforeSave($options = array()) | |
{ | |
foreach ($this->_youtube as $youtube) { | |
if (isset($this->data[$this->alias]) | |
&& isset($this->data[$this->alias][$youtube]) | |
) { | |
$matches = array(); | |
if (preg_match( | |
self::REGEX, $this->data[$this->alias][$youtube], $matches | |
)) { | |
$this->data[$this->alias][$youtube] = reset($matches); | |
$xml = file_get_contents('http://gdata.youtube.com/feeds/api/videos/' . reset($matches) ); | |
$search = preg_match("<yt:duration seconds=\'(.*?)\'\/>", $xml, $seconds); | |
$duration = $this->toMinutes($seconds[1]); | |
$this->data[$this->alias][$this->_duration[$youtube]] = $duration; | |
} | |
} | |
} | |
return parent::beforeSave($options); | |
} | |
public function toMinutes($seconds){ | |
$floor = floor( $seconds / 60 ); | |
return sprintf( "%02.2d:%02.2d:%02.2d", floor( $floor / 60 ), $floor, $seconds % 60 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment