Add human title to metadata

Most of the time meta data (from my source) has the season title as
title.
Instead use episode title with episode number.
This commit is contained in:
Daniel Siepmann 2020-10-05 11:53:47 +02:00
parent 566b73ee04
commit 5838745b96
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 41 additions and 11 deletions

View file

@ -96,7 +96,7 @@ class Cutting
$command = sprintf(
'ffmpeg -y -f concat -safe 0 -i %s -c copy'
. ' -f ffmetadata -i %s -c copy -map_metadata 1'
// . ' -metadata Title="$episodeTitle"'
. ' -metadata Title=' . escapeshellarg($this->video->getTitleForHumans())
. ' %s',
escapeshellarg($this->getConcatFilename()),
escapeshellarg($this->getMetadataFilename()),

View file

@ -62,23 +62,29 @@ class VideoInfo
return $parts[count($parts) - 2];
}
public function getTitleForHumans(): string
{
$title = ucwords(str_replace('-', ' ', $this->getTitle()));
if ($this->hasEpisode()) {
$title = str_pad($this->getEpisodeNumber(), 2, '0', STR_PAD_LEFT) . ' - ' . $title;
}
return $title;
}
public function getTargetFilePath(): string
{
$folderParts = [];
$filenameParts = [];
$folderParts[] = $this->getSeries();
if ($this->hasSeason()) {
$folderParts[] = 'Staffel-' . str_pad($this->getSeasonNumber(), 2, '0', STR_PAD_LEFT);
}
if ($this->hasEpisode()) {
$filenameParts[] = str_pad($this->getEpisodeNumber(), 2, '0', STR_PAD_LEFT);
}
$filenameParts[] = ucwords(str_replace('-', ' ', $this->getTitle()));
return implode(DIRECTORY_SEPARATOR, $folderParts)
. DIRECTORY_SEPARATOR
. implode('-', $filenameParts)
. $this->getTitleForHumans()
. '.' . $this->getExtension();
}

View file

@ -222,12 +222,13 @@ class CuttingTest extends TestCase
/**
* @test
*/
public function generatesCommandForGeneratingVideo(): void
public function generatesCommandForGeneratingVideoWithCustomTitle(): void
{
$video = $this->prophesize(VideoInfo::class);
$video->getTargetFilePath()->willReturn('Series-Name/Series-01/10-episode title.mp4');
$video->getOriginalFilenameWithSuffix('concat')->willReturn('Series-Name_Series-01_episode-title-01-concat.mp4');
$video->getOriginalFilenameWithSuffix('metadata')->willReturn('Series-Name_Series-01_episode-title-01-metadata.mp4');
$video->getTitleForHumans()->willReturn('01 - Episode Title');
$subject = new Cutting(
$video->reveal()
@ -238,7 +239,7 @@ class CuttingTest extends TestCase
static::assertSame(
'ffmpeg -y -f concat -safe 0 -i \'/tmp/Series-Name_Series-01_episode-title-01-concat.txt\' -c copy'
. ' -f ffmetadata -i \'/tmp/Series-Name_Series-01_episode-title-01-metadata.txt\' -c copy -map_metadata 1'
// . ' -metadata Title="$episodeTitle"'
. ' -metadata Title=\'01 - Episode Title\''
. ' \'Series-Name/Series-01/10-episode title.mp4\'',
$command->getCommandLine()
);

View file

@ -167,6 +167,29 @@ class VideoInfoTest extends TestCase
);
}
/**
* @test
* @dataProvider possibleFilenames
*/
public function returnsHumanTitle(
string $filename,
string $expectedTargetFilePath
): void {
$subject = new VideoInfo(
$filename,
'05:20.1',
'32:30.30',
[]
);
$file = new \SplFileInfo($expectedTargetFilePath);
static::assertSame(
$file->getBasename('.' . $file->getExtension()),
$subject->getTitleForHumans()
);
}
public function possibleFilenames(): array
{
return [