Skip to content

Commit

Permalink
Merge pull request #5 from kiwilan/develop
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
ewilan-riviere authored Jun 13, 2023
2 parents 96b154d + ccf5a83 commit 799d724
Show file tree
Hide file tree
Showing 35 changed files with 1,546 additions and 1,356 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Codecov

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Install for Linux
run: |
sudo apt -y install p7zip-full ghostscript imagemagick
sudo apt-get install -y unrar
sudo apt-get install -y libunrar-dev
sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
shell: bash

- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: imagick, zip, fileinfo, intl
coverage: pcov

- name: Add rar extension
run: |
git clone https://github.com/cataphract/php-rar
cd php-rar
phpize
./configure
sudo make
sudo make install
pecl_path=$(pecl config-get ext_dir)
phpini_path=$(php -i | grep /.+/php.ini -oE)
sudo cp ./modules/rar.so $pecl_path
sudo echo "extension=rar.so" > $phpini_path
- name: Check extension rar
run: php -m | grep rar

- name: Check extension imagick
run: php -m | grep imagick

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: composer update --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/pest --coverage

- name: Send code coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: false
11 changes: 2 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: imagick, zip, fileinfo, intl
coverage: pcov

- name: Setup problem matchers
Expand Down Expand Up @@ -75,11 +75,4 @@ jobs:
shell: bash

- name: Execute tests
run: vendor/bin/pest --coverage

- name: on Linux send code coverage
if: runner.os == 'Linux'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: false
run: vendor/bin/pest
30 changes: 12 additions & 18 deletions .github/workflows/run-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [windows-latest]
php: [8.1]
stability: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
runs-on: windows-latest

steps:
- name: scoop
- name: Install scoop
run: |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
scoop update
scoop checkup
scoop install 7zip imagemagick ghostscript unrar
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
scoop install 7zip unrar
shell: powershell

- name: Checkout code
Expand All @@ -29,8 +23,8 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, bz2, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, fileinfo
php-version: 8.1
extensions: imagick, zip, fileinfo, intl
coverage: pcov

# - name: Install rar extension
Expand All @@ -50,13 +44,13 @@ jobs:
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

# - name: Check extension imagick
# run: php -m | grep imagick
run: composer update --prefer-dist --no-interaction

# - name: Check extension rar
# run: php -m | grep rar

- name: Check extension imagick
run: php -m | grep imagick

- name: Execute tests
run: .\vendor\bin\pest.bat --colors=always
run: vendor/bin/pest
7 changes: 7 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ jobs:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md

- name: Merge on develop
run: |
git checkout origin/develop
git merge origin/main
git push
shell: bash
118 changes: 57 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![tests][tests-src]][tests-href]
[![codecov][codecov-src]][codecov-href]

PHP package to read metadata and extract covers from eBooks (`.epub`, `.cbz`, `.cbr`, `.cb7`, `.cbt`, `.pdf`).
PHP package to read metadata and extract covers from eBooks (`.epub`, `.cbz`, `.cbr`, `.cb7`, `.cbt`, `.pdf`) and audiobooks (`mp3`, `m4a`, `m4b`, `flac`, `ogg`).

Supports Linux, macOS and Windows.

Expand All @@ -18,21 +18,27 @@ Supports Linux, macOS and Windows.
## About

This package was built for [bookshelves-project/bookshelves-back](https://github.com/bookshelves-project/bookshelves-back), a web app to handle eBooks.
This package was built for [bookshelves-project/bookshelves](https://github.com/bookshelves-project/bookshelves), a web app to handle eBooks.

## Requirements

- PHP >= 8.1
- Depends of extension and features you want to use

| Type | Native | Dependency |
| :-------------: | :----: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| `.epub`, `.cbz` || N/A |
| `.cbt` || N/A |
| `.cbr` || [`rar` PHP extension](https://github.com/cataphract/php-rar) or [`p7zip`](https://www.7-zip.org/) binary |
| `.cb7` || [`p7zip`](https://www.7-zip.org/) binary |
| `.pdf` || Optional (for extraction) [`imagick` PHP extension](https://github.com/Imagick/imagick) |
| ALL || [`p7zip`](https://www.7-zip.org/) binary ([`rar` PHP extension](https://github.com/cataphract/php-rar) and [`imagick` PHP extension](https://github.com/Imagick/imagick) are optional) |
- **PHP version** >= _8.1_
- **PHP extensions**:
- [`intl`](https://www.php.net/manual/en/book.intl.php) (native) for `Transliterator`
- [`zip`](https://www.php.net/manual/en/book.zip.php) (native, optional) for `.EPUB`, `.CBZ`
- [`fileinfo`](https://www.php.net/manual/en/book.fileinfo.php) (native, optional) for better detection of file type
- [`rar`](https://www.php.net/manual/en/book.rar.php) (optional) for `.CBR`
- [`imagick`](https://www.php.net/manual/en/book.imagick.php) (optional) for `.PDF`

| Type | Native | Dependency | Uses |
| :--------------------------------: | :----: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------: |
| `.epub`, `.cbz` || N/A | PHP |
| `.cbt` || N/A | PHP |
| `.cbr` || [`rar` PHP extension](https://github.com/cataphract/php-rar) or [`p7zip`](https://www.7-zip.org/) binary | PHP `rar` or `p7zip` |
| `.cb7` || [`p7zip`](https://www.7-zip.org/) binary | `p7zip` |
| `.pdf` || Optional (for extraction) [`imagick` PHP extension](https://github.com/Imagick/imagick) | `smalot/pdfparser` |
| `mp3`, `m4a`, `m4b`, `flac`, `ogg` || N/A | `kiwilan/php-audio` |
| ALL || [`p7zip`](https://www.7-zip.org/) binary ([`rar` PHP extension](https://github.com/cataphract/php-rar) and [`imagick` PHP extension](https://github.com/Imagick/imagick) are optional) | |

> **Note**
>
Expand All @@ -51,14 +57,15 @@ If you want more informations, you can read [kiwilan/php-archive](https://github

## Features

- Read metadata from eBooks
- Extract covers from eBooks
- Read metadata from eBooks and audiobooks
- Extract covers from eBooks and audiobooks
- Support metadata
- EPUB v2 and v3 from [IDPF](https://idpf.org/)
- `calibre:series` for EPUB from [Calibre](https://calibre-ebook.com/)
- `calibre:series_index` for EPUB from [Calibre](https://calibre-ebook.com/)
- `ComicInfo.xml` (CBAM) format from ComicRack and maintained by [anansi-project](https://github.com/anansi-project/comicinfo)
- PDF by [smalot/pdfparser](https://github.com/smalot/pdfparser)
- ID3, Vorbis and flac tags with [kiwilan/php-audio](https://github.com/kiwilan/php-audio)

## Installation

Expand All @@ -70,68 +77,56 @@ composer require kiwilan/php-ebook

## Usage

With eBook files (`.epub`, `.cbz`, `.cba`, `.cbr`, `.cb7`, `.cbt`, `.pdf`)
With eBook files (`.epub`, `.cbz`, `.cba`, `.cbr`, `.cb7`, `.cbt`, `.pdf`) or audiobook files (`mp3`, `m4a`, `m4b`, `flac`, `ogg`).

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

$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)
$path = $ebook->path(); // string
$filename = $ebook->filename(); // string
$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
// File data
$book->path(); // string
$book->filename(); // string
$book->extension(); // string

// Book data
$book->title(); // string
$book->metaTitle(); // ?MetaTitle, with slug and sort properties for `title` and `series`
$book->authors(); // BookAuthor[] (name: string, role: string)
$book->authorFirst(); // ?BookAuthor => First BookAuthor (name: string, role: string)
$book->authorMain(); // ?BookAuthor => First BookAuthor (name: string, role: string)
$book->description(); // ?string
$book->contributor(); // ?string
$book->rights(); // ?string
$book->copyright(); // ?string
$book->publisher(); // ?string
$book->identifiers(); // BookIdentifier[] (content: string, type: string)
$book->date(); // ?DateTime
$book->publishDate(); // ?DateTime
$book->language(); // ?string
$book->tags(); // string[] => `subject` in EPUB, `keywords` in PDF, `genres` in CBA
$book->series(); // ?string => `calibre:series` in EPUB, `series` in CBA
$book->volume(); // ?int => `calibre:series_index` in EPUB, `number` in CBA
$book->rating(); // ?float => `rating` in CBA
$book->pageCount(); // ?int => computed from words (250 words by page) in EPUB, `pageCount` in PDF, `pageCount` in CBA
$book->pagesCount(); // ?int => computed from words (250 words by page) in EPUB, `pageCount` in PDF, `pageCount` in CBA
$book->wordsCount(); // ?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 | Additional data about mangas
$book->isBlackAndWhite(); // bool => `blackAndWhite` in CBA
$book->ageRating(); // ?AgeRatingEnum => `ageRating` in CBA | Additional data about age rating
$book->comicMeta(); // ?ComicMeta => Additional data for CBA

// Additional data
$book->format(); // ?EbookFormatEnum => `epub`, `pdf`, `cba`
$book->cover(); // ?EbookCover => cover of book
$book->extras(); // array => additional data for book

// Check validity
$book->isArchive(); // bool
$book->isAudio(); // bool
$book->hasMetadata(); // bool
$book->hasCover(); // bool
```

### Metadata

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

$metadata = $ebook->metadata(); // with `module` as `EbookModule::class`, can be `EpubMetadata::class`, `PdfMetadata::class`, `CbaMetadata::class` or `AudiobookMetadata::class`

$metadata->epub(); // `EpubMetadata::class`
$metadata->pdf(); // `PdfMetadata::class`
$metadata->cba(); // `CbaMetadata::class`
$metadata->audiobook(); // `AudiobookMetadata::class`
```

### MetaTitle
Expand Down Expand Up @@ -261,6 +256,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re

- [Kiwilan](https://github.com/kiwilan)
- [spatie](https://github.com/spatie) for `spatie/package-skeleton-php`
- [kiwilan/php-audio](https://github.com/kiwilan/php-audio)

## License

Expand Down
6 changes: 3 additions & 3 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 (.epub, .cbz, .cbr, .cb7, .cbt, .pdf).",
"version": "0.34.0",
"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.0",
"keywords": [
"php",
"ebook",
Expand Down Expand Up @@ -34,7 +34,7 @@
],
"require": {
"php": "^8.1",
"kiwilan/php-archive": "^1.3.02",
"kiwilan/php-archive": "^1.4.02",
"kiwilan/php-audio": "^2.0.0"
},
"require-dev": {
Expand Down
Loading

0 comments on commit 799d724

Please sign in to comment.