diff options
| -rw-r--r-- | providers/Youtube.php | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/providers/Youtube.php b/providers/Youtube.php index b84ef77..7ec490d 100644 --- a/providers/Youtube.php +++ b/providers/Youtube.php @@ -43,18 +43,26 @@ class Youtube extends Rss { $cacheData[$video->id] = $video; } } + # do not cache 0-duration videos, they're future videos + $cacheData = array_filter($cacheData, [$this, '_getVideoDuration']); file_put_contents($cacheFile, serialize($cacheData)); return array_filter($cacheData, function($item) use($ids) { return in_array($item->id, $ids); }); } + private function _getVideoDuration($metadata) { + $duration = new \DateInterval($metadata->contentDetails->duration); + return $duration->h * 3600 + $duration->i * 60 + $duration->s; + } + private function _getVideoDurations($ids) { $metadata = $this->_getVideoMetadata($ids); $return = []; foreach ($ids as $id) { - $duration = new \DateInterval($metadata[$id]->contentDetails->duration); - $return[$id] = $duration->h * 3600 + $duration->i * 60 + $duration->s; + if (isset($metadata[$id])) { + $return[$id] = $this->_getVideoDuration($metadata[$id]); + } } return $return; } @@ -76,7 +84,8 @@ class Youtube extends Rss { } $items = array_filter($items, function($item) use($minDuration, $durations) { $videoID = $this->_getVideoID($item); - return $durations[$videoID] >= $minDuration; + return isset($durations[$videoID]) && + ($durations[$videoID] >= $minDuration); }); } |
