Skip to content

Commit

Permalink
Merge pull request #97 from kiwilan/develop
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
ewilan-riviere authored Oct 3, 2024
2 parents bbed34b + 05a28f4 commit a15aea1
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 41 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/phpstan-php-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: PHPStan PHP code issues

on: [push]

jobs:
build-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: php-actions/composer@v6
- uses: php-actions/phpstan@v3
with:
path: src/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ vendor
.DS_Store
CHANGELOG-draft.md
node_modules
.phpunit.cache
9 changes: 4 additions & 5 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.6.9",
"version": "2.7.0",
"keywords": [
"php",
"ebook",
Expand Down Expand Up @@ -40,13 +40,12 @@
"require": {
"php": "^8.1",
"kiwilan/php-archive": "^2.2.0",
"kiwilan/php-xml-reader": "^1.0.11"
"kiwilan/php-xml-reader": "^1.1.0"
},
"require-dev": {
"kiwilan/php-audio": "^3.0.08",
"kiwilan/php-audio": "^4.0.01",
"laravel/pint": "^1.7",
"pestphp/pest": "^1.20",
"pestphp/pest-plugin-parallel": "^1.2",
"pestphp/pest": "^2.0",
"phpstan/phpstan": "^1.10",
"spatie/ray": "^1.28"
},
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ parameters:

# The level 9 is the highest level
level: 5

checkMissingIterableValueType: false
17 changes: 8 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Kiwilan Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage" />
<text outputFile="build/coverage.txt" />
Expand All @@ -36,4 +30,9 @@
<logging>
<junit outputFile="build/report.junit.xml" />
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/Ebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private static function parseFile(string $path): Ebook

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

return $self;
Expand Down
47 changes: 26 additions & 21 deletions src/Formats/Audio/AudiobookModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,38 @@ private function create(): self
$genres = array_map('ucfirst', $genres);
}

$series = $audio->getTag('series') ?? $audio->getTag('mvnm');
$series_part = $audio->getTag('series-part') ?? $audio->getTag('mvin');
$language = $audio->getTag('language') ?? $audio->getTag('lang');
$series = $audio->getRawKey('series') ?? $audio->getRawKey('mvnm');
$series_part = $audio->getRawKey('series-part') ?? $audio->getRawKey('mvin');
$language = $audio->getRawKey('language') ?? $audio->getRawKey('lang');
$narrators = $audio->getComposer();

$chapters = [];
$quicktime = $audio->toArray()['quicktime'] ?? [];
if (array_key_exists('chapters', $quicktime)) {
$chapters = $quicktime['chapters'];
}

$this->audio = [
'authors' => EbookUtils::parseStringWithSeperator($authors),
'title' => $audio->getAlbum() ?? $audio->getTitle(),
'subtitle' => $this->parseTag($audio->getTag('subtitle'), false),
'publisher' => $audio->getTag('encoded_by'),
'subtitle' => $this->parseTag($audio->getRawKey('subtitle'), false),
'publisher' => $audio->getRawKey('encoded_by'),
'publish_year' => $audio->getYear(),
'narrators' => EbookUtils::parseStringWithSeperator($narrators),
'description' => $this->parseTag($audio->getDescription(), false),
'lyrics' => $this->parseTag($audio->getLyrics()),
'comment' => $this->parseTag($audio->getComment()),
'synopsis' => $this->parseTag($audio->getTag('description_long')),
'synopsis' => $this->parseTag($audio->getRawKey('description_long')),
'genres' => $genres,
'series' => $this->parseTag($series),
'series_sequence' => $series_part !== null ? EbookUtils::parseNumber($series_part) : null,
'language' => $this->parseTag($language),
'isbn' => $this->parseTag($audio->getTag('isbn')),
'asin' => $this->parseTag($audio->getTag('asin') ?? $audio->getTag('audible_asin')),
'chapters' => $chapters,
'date' => $audio->getCreationDate() ?? $audio->getTag('origyear'),
'isbn' => $this->parseTag($audio->getRawKey('isbn')),
'asin' => $this->parseTag($audio->getRawKey('asin') ?? $audio->getRawKey('audible_asin')),
'chapters' => $audio->getMetadata()?->getQuicktime()?->getChapters(),
'date' => $audio->getCreationDate() ?? $audio->getRawKey('origyear'),
'is_compilation' => $audio->isCompilation(),
'encoding' => $audio->getEncoding(),
'track_number' => $audio->getTrackNumber(),
'disc_number' => $audio->getDiscNumber(),
'copyright' => $this->parseTag($audio->getTag('copyright')),
'stik' => $audio->getStik(),
'copyright' => $this->parseTag($audio->getRawKey('copyright')),
'stik' => $audio->getRawKey('stik'),
'duration' => $audio->getDuration(),
'duration_human_readable' => $audio->getDurationHumanReadable(),
'duration_human_readable' => $audio->getDurationHuman(),
'audio_title' => $audio->getTitle(),
'audio_artist' => $audio->getArtist(),
'audio_album' => $audio->getAlbum(),
Expand Down Expand Up @@ -138,6 +132,17 @@ public function toEbook(): Ebook
}
$this->ebook->setCopyright($this->getAudioValue('copyright'));

$chapters = [];
$quicktime = $this->ebook->getAudio()?->getMetadata()?->getQuicktime();
if ($quicktime && $quicktime->getChapters()) {
foreach ($quicktime->getChapters() as $chapter) {
$chapters[] = [
'timestamp' => $chapter->getTimestamp(),
'title' => $chapter->getTitle(),
];
}
}

$this->ebook->setExtras([
'subtitle' => $this->getAudioValue('subtitle'),
'publish_year' => $this->getAudioValue('publish_year'),
Expand All @@ -146,7 +151,7 @@ public function toEbook(): Ebook
'lyrics' => $this->getAudioValue('lyrics'),
'comment' => $this->getAudioValue('comment'),
'synopsis' => $this->getAudioValue('synopsis'),
'chapters' => $this->getAudioValue('chapters'),
'chapters' => $chapters,
'is_compilation' => $this->getAudioValue('is_compilation'),
'encoding' => $this->getAudioValue('encoding'),
'track_number' => $this->getAudioValue('track_number'),
Expand Down Expand Up @@ -186,7 +191,7 @@ public function toArray(): array
{
return [
'audio' => $this->audio,
'tags' => $this->ebook->getAudio()->getTags(),
'tags' => $this->ebook->getAudio()->getRaw(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AudiobookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
->each(fn (Expectation $expectation) => expect($expectation->value)
->toBeInstanceOf(BookAuthor::class)
);
expect($ebook->getPublisher())->toBe('Ewilan Rivi&#232;re');
expect($ebook->getPublisher())->toBe('Ewilan Rivière');
expect($ebook->getDescription())->toBe('Description');
expect($ebook->getExtra('comment'))->toBe('Do you want to extract an audiobook?');
expect($ebook->getSeries())->toBeNull();
Expand Down
2 changes: 0 additions & 2 deletions tests/EpubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,4 @@
$html = $module->getHtml();
expect($html)->toBeArray()
->each(fn (Pest\Expectation $expectation) => expect($expectation->value)->toBeInstanceOf(EpubHtml::class));
expect(fn () => $module->getChapters())->toThrow(Exception::class);
expect(fn () => $module->getNcx())->toThrow(Exception::class);
});

0 comments on commit a15aea1

Please sign in to comment.