Skip to content

Commit

Permalink
drop audiobook native support
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Jan 22, 2024
1 parent e7a7a84 commit 39e6cdf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PHP package to read metadata and extract covers from eBooks, comics and audioboo

- eBooks: `.epub`, `.pdf`, `.azw`, `.azw3`, `.kf8`, `.kfx`, `.mobi`, `.prc`, `.fb2`
- Comics: `.cbz`, `.cbr`, `.cb7`, `.cbt` (metadata from [github.com/anansi-project](https://github.com/anansi-project))
- Audiobooks: `.mp3`, `.m4a`, `.m4b`, `.flac`, `.ogg`
- Audiobooks: `.mp3`, `.m4a`, `.m4b`, `.flac`, `.ogg` [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio) **MUST** be installed

To know more see [Supported formats](#supported-formats). _Supports Linux, macOS and Windows._

Expand Down Expand Up @@ -41,7 +41,9 @@ This package was built for [`bookshelves-project/bookshelves`](https://github.co
- [`fileinfo`](https://www.php.net/manual/en/book.fileinfo.php) (native, optional) for better detection of file type
- **Binaries**
- [`p7zip`](https://www.7-zip.org/) (optional) binarys for `.CB7` (can handle `.CBR` too)
- To know more about requirements, see [Supported formats](#supported-formats).
- **Audiobooks**
- [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio) (optional) for `.mp3`, `.m4a`, `.m4b`, `.flac`, `.ogg` (see [Supported formats](#supported-formats)
- To know more about requirements, see [Supported formats](#supported-formats)

> [!NOTE]
>
Expand All @@ -57,11 +59,12 @@ This package was built for [`bookshelves-project/bookshelves`](https://github.co
- Support multiple formats, see [Supported formats](#supported-formats)
- 🔎 Read metadata from eBooks, comics, and audiobooks
- 🖼️ Extract covers from eBooks, comics, and audiobooks
- 🎵 Works with audiobooks if [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio) is installed
- 📚 Support metadata
- eBooks: `EPUB` v2 and v3 from [IDPF](https://idpf.org/) with `calibre:series` from [Calibre](https://calibre-ebook.com/) | `MOBI` from Mobipocket (and derivatives) | `FB2` from [FictionBook](https://en.wikipedia.org/wiki/FictionBook)
- Comics: `CBAM` (Comic Book Archive Metadata) : `ComicInfo.xml` format from _ComicRack_ and maintained by [`anansi-project`](https://github.com/anansi-project/comicinfo)
- `PDF` with [`smalot/pdfparser`](https://github.com/smalot/pdfparser)
- Audiobooks: `ID3`, `vorbis` and `flac` tags with [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio)
- Audiobooks: `ID3`, `vorbis` and `flac` tags with [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio) (not included)
- 🔖 Chapters extraction (`EPUB` only)
- 📦 `EPUB` and `CBZ` creation supported
<!-- - 📝 `EPUB` and `CBZ` metadata update supported -->
Expand All @@ -86,7 +89,9 @@ composer require kiwilan/php-ebook

## Usage

With eBook files or audiobook files (to know more about formats, see [Supported formats](#supported-formats)).
With eBook files or audiobook\* files (to know more about formats, see [Supported formats](#supported-formats)).

\*: should be installed separately, see [Requirements](#requirements).

```php
use Kiwilan\Ebook\Ebook;
Expand Down Expand Up @@ -234,6 +239,10 @@ $cover->getContents(bool $toBase64 = false); // ?string => content of cover, if
### Formats specifications

#### Audiobooks

For audiobooks, you have to install seperately [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio).

#### EPUB

With `EPUB`, metadata are extracted from `OPF` file, `META-INF/container.xml` files, you could access to these metatada but you can also get chapters from `NCX` file. And with `chapters()` method you can merge `NCX` and `HTML` chapters to get full book chapters with `label`, `source` and `content`.
Expand Down Expand Up @@ -309,7 +318,7 @@ There is a lot of different formats for eBooks and comics, if you want to know m
| Comics CBR | `.cbr` || [`rar`](https://github.com/cataphract/php-rar) PHP extension or [`p7zip`](https://www.7-zip.org/) binary |||
| Comics CB7 | `.cb7` || [`p7zip`](https://www.7-zip.org/) binary |||
| Comics CBT | `.cbt` || Native [`phar`](https://www.php.net/manual/en/book.phar.php) |||
| Audio | `.mp3`, `.m4a`, `.m4b`, `.flac`, `.ogg` || See [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio) | [Depends of format](https://github.com/kiwilan/php-audio#supported-formats) ||
| Audio | `.mp3`, `.m4a`, `.m4b`, `.flac`, `.ogg` || If [`kiwilan/php-audio`](https://github.com/kiwilan/php-audio) is installed | [Depends of format](https://github.com/kiwilan/php-audio#supported-formats) ||

### MOBI cover note

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.2.01",
"version": "2.3.0",
"keywords": [
"php",
"ebook",
Expand Down Expand Up @@ -40,10 +40,10 @@
"require": {
"php": "^8.1",
"kiwilan/php-archive": "^2.2.0",
"kiwilan/php-audio": "^3.0.01",
"kiwilan/php-xml-reader": "^1.0.11"
},
"require-dev": {
"kiwilan/php-audio": "^3.0.01",
"laravel/pint": "^1.7",
"pestphp/pest": "^1.20",
"pestphp/pest-plugin-parallel": "^1.2",
Expand Down
8 changes: 4 additions & 4 deletions src/Ebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Kiwilan\Archive\Archive;
use Kiwilan\Archive\ArchiveZipCreate;
use Kiwilan\Archive\Readers\BaseArchive;
use Kiwilan\Audio\Audio;
use Kiwilan\Ebook\Creator\EbookCreator;
use Kiwilan\Ebook\Enums\EbookFormatEnum;
use Kiwilan\Ebook\Formats\Audio\AudiobookModule;
Expand Down Expand Up @@ -76,7 +75,7 @@ protected function __construct(
protected string $basename,
protected string $extension,
protected ?BaseArchive $archive = null,
protected ?Audio $audio = null,
protected ?\Kiwilan\Audio\Audio $audio = null,
protected bool $isArchive = false,
protected bool $isAudio = false,
protected bool $isMobi = false,
Expand Down Expand Up @@ -210,7 +209,7 @@ private static function parseFile(string $path): Ebook
}

if ($self->isAudio) {
$self->audio = Audio::get($path);
$self->audio = \Kiwilan\Audio\Audio::get($path);
}

return $self;
Expand Down Expand Up @@ -485,10 +484,11 @@ public function getArchive(): ?BaseArchive

/**
* Audio reader, from `kiwilan/php-audio`.
* You have to install `kiwilan/php-audio` to use this feature.
*
* @docs https://github.com/kiwilan/php-audio
*/
public function getAudio(): ?Audio
public function getAudio(): ?\Kiwilan\Audio\Audio
{
return $this->audio;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Formats/Audio/AudiobookModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class AudiobookModule extends EbookModule

public static function make(Ebook $ebook): self
{
if (! \Composer\InstalledVersions::isInstalled('kiwilan/php-audio')) {
throw new \Exception('To handle audiobooks, you have to install `kiwilan/php-audio`, see https://github.com/kiwilan/php-audio');
}

$self = new self($ebook);
$self->create();

Expand Down
2 changes: 1 addition & 1 deletion tests/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
expect(file_exists($path))->toBeTrue();
expect($path)->toBeReadableFile();
expect(fileIsValidImg($path))->toBeTrue();
})->skip(PHP_OS_FAMILY === 'Windows' || PHP_VERSION > '8.2', 'Skip on Windows');
})->skip(PHP_OS_FAMILY === 'Windows' || PHP_VERSION >= '8.3', 'Skip on Windows or PHP >= 8.3');

it('can parse empty pdf', function () {
$ebook = Ebook::read(PDF_EMPTY);
Expand Down

0 comments on commit 39e6cdf

Please sign in to comment.