Skip to content

Commit

Permalink
0.3.40
Browse files Browse the repository at this point in the history
- `EpubOpf` is now `OpfMetadata`, `CbaFormat` is now `CbaMetadata`
- add properties to `OpfMetadata` with `metadata`, `manifest`, `spine`, `guide`
- `MetaTitle` fix accent characters
- add tests
  • Loading branch information
ewilan-riviere committed May 8, 2023
1 parent 0db2a65 commit d52b386
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 57 deletions.
26 changes: 13 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@ All notable changes to `php-ebook` will be documented in this file.

## 0.3.32 - 2023-05-08

- MetaTitle `slugSortWithSerie` fix
- MetaTitle `slugSortWithSerie` fix

## 0.3.31 - 2023-05-05

- improve documentation
- improve documentation

## 0.3.30 - 2023-05-05

- make `slugSortWithSerie` always generated (if title)
- make `slugSortWithSerie` always generated (if title)

## 0.3.20 - 2023-05-05

- update `titleMeta` to `metaTitle`
- update `titleMeta` to `metaTitle`

## 0.3.10 - 2023-05-05

- add `titleMeta()` to `BookEntity` with extra infos with title slug and series slug
- move `ComicMeta` to `Kiwilan\Ebook\Entity\ComicMeta`
- add `titleMeta()` to `BookEntity` with extra infos with title slug and series slug
- move `ComicMeta` to `Kiwilan\Ebook\Entity\ComicMeta`

## 0.3.0 - 2023-05-05

- add `filename` to `Ebook`
- remove `path` from `BookEntity` (it's in `Ebook`)
- `Book` `manga` is default `UNKNOWN`
- add methods `toArray`, `toJson` and `__toString` to `Ebook`, `BookEntity`, `EpubOpf`, `CbaFormat`
- add `filename` to `Ebook`
- remove `path` from `BookEntity` (it's in `Ebook`)
- `Book` `manga` is default `UNKNOWN`
- add methods `toArray`, `toJson` and `__toString` to `Ebook`, `BookEntity`, `OpfMetadata`, `CbaMetadata`

## 0.2.10 - 2023-05-05

- add `words` property
- add `words` property

## 0.2.0 - 2023-05-05

- Move `BookEntity` `cover` to `Ebook`
- Move `BookEntity` `cover` to `Ebook`

## 0.1.01 - 2023-05-05

- Update `kiwilan/php-archive`
- Update `kiwilan/php-archive`

## 0.1.0 - 2023-04-01

Expand Down
44 changes: 31 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ composer require kiwilan/php-ebook

## Usage

With eBook files (`.epub`, `.cbz`, `.cbr`, `.cb7`, `.cbt`, `.pdf`)
With eBook files (`.epub`, `.cbz`, `.cba`, `.cbr`, `.cb7`, `.cbt`, `.pdf`)

```php
$ebook = Ebook::read('path/to/archive.epub');

$metadata = $ebook->metadata(); // EpubOpf|CbaFormat|null => metadata OPF for EPUB, metadata CBA for CBA
$metadata = $ebook->metadata(); // OpfMetadata|CbaMetadata|null => metadata OPF for EPUB, metadata CBA for CBA
$format = $book->format(); // epub, pdf, cba
$book = $ebook->book(); // ?BookEntity
$cover = $ebook->cover(bool $convertBase64 = true); // string => cover as string ($toString convert base64)
Expand All @@ -85,13 +85,31 @@ $extension = $ebook->extension(); // string
$hasMetadata = $ebook->hasMetadata(); // bool
```

### Metadata

```php
$metadata = $ebook->metadata(); // OpfMetadata|CbaMetadata|null => metadata OPF for EPUB, metadata CBA for CBA

// For OpfMetadata
$metadata->metadata(); // `metadata` entry from `.opf` file
$metadata->manifest(); // `manifest` entry from `.opf` file
$metadata->spine(); // `spine` entry from `.opf` file
$metadata->guide(); // `guide` entry from `.opf` file
$metadata->dcX(); // `dcX` entries from `.opf` file

// For CbaMetadata, see docs https://anansi-project.github.io/docs/comicinfo/documentation
$metadata->writers(); // `writers` entry from `ComicInfo` format
$metadata->pencillers(); // `pencillers` entry from `ComicInfo` format
// more from `ComicInfo` format
```

### Book

```php
$book = $ebook->book(); // BookEntity

$book->title(); // string
$book->metaTitle(); // ?MetaTitle, with `slug` and `sort` properties for `title` and `series`
$book->metaTitle(); // ?MetaTitle, with slug and sort properties for `title` and `series`
$book->authors(); // BookCreator[] (name: string, role: string)
$book->authorFirst(); // ?BookCreator => First BookCreator (name: string, role: string)
$book->description(); // ?string
Expand All @@ -110,10 +128,10 @@ $book->words(); // ?int => `words` count in EPUB
$book->editors(); // string[] => `editors` in CBA
$book->review(); // ?string => `review` in CBA
$book->web(); // ?string => `web` in CBA
$book->manga(); // ?MangaEnum => `manga` in CBA | Addtional data about mangas
$book->manga(); // ?MangaEnum => `manga` in CBA | Additional data about mangas
$book->isBlackAndWhite(); // bool => `blackAndWhite` in CBA
$book->ageRating(); // ?AgeRatingEnum => `ageRating` in CBA | Addtional data about age rating
$book->comicMeta(); // ?ComicMeta => Addtional data for CBA
$book->ageRating(); // ?AgeRatingEnum => `ageRating` in CBA | Additional data about age rating
$book->comicMeta(); // ?ComicMeta => Additional data for CBA
```

### MetaTitle
Expand All @@ -123,15 +141,15 @@ Can be set if book's title is not null.
```php
$metaTitle = $book->metaTitle(); // ?MetaTitle

$metaTitle->slug(); // string => slugify title
$metaTitle->slugSort(); // string => slugify title without determiners
$metaTitle->slugLang(); // string => slugify title with language
$metaTitle->slug(); // string => slugify title, like `the-clan-of-the-cave-bear`
$metaTitle->slugSort(); // string => slugify title without determiners, like `clan-of-the-cave-bear`
$metaTitle->slugLang(); // string => slugify title with language and type, like `the-clan-of-the-cave-bear-epub-en`

$metaTitle->serieSlug(); // ?string => slugify series title
$metaTitle->serieSort(); // ?string => slugify series title without determiners
$metaTitle->serieLang(); // ?string => slugify series title with language
$metaTitle->serieSlug(); // ?string => slugify series title, like `earths-children`
$metaTitle->serieSort(); // ?string => slugify series title without determiners, like `earths-children`
$metaTitle->serieLang(); // ?string => slugify series title with language and type, like `earths-children-epub-en`

$metaTitle->slugSortWithSerie(); // string => slugify title with series title and volume
$metaTitle->slugSortWithSerie(); // string => slugify title with series title and volume, like `earths-children-01_clan-of-the-cave-bear`
```

## Testing
Expand Down
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).",
"version": "0.3.32",
"version": "0.3.40",
"keywords": [
"php",
"ebook",
Expand Down
4 changes: 2 additions & 2 deletions src/Cba/CbaCbam.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @docs https://anansi-project.github.io/docs/comicinfo/schemas/v2.0
*/
class CbaCbam extends CbaFormat
class CbaCbam extends CbaMetadata
{
protected string $metadataFilename = 'ComicInfo.xml';

Expand Down Expand Up @@ -180,7 +180,7 @@ private function parse(): void
$this->seriesGroup = $this->extract('SeriesGroup');

$ageRating = $this->extract('AgeRating');
$this->ageRating = $ageRating ? AgeRatingEnum::tryFrom($ageRating) : null;
$this->ageRating = $ageRating ? AgeRatingEnum::tryFrom($ageRating) : AgeRatingEnum::UNKNOWN;

$communityRating = $this->extract('CommunityRating');
$this->communityRating = $communityRating ? (float) $communityRating : null;
Expand Down
2 changes: 1 addition & 1 deletion src/Cba/CbaFormat.php → src/Cba/CbaMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Kiwilan\Ebook\Enums\AgeRatingEnum;
use Kiwilan\Ebook\Enums\MangaEnum;

abstract class CbaFormat
abstract class CbaMetadata
{
/** @var string[] */
protected array $writers = [];
Expand Down
12 changes: 6 additions & 6 deletions src/Ebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Kiwilan\Ebook\Book\BookCreator;
use Kiwilan\Ebook\Cba\Cba;
use Kiwilan\Ebook\Cba\CbaCbam;
use Kiwilan\Ebook\Cba\CbaFormat;
use Kiwilan\Ebook\Cba\CbaMetadata;
use Kiwilan\Ebook\Epub\EpubContainer;
use Kiwilan\Ebook\Epub\EpubOpf;
use Kiwilan\Ebook\Epub\OpfMetadata;

class Ebook
{
protected EpubOpf|CbaFormat|null $metadata = null;
protected OpfMetadata|CbaMetadata|null $metadata = null;

protected ?BookEntity $book = null;

Expand Down Expand Up @@ -70,7 +70,7 @@ private function epub(): self
if (! $opf) {
return $this;
}
$opf = EpubOpf::make($opf);
$opf = OpfMetadata::make($opf);
$this->metadata = $opf;
$this->book = $opf->toBook();

Expand Down Expand Up @@ -111,7 +111,7 @@ private function cba(): self
default => null,
};

/** @var ?CbaFormat */
/** @var ?CbaMetadata */
$parser = match ($metadataType) {
'cbam' => CbaCbam::class,
// 'cbml' => CbaCbml::class,
Expand Down Expand Up @@ -243,7 +243,7 @@ public function format(): ?string
/**
* Metadata of the ebook.
*/
public function metadata(): EpubOpf|CbaFormat|null
public function metadata(): OpfMetadata|CbaMetadata|null
{
return $this->metadata;
}
Expand Down
21 changes: 12 additions & 9 deletions src/Entity/MetaTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,56 +76,56 @@ private function setMetaTitle(Ebook $ebook): static
}

/**
* Get slug of book title, like `le-clan-de-lours-des-cavernes`.
* Get slug of book title, like `the-clan-of-the-cave-bear`.
*/
public function slug(): string
{
return $this->slug;
}

/**
* Get slug of book title without determiners, like `clan-de-lours-des-cavernes`.
* Get slug of book title without determiners, like `clan-of-the-cave-bear`.
*/
public function slugSort(): string
{
return $this->slugSort;
}

/**
* Get slug of book title with language, like `le-clan-de-lours-des-cavernes-epub-fr`.
* Get slug of book title with language and with type, like `the-clan-of-the-cave-bear-epub-en`.
*/
public function slugLang(): string
{
return $this->slugLang;
}

/**
* Get slug of serie title, like `les-enfants-de-la-terre`.
* Get slug of serie title, like `earths-children`.
*/
public function serieSlug(): ?string
{
return $this->serieSlug;
}

/**
* Get slug of serie title without determiners, like `enfants-de-la-terre`.
* Get slug of serie title without determiners, like `earths-children`.
*/
public function serieSlugSort(): ?string
{
return $this->serieSlugSort;
}

/**
* Get slug of serie title with language, like `les-enfants-de-la-terre-epub-fr`.
* Get slug of serie title with language and with type, like `earths-children-epub-en`.
*/
public function serieSlugLang(): ?string
{
return $this->serieSlugLang;
}

/**
* Get slug of book title with serie title, like `enfants-de-la-terre-01_clan-de-lours-des-cavernes`.
* If series is null, book's title will be used like `clan-de-lours-des-cavernes`.
* Get slug of book title with serie title, like `earths-children-01_clan-of-the-cave-bear`.
* If series is null, book's title will be used like `clan-of-the-cave-bear`.
*/
public function slugSortWithSerie(): string
{
Expand Down Expand Up @@ -182,7 +182,7 @@ private function generateSortSerie(string $title, ?string $serieTitle, ?int $vol
}

/**
* Generate `slug` with `title`, `BookTypeEnum` and `language_slug`.
* Generate `slug` with `title`, `type` and `language`.
*/
private function generateSlug(string $title, ?string $type, ?string $language): string
{
Expand Down Expand Up @@ -225,6 +225,9 @@ private function setSlug(?string $title, string $separator = '-', array $diction
return null;
}

$transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD);
$title = $transliterator->transliterate($title);

// Convert all dashes/underscores into separator
$flip = $separator === '-' ? '_' : '-';

Expand Down
22 changes: 21 additions & 1 deletion src/Epub/EpubOpf.php → src/Epub/OpfMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Kiwilan\Ebook\BookEntity;
use Kiwilan\Ebook\XmlReader;

class EpubOpf
class OpfMetadata
{
protected array $metadata = [];

Expand Down Expand Up @@ -230,6 +230,26 @@ private function findContent(): array
return $files;
}

public function metadata(): array
{
return $this->metadata;
}

public function manifest(): array
{
return $this->manifest;
}

public function spine(): array
{
return $this->spine;
}

public function guide(): array
{
return $this->guide;
}

public function epubVersion(): ?int
{
return $this->epubVersion;
Expand Down
11 changes: 6 additions & 5 deletions tests/CbaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// CBML comic-book-markup language with ComicBook.xml

use Kiwilan\Ebook\Cba\CbaCbam;
use Kiwilan\Ebook\Cba\CbaFormat;
use Kiwilan\Ebook\Cba\CbaMetadata;
use Kiwilan\Ebook\Entity\ComicMeta;
use Kiwilan\Ebook\Enums\AgeRatingEnum;
use Kiwilan\Ebook\Enums\MangaEnum;
Expand Down Expand Up @@ -96,7 +96,7 @@
expect($book->date()->format('Y-m-d'))->toBe($date->format('Y-m-d'));
expect($book->pageCount())->toBe(24);
expect($book->manga())->toBe(MangaEnum::NO);
expect($book->ageRating())->toBe(AgeRatingEnum::UNKNOWN);
expect($book->ageRating())->toBe(AgeRatingEnum::TEEN);

expect($book->comicMeta()->imprint())->toBe('Vertigo');
expect($book->comicMeta()->characters())->toBeArray();
Expand All @@ -112,11 +112,11 @@
expect($book->comicMeta()->storyArcNumber())->toBeNull();
})->with([CBZ_CBAM]);

it('can parse CbaFormat', function (string $path) {
it('can parse CbaMetadata', function (string $path) {
$ebook = Kiwilan\Ebook\Ebook::read($path);
$metadata = $ebook->metadata();

expect($metadata)->toBeInstanceOf(CbaFormat::class);
expect($metadata)->toBeInstanceOf(CbaMetadata::class);
expect($metadata->title())->toBe('You Had One Job');
expect($metadata->series())->toBe('Fantastic Four');
expect($metadata->number())->toBe(22);
Expand All @@ -143,7 +143,8 @@

expect($metadata->alternateSeries())->toBe('Empyre');
expect($metadata->seriesGroup())->toBe('Fantastic Four');
expect($metadata->ageRating())->toBeNull();
dump($metadata->ageRating());
expect($metadata->ageRating())->toBe(AgeRatingEnum::TEEN);
expect($metadata->manga())->toBe(MangaEnum::NO);
expect($metadata->pageCount())->toBe(24);
expect($metadata->imprint())->toBe('Vertigo');
Expand Down
Loading

0 comments on commit d52b386

Please sign in to comment.