Skip to content

Commit

Permalink
Merge pull request #9 from kiwilan/develop
Browse files Browse the repository at this point in the history
1.0.12
  • Loading branch information
ewilan-riviere authored Jun 15, 2023
2 parents 24b5ce3 + 29304b0 commit 02f2e28
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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.0.11",
"version": "1.0.12",
"keywords": [
"php",
"ebook",
Expand Down
28 changes: 28 additions & 0 deletions src/Tools/MetaTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected function __construct(
protected ?string $serieSlugLang = null,

protected ?string $slugSortWithSerie = null,
protected ?string $uniqueFilename = null,
) {
}

Expand Down Expand Up @@ -74,6 +75,7 @@ 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 @@ -135,6 +137,14 @@ public function slugSortWithSerie(): string
return $this->slugSortWithSerie;
}

/**
* Get unique filename, like `jean-m-auel-earths-children-01-clan-of-the-cave-bear-en`.
*/
public function uniqueFilename(): string
{
return $this->uniqueFilename;
}

/**
* Try to get sort title.
* Example: `collier-de-la-reine` from `Le Collier de la Reine`.
Expand Down Expand Up @@ -196,6 +206,24 @@ private function generateSlug(string $title, ?string $type, ?string $language):
return $this->setSlug($title.' '.$type.' '.$language);
}

/**
* Generate unique filename.
*/
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;
$title = $this->setSlug($ebook->title());
$language = $this->setSlug($ebook->language());

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

return $filename;
}

public function toArray(): array
{
return [
Expand Down
1 change: 1 addition & 0 deletions tests/MetaTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
expect($meta->serieSlugSort())->toBe('a-comme-association');
expect($meta->serieSlugLang())->toBe('a-comme-association-epub-fr');
expect($meta->slugSortWithSerie())->toBe('a-comme-association-01_pale-lumiere-des-tenebres');
expect($meta->uniqueFilename())->toBe('jean-m-auel-a-comme-association-01-la-pale-lumiere-des-tenebres-fr');
});

0 comments on commit 02f2e28

Please sign in to comment.