Skip to content

Commit

Permalink
Merge pull request #66 from kiwilan/develop
Browse files Browse the repository at this point in the history
v2.3.6
  • Loading branch information
ewilan-riviere authored Feb 4, 2024
2 parents 5a088f9 + 0e8c55d commit fdd1110
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 35 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ use Kiwilan\Ebook\Ebook;
$ebook = Ebook::read('path/to/ebook.epub');
$metaTitle = $ebook->getMetaTitle(); // ?MetaTitle

$metaTitle->getSlug(); // string => slug title, like `lord-of-the-rings-01-fellowship-of-the-ring-j-r-r-tolkien-1954-epub-en`
$metaTitle->getSlug(); // string => slug title, like `lord-of-the-rings-en-01-fellowship-of-the-ring-j-r-r-tolkien-1954-epub`
$metaTitle->getSlugSimple(); // string => slug title simple, like `the-fellowship-of-the-ring`
$metaTitle->getSeriesSlug(); // ?string => slug series title, like `lord-of-the-rings-j-r-r-tolkien-epub-en`
$metaTitle->getSeriesSlug(); // ?string => slug series title, like `lord-of-the-rings-en-j-r-r-tolkien-epub`
$metaTitle->getSeriesSlugSimple(); // ?string => slug series title simple, like `the-lord-of-the-rings`
```

Expand Down Expand Up @@ -247,17 +247,19 @@ For audiobooks, you have to install seperately [`kiwilan/php-audio`](https://git

Properties of `Audio::class` are:

| **Ebook** | **Audio** |
| ----------- | ------------ |
| title | title |
| author | artist |
| description | description |
| tags | artist |
| series | album |
| volume | trackNumber |
| publishDate | artist |
| copyright | creationDate |
| author | encodingBy |
| **Ebook** | **Audio** |
| ------------- | ------------------------ |
| `title` | `title` |
| `author` | `artist` |
| `description` | `description` |
| `publisher` | `albumArtist` |
| `series` | `album` |
| `volume` | `trackNumber` |
| `publishDate` | `artist` |
| `copyright` | `year` or `creationDate` |
| `copyright` | `encodingBy` |
| `tags` | `genre` |
| `language` | `language` |

You can find all metadata into `getExtras()` array of `Ebook::class`.

Expand Down
4 changes: 2 additions & 2 deletions 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, comics and audiobooks.",
"version": "2.3.5",
"version": "2.3.6",
"keywords": [
"php",
"ebook",
Expand Down Expand Up @@ -43,7 +43,7 @@
"kiwilan/php-xml-reader": "^1.0.11"
},
"require-dev": {
"kiwilan/php-audio": "^3.0.01",
"kiwilan/php-audio": "^3.0.06",
"laravel/pint": "^1.7",
"pestphp/pest": "^1.20",
"pestphp/pest-plugin-parallel": "^1.2",
Expand Down
17 changes: 16 additions & 1 deletion src/Formats/Audio/AudiobookModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,23 @@ public function toEbook(): Ebook
$this->ebook->setAuthors([$author]);
$this->ebook->setPublisher($audio->getAlbumArtist());
$this->ebook->setDescription($description);
$this->ebook->setTags([$audio->getGenre()]);

$tags = $audio->getGenre();
if (str_contains($tags, ';') || str_contains($tags, ',')) {
$tags = preg_split('/[;,]/', $tags);
} else {
$tags = [$tags];
}

$tags = array_map('trim', $tags);
$tags = array_map('ucfirst', $tags);
$this->ebook->setTags($tags);

$this->ebook->setSeries($audio->getAlbum());
$this->ebook->setVolume($audio->getTrackNumber());
$this->ebook->setPublishDate($date);
$this->ebook->setCopyright($audio->getEncodingBy());
$this->ebook->setLanguage($audio->getLanguage());
$this->ebook->setExtras([
'title' => $audio->getTitle(),
'artist' => $audio->getArtist(),
Expand All @@ -101,6 +113,8 @@ public function toEbook(): Ebook
'discNumber' => $audio->getDiscNumber(),
'isCompilation' => $audio->isCompilation(),
'encoding' => $audio->getEncoding(),
'podcastDescription' => $audio->getPodcastDescription(),
'language' => $audio->getLanguage(),
'lyrics' => $audio->getLyrics(),
'stik' => $audio->getStik(),
'duration' => $audio->getDuration(),
Expand Down Expand Up @@ -131,6 +145,7 @@ public function toArray(): array
{
return [
'audio' => $this->audio,
'tags' => $this->ebook->getAudio()->getTags(),
];
}

Expand Down
30 changes: 20 additions & 10 deletions src/Models/MetaTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,25 @@ private function parse(Ebook $ebook): static
return $this;
}

$this->slug = $this->generateSlug([
$seriesDeterminer,
$volume,
$titleDeterminer,
$author,
$year,
$extension,
$language,
]);
if ($ebook->getSeries()) {
$this->slug = $this->generateSlug([
$seriesDeterminer,
$language,
$volume,
$titleDeterminer,
$author,
$year,
$extension,
]);
} else {
$this->slug = $this->generateSlug([
$titleDeterminer,
$language,
$author,
$year,
$extension,
]);
}
$this->slugSimple = $this->generateSlug([$title]);

if (! $ebook->getSeries()) {
Expand All @@ -341,9 +351,9 @@ private function parse(Ebook $ebook): static

$this->seriesSlug = $this->generateSlug([
$seriesDeterminer,
$language,
$author,
$extension,
$language,
]);
$this->seriesSlugSimple = $this->generateSlug([$series]);

Expand Down
5 changes: 3 additions & 2 deletions tests/AudiobookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$ebook = Ebook::read($path);

expect($ebook->getpath())->toBe($path);
expect($ebook->getTags())->toBeArray();

$metadata = $ebook->getParser();
expect($metadata->getAudiobook()->getAudio())->toBeArray();
Expand All @@ -26,7 +27,7 @@
->each(fn (Expectation $expectation) => expect($expectation->value)
->toBeInstanceOf(BookAuthor::class)
);
// expect($ebook->getLanguage())->toBe('en');
expect($ebook->getLanguage())->toBe('Language');
expect($ebook->getPublisher())->toBe('P1PDD & Mr Piouf');
expect($ebook->getExtra('comment'))->toBe('http://www.p1pdd.com');
expect($ebook->getSeries())->toBe('P1PDD Le conclave de Troie');
Expand All @@ -44,7 +45,7 @@
->toBeInstanceOf(BookAuthor::class)
);
expect($ebook->getPublisher())->toBe('Ewilan');
expect($ebook->getDescription())->toBe('Epic story about audiobooks.');
expect($ebook->getDescription())->toBe('Description');
expect($ebook->getExtra('comment'))->toBe('Do you want to extract an audiobook?');
expect($ebook->getSeries())->toBe('Audiobook Test');
expect($ebook->getVolume())->toBe(1);
Expand Down
4 changes: 2 additions & 2 deletions tests/EpubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
$ebook = Ebook::read(EPUB);
$meta = $ebook->getMetaTitle();

expect($meta->getSlug())->toBe('earths-children-01-clan-of-the-cave-bear-jean-m-auel-1980-epub-en');
expect($meta->getSeriesSlug())->toBe('earths-children-jean-m-auel-epub-en');
expect($meta->getSlug())->toBe('earths-children-en-01-clan-of-the-cave-bear-jean-m-auel-1980-epub');
expect($meta->getSeriesSlug())->toBe('earths-children-en-jean-m-auel-epub');

expect($meta->toArray())->toBeArray();
expect($meta->__toString())->toBeString();
Expand Down
10 changes: 5 additions & 5 deletions tests/MetaTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
$ebook->setAuthorMain(new BookAuthor('Pierre Bottero'));
$meta = MetaTitle::make($ebook);

expect($meta->getSlug())->toBe('a-comme-association-01-pale-lumiere-des-tenebres-pierre-bottero-1980-epub-fr');
expect($meta->getSlug())->toBe('a-comme-association-fr-01-pale-lumiere-des-tenebres-pierre-bottero-1980-epub');
expect($meta->getSlugSimple())->toBe('la-pale-lumiere-des-tenebres');
expect($meta->getSeriesSlug())->toBe('a-comme-association-pierre-bottero-epub-fr');
expect($meta->getSeriesSlug())->toBe('a-comme-association-fr-pierre-bottero-epub');
expect($meta->getSeriesSlugSimple())->toBe('a-comme-association');

$ebook->setTitle('The Fellowship of the Ring');
Expand All @@ -26,9 +26,9 @@
$ebook->setAuthorMain(new BookAuthor('J. R. R. Tolkien'));
$meta = MetaTitle::make($ebook);

expect($meta->getSlug())->toBe('lord-of-the-rings-01-fellowship-of-the-ring-j-r-r-tolkien-1980-epub-en');
expect($meta->getSlug())->toBe('lord-of-the-rings-en-01-fellowship-of-the-ring-j-r-r-tolkien-1980-epub');
expect($meta->getSlugSimple())->toBe('the-fellowship-of-the-ring');
expect($meta->getSeriesSlug())->toBe('lord-of-the-rings-j-r-r-tolkien-epub-en');
expect($meta->getSeriesSlug())->toBe('lord-of-the-rings-en-j-r-r-tolkien-epub');
expect($meta->getSeriesSlugSimple())->toBe('the-lord-of-the-rings');

$ebook->setTitle('Artemis');
Expand All @@ -38,7 +38,7 @@
$ebook->setAuthorMain(new BookAuthor('Andy Weir'));
$meta = MetaTitle::make($ebook);

expect($meta->getSlug())->toBe('artemis-andy-weir-1980-epub-en');
expect($meta->getSlug())->toBe('artemis-en-andy-weir-1980-epub');
expect($meta->getSlugSimple())->toBe('artemis');
expect($meta->getSeriesSlug())->toBeNull();
expect($meta->getSeriesSlugSimple())->toBeNull();
Expand Down
Binary file modified tests/media/audiobook-test-1.mp3
Binary file not shown.
Binary file modified tests/media/audiobook-test-2.mp3
Binary file not shown.
Binary file modified tests/media/audiobook-test.m4b
Binary file not shown.
Binary file modified tests/media/audiobook.m4b
Binary file not shown.
Binary file modified tests/media/audiobook.mp3
Binary file not shown.

0 comments on commit fdd1110

Please sign in to comment.