Skip to content

Commit

Permalink
fixed ChapterHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed May 7, 2019
1 parent b529f12 commit 254ef54
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/library/M4bTool/Chapter/ChapterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ class ChapterHandler
{
// chapters are seen as numbered consecutively, if this ratio of all chapter names only differs by numeric values
const CHAPTER_REINDEX_RATIO = 0.75;
const CHAPTER_START_MAX_OFFSET_MS = 25;
const MIN_CHAPTER_LENGTH_MILLISECONDS = 60000;

const NO_REINDEXING = 1 << 0;
const USE_FILENAMES = 1 << 1;
const MIN_CHAPTER_LENGTH_MS = 600000;
/**
* @var MetaDataHandler
*/
Expand Down Expand Up @@ -204,16 +203,16 @@ private function splitChapterBySilence(Chapter $chapter, array $matchingSilences
continue;
}
$halfSilenceLengthMs = $silence->getLength()->milliseconds() / 2;
$chapterEndMs = $silence->getStart()->milliseconds() + min(static::CHAPTER_START_MAX_OFFSET_MS, $halfSilenceLengthMs);
$chapterCutPositionInMilliseconds = $silence->getStart()->milliseconds() + floor($halfSilenceLengthMs);

if ($chapterEndMs - $lastChapter->getStart()->milliseconds() < $desiredLength->milliseconds()) {
if ($chapterCutPositionInMilliseconds - $lastChapter->getStart()->milliseconds() < $desiredLength->milliseconds()) {
continue;
}

$lastChapter->setEnd(new TimeUnit($chapterEndMs));
$lastChapter->setEnd(new TimeUnit($chapterCutPositionInMilliseconds));
$splitChapters[] = $lastChapter;
$lastChapter = clone $chapter;
$lastChapter->setStart(clone $silence->getEnd());
$lastChapter->setStart(new TimeUnit($chapterCutPositionInMilliseconds));
}
$lastChapter->setEnd($chapter->getEnd());
$splitChapters[] = $lastChapter;
Expand All @@ -231,7 +230,7 @@ private function mergeNeedlessSplits(array $fixedSplitChapters)
}
$last = $fixedSplitChapters[$lastKey];

if ($last->getLength()->milliseconds() > static::MIN_CHAPTER_LENGTH_MS) {
if ($last->getLength()->milliseconds() > static::MIN_CHAPTER_LENGTH_MILLISECONDS) {
return $fixedSplitChapters;
}

Expand Down

0 comments on commit 254ef54

Please sign in to comment.