diff --git a/composer.json b/composer.json index 451825e..2b9057d 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Tools/MetaTitle.php b/src/Tools/MetaTitle.php index 768b562..83dda36 100644 --- a/src/Tools/MetaTitle.php +++ b/src/Tools/MetaTitle.php @@ -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; @@ -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; } @@ -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; diff --git a/tests/EbookTest.php b/tests/EbookTest.php index 122f9fa..6494a2b 100644 --- a/tests/EbookTest.php +++ b/tests/EbookTest.php @@ -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);