diff options
| author | emkael <emkael@tlen.pl> | 2026-09-05 14:54:50 +0200 |
|---|---|---|
| committer | emkael <emkael@tlen.pl> | 2026-09-05 14:54:50 +0200 |
| commit | ad6b96a581fc815b555f31e48716ce44c5df9075 (patch) | |
| tree | b293bb2f2e501579451a2ccfda535bc177466ff1 /providers/Youtube.php | |
| parent | 9fcd58aab29e53044fc786aed960ed93c7fde110 (diff) | |
YouTube duration filter and its 0-length videos quirks
Diffstat (limited to 'providers/Youtube.php')
| -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); }); } |
