Skip to content

Commit

Permalink
Merge pull request #21 from kiwilan/develop
Browse files Browse the repository at this point in the history
1.3.33
  • Loading branch information
ewilan-riviere authored Jun 22, 2023
2 parents fb26ea9 + ea10245 commit 45f697a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kiwilan/php-ebook",
"description": "PHP package to read metadata and extract covers from eBooks (.epub, .cbz, .cbr, .cb7, .cbt, .pdf) and audiobooks (.mp3, .m4a, .m4b, .flac, .ogg).",
"version": "1.3.32",
"version": "1.3.33",
"keywords": [
"php",
"ebook",
Expand Down
19 changes: 14 additions & 5 deletions src/Tools/MetaTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private function setMetaTitle(Ebook $ebook): static
$this->slugLang = $this->generateSlug($title, $ebook->extension(), $language);

$this->slugSortWithSerie = $this->generateSortSerie($title, $series, $volume, $language);
$this->uniqueFilename = $this->generateUniqueFilename($ebook);

if (! $series) {
return $this;
Expand All @@ -75,7 +76,6 @@ private function setMetaTitle(Ebook $ebook): static
$this->serieSlug = $this->setSlug($series);
$this->serieSlugSort = $this->generateSortTitle($series, $language);
$this->serieSlugLang = $this->generateSlug($series, $ebook->extension(), $language);
$this->uniqueFilename = $this->generateUniqueFilename($ebook);

return $this;
}
Expand Down Expand Up @@ -212,14 +212,23 @@ private function generateSlug(string $title, ?string $type, ?string $language):
private function generateUniqueFilename(Ebook $ebook): string
{
$author = $this->setSlug($ebook->authorMain());
$series = $this->setSlug($ebook->series());
$volume = (string) $ebook->volume();
$volume = $volume = strlen($volume) < 2 ? '0'.$volume : $volume;
$filename = "{$author}";
if ($ebook->series()) {
$series = $this->setSlug($ebook->series());
$filename .= "-{$series}";
}
if ($ebook->volume()) {
$volume = (string) $ebook->volume();
$volume = $volume = strlen($volume) < 2 ? '0'.$volume : $volume;
$filename .= "-{$volume}";
}
$title = $this->setSlug($ebook->title());
$filename .= "-{$title}";
$language = $this->setSlug($ebook->language());
$filename .= "-{$language}";
$format = $this->setSlug($ebook->extension());
$filename .= "-{$format}";

$filename = "{$author}-{$series}-{$volume}-{$title}-{$language}-{$format}";
$filename = $this->setSlug($filename);

return $filename;
Expand Down
1 change: 1 addition & 0 deletions tests/EbookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

$metadata = $ebook->metadata();
expect($metadata)->toBeInstanceOf(EbookMetadata::class);
expect($ebook->metaTitle()->uniqueFilename())->toBeString();

if ($metadata->isEpub()) {
expect($metadata->epub())->toBeInstanceOf(EpubMetadata::class);
Expand Down

0 comments on commit 45f697a

Please sign in to comment.