Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when YouTube API doesn't return video duration #412

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function updateVideos($response): void
$key = array_search($item->id, array_column($this->data['videos'], 'id'));
$video = $this->data['videos'][$key];

$video['duration'] = Convert::videoDuration($item->contentDetails->duration);
$video['duration'] = Convert::videoDuration($item->contentDetails->duration ?? '');
$video['tags'] = array();
$video['premiere'] = false;
$video['stream'] = false;
Expand Down
2 changes: 1 addition & 1 deletion include/Helper/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Convert
public static function videoDuration(string $duration, bool $allowNegative = true)
{
$matches = array();
$text = 'Unknown';
$text = 'Unknown duration';

if (preg_match(self::$iso8601Regex, $duration, $matches)) {
foreach ($matches as &$match) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Helper/ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ConvertTest extends TestCase
*/
public function testVideoDuration(): void
{
self::assertEquals('Unknown', Convert::videoDuration('text'));
self::assertEquals('Unknown duration', Convert::videoDuration('text'));
self::assertEquals('03:45', Convert::videoDuration('PT3M45S'));
self::assertEquals('01:33:05', Convert::videoDuration('PT1H33M5S'));
self::assertEquals('10:00:05', Convert::videoDuration('PT10H5S'));
Expand Down