Skip to content

Commit

Permalink
Fix error when YouTube API doesn't return video duration (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
VerifiedJoseph authored Nov 3, 2024
1 parent 2fbd541 commit 9f2223f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
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

0 comments on commit 9f2223f

Please sign in to comment.