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:
parent
566b73ee04
commit
5838745b96
4 changed files with 41 additions and 11 deletions
|
@ -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()),
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
|
|
|
@ -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 [
|
||||
|
@ -176,11 +199,11 @@ class VideoInfoTest extends TestCase
|
|||
],
|
||||
'Series no seasons' => [
|
||||
'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' => [
|
||||
'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',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue