Skip to content

Commit

Permalink
Fix: Allow sub-second/float timecode
Browse files Browse the repository at this point in the history
  • Loading branch information
Kajetan Dvoracek committed Jul 1, 2022
1 parent 826a5b3 commit 23ff2a0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Classes/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,10 @@ public static function renderFlashMessages($queue = 'kitodo.default.flashMessage
* - `hh:mm:ss`
* - `mm:ss`
* - `ss`
*
* Floating point values may be used.
*/
public static function timecodeToSeconds(string $timecode): int
public static function timecodeToSeconds(string $timecode): float
{
$parts = explode(":", $timecode);

Expand All @@ -669,7 +671,7 @@ public static function timecodeToSeconds(string $timecode): int

// Iterate through $parts reversely
for ($i = count($parts) - 1; $i >= 0; $i--) {
$totalSeconds += $factor * $parts[$i];
$totalSeconds += $factor * (float) $parts[$i];
$factor *= 60;
}

Expand Down
2 changes: 2 additions & 0 deletions Documentation/Features/MediaPlayer/METS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Only the begin is used.
</mets:fptr>
</mets:div>
Fractional timecodes (e.g., ``00:06:04.5``) may be used.

Multiple Sources
================

Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/MetsDocument/av_beispiel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@
</mets:div>
<mets:div ID="PHYS_0002" ORDER="2" TYPE="track">
<mets:fptr>
<mets:area FILEID="FILE_0000_DEFAULT_MOV" BEGIN="00:00:20" BETYPE="TIME" EXTENT="00:00:20" EXTTYPE="TIME"></mets:area>
<mets:area FILEID="FILE_0000_DEFAULT_MOV" BEGIN="00:00:20.5" BETYPE="TIME" EXTENT="00:00:20" EXTTYPE="TIME"></mets:area>
</mets:fptr>
<mets:fptr>
<mets:area FILEID="FILE_0000_DEFAULT_MP4" BEGIN="00:00:20" BETYPE="TIME" EXTENT="00:00:20" EXTTYPE="TIME"></mets:area>
<mets:area FILEID="FILE_0000_DEFAULT_MP4" BEGIN="00:00:20.5" BETYPE="TIME" EXTENT="00:00:20" EXTTYPE="TIME"></mets:area>
</mets:fptr>
</mets:div>
<mets:div ID="PHYS_0003" ORDER="3" TYPE="track">
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Common/MetsDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function canGetLogicalStructure()
'admId' => '',
'videoChapter' => [
'fileId' => 'FILE_0000_DEFAULT_MOV',
'timecode' => 20,
'timecode' => 20.5,
],
],
[
Expand Down
11 changes: 11 additions & 0 deletions Tests/Unit/Common/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ public function validXmlIsAccepted(): void
$this->assertIsObject($node);
$this->assertEquals('root', $node->getName());
}

/**
* @test
* @group timecodeToSeconds
*/
public function canConvertTimecode()
{
$this->assertEquals(20, Helper::timecodeToSeconds('20'));
$this->assertEquals(20.5, Helper::timecodeToSeconds('20.5'));
$this->assertEquals(80.5, Helper::timecodeToSeconds('1:20.5'));
}
}

0 comments on commit 23ff2a0

Please sign in to comment.