Skip to content

Commit

Permalink
function -> private static method
Browse files Browse the repository at this point in the history
  • Loading branch information
boyska committed Mar 7, 2024
1 parent 0365299 commit 968055c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions formats/M3uFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function stringify()
$m3uitem->bytes = $itemArray['enclosure']['length'];
}
if (isset($itemArray['itunes']) && isset($itemArray['itunes']['duration'])) {
$m3uitem->duration = parse_duration($itemArray['itunes']['duration']);
$m3uitem->duration = self::parseDuration($itemArray['itunes']['duration']);
}
if (isset($itemArray['title'])) {
$m3uitem->title = $itemArray['title'];
Expand All @@ -31,22 +31,22 @@ public function stringify()
}
return mb_convert_encoding($contents, $this->getCharset(), 'UTF-8');
}
}

/*
* parse_duration converts a string like "00:4:20" to 260
* allowing to convert duration as used in the itunes:duration tag to the number of seconds
*/
function parse_duration(string $duration_string): int
{
$seconds = 0;
$parts = explode(':', $duration_string);
for ($i = 0; $i < count($parts); $i++) {
$seconds += intval($parts[count($parts) - $i - 1]) * pow(60, $i);
/*
* parseDuration converts a string like "00:4:20" to 260
* allowing to convert duration as used in the itunes:duration tag to the number of seconds
*/
private static function parseDuration(string $duration_string): int
{
$seconds = 0;
$parts = explode(':', $duration_string);
for ($i = 0; $i < count($parts); $i++) {
$seconds += intval($parts[count($parts) - $i - 1]) * pow(60, $i);
}
return $seconds;
}
return $seconds;
}


class M3uItem
{
public $duration = null;
Expand Down

0 comments on commit 968055c

Please sign in to comment.