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( $command = sprintf(
'ffmpeg -y -f concat -safe 0 -i %s -c copy' 'ffmpeg -y -f concat -safe 0 -i %s -c copy'
. ' -f ffmetadata -i %s -c copy -map_metadata 1' . ' -f ffmetadata -i %s -c copy -map_metadata 1'
// . ' -metadata Title="$episodeTitle"' . ' -metadata Title=' . escapeshellarg($this->video->getTitleForHumans())
. ' %s', . ' %s',
escapeshellarg($this->getConcatFilename()), escapeshellarg($this->getConcatFilename()),
escapeshellarg($this->getMetadataFilename()), escapeshellarg($this->getMetadataFilename()),

View file

@ -62,23 +62,29 @@ class VideoInfo
return $parts[count($parts) - 2]; 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 public function getTargetFilePath(): string
{ {
$folderParts = []; $folderParts = [];
$filenameParts = [];
$folderParts[] = $this->getSeries(); $folderParts[] = $this->getSeries();
if ($this->hasSeason()) { if ($this->hasSeason()) {
$folderParts[] = 'Staffel-' . str_pad($this->getSeasonNumber(), 2, '0', STR_PAD_LEFT); $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) return implode(DIRECTORY_SEPARATOR, $folderParts)
. DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
. implode('-', $filenameParts) . $this->getTitleForHumans()
. '.' . $this->getExtension(); . '.' . $this->getExtension();
} }

View file

@ -222,12 +222,13 @@ class CuttingTest extends TestCase
/** /**
* @test * @test
*/ */
public function generatesCommandForGeneratingVideo(): void public function generatesCommandForGeneratingVideoWithCustomTitle(): void
{ {
$video = $this->prophesize(VideoInfo::class); $video = $this->prophesize(VideoInfo::class);
$video->getTargetFilePath()->willReturn('Series-Name/Series-01/10-episode title.mp4'); $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('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->getOriginalFilenameWithSuffix('metadata')->willReturn('Series-Name_Series-01_episode-title-01-metadata.mp4');
$video->getTitleForHumans()->willReturn('01 - Episode Title');
$subject = new Cutting( $subject = new Cutting(
$video->reveal() $video->reveal()
@ -238,7 +239,7 @@ class CuttingTest extends TestCase
static::assertSame( static::assertSame(
'ffmpeg -y -f concat -safe 0 -i \'/tmp/Series-Name_Series-01_episode-title-01-concat.txt\' -c copy' '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' . ' -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\'', . ' \'Series-Name/Series-01/10-episode title.mp4\'',
$command->getCommandLine() $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 public function possibleFilenames(): array
{ {
return [ return [
@ -176,11 +199,11 @@ class VideoInfoTest extends TestCase
], ],
'Series no seasons' => [ 'Series no seasons' => [
'filename' => 'Storage-Hunters_episode-2_trucker-auktion_hq.mp4', 'filename' => 'Storage-Hunters_episode-2_trucker-auktion_hq.mp4',
'expectedTargetFilePath' => 'Storage-Hunters/02-Trucker Auktion.mp4', 'expectedTargetFilePath' => 'Storage-Hunters/02 - Trucker Auktion.mp4',
], ],
'Series with seasons' => [ 'Series with seasons' => [
'filename' => 'The-Big-Bang-Theory_season-1_episode-12_das-jerusalem-projekt_hq.mp4', 'filename' => 'The-Big-Bang-Theory_season-1_episode-12_das-jerusalem-projekt_hq.mp4',
'expectedTargetFilePath' => 'The-Big-Bang-Theory/Staffel-01/12-Das Jerusalem Projekt.mp4', 'expectedTargetFilePath' => 'The-Big-Bang-Theory/Staffel-01/12 - Das Jerusalem Projekt.mp4',
], ],
]; ];
} }