From fc18018c73b9fcfa8f7456b95cdf637475c09131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Sun, 4 Feb 2024 13:01:23 +0100 Subject: [PATCH 1/2] v2.3.6 - Audiobook: add `language`, `tags` will be splitted by `;` or `,` - MetaTitle: now `language` slug will be added just after series if series exists, and before author if not to help for sorting with series in different languages --- composer.json | 4 ++-- src/Formats/Audio/AudiobookModule.php | 17 ++++++++++++++- src/Models/MetaTitle.php | 30 +++++++++++++++++--------- tests/AudiobookTest.php | 5 +++-- tests/EpubTest.php | 4 ++-- tests/MetaTitleTest.php | 10 ++++----- tests/media/audiobook-test-1.mp3 | Bin 272737 -> 366480 bytes tests/media/audiobook-test-2.mp3 | Bin 272737 -> 366467 bytes tests/media/audiobook-test.m4b | Bin 431317 -> 502449 bytes tests/media/audiobook.m4b | Bin 261476 -> 261476 bytes tests/media/audiobook.mp3 | Bin 272737 -> 366467 bytes 11 files changed, 48 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 1bc835b..1d1cff3 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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", diff --git a/src/Formats/Audio/AudiobookModule.php b/src/Formats/Audio/AudiobookModule.php index da2f85b..ba10627 100644 --- a/src/Formats/Audio/AudiobookModule.php +++ b/src/Formats/Audio/AudiobookModule.php @@ -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(), @@ -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(), @@ -131,6 +145,7 @@ public function toArray(): array { return [ 'audio' => $this->audio, + 'tags' => $this->ebook->getAudio()->getTags(), ]; } diff --git a/src/Models/MetaTitle.php b/src/Models/MetaTitle.php index 012c0f2..dc055e0 100644 --- a/src/Models/MetaTitle.php +++ b/src/Models/MetaTitle.php @@ -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()) { @@ -341,9 +351,9 @@ private function parse(Ebook $ebook): static $this->seriesSlug = $this->generateSlug([ $seriesDeterminer, + $language, $author, $extension, - $language, ]); $this->seriesSlugSimple = $this->generateSlug([$series]); diff --git a/tests/AudiobookTest.php b/tests/AudiobookTest.php index 96e2cae..9a49853 100644 --- a/tests/AudiobookTest.php +++ b/tests/AudiobookTest.php @@ -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(); @@ -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'); @@ -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); diff --git a/tests/EpubTest.php b/tests/EpubTest.php index df6d16a..7323ee8 100644 --- a/tests/EpubTest.php +++ b/tests/EpubTest.php @@ -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(); diff --git a/tests/MetaTitleTest.php b/tests/MetaTitleTest.php index c163194..945c2ce 100644 --- a/tests/MetaTitleTest.php +++ b/tests/MetaTitleTest.php @@ -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'); @@ -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'); @@ -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(); diff --git a/tests/media/audiobook-test-1.mp3 b/tests/media/audiobook-test-1.mp3 index e60e8a5fd6f50e95bb955ca702ece562e6da6af0..71ef745086d611c3af1a0548c182419844759b89 100644 GIT binary patch delta 893 zcmZ`%&ui3B5dL1b_yd(z&~8zx0a02gtr6-$5J_L+8qH=yl7-!i5YjYF$tEG2wd`pN z9=s|&^y;DXst2L}hWH=!AK7(YOez+9Fq3&R!#Cf&eCNLwKYv^L-e4=dV*zLaY&PXc zkztG+5kl;t_%dsvx5}9+G&ta}p~Hepz5_9GHdSfFkaiI3Wwc2|%o3_7md?TAM-)Z_??D)B?q@-W z22Vc(xuoQUwE8+vlVWXSKMOyeva?gh7V=Lg1tXg~J1H73f4o;L%~e`j@8?xuAz`>p zXmq}op4`nUaCO(vpeIG1?u`5*N|S3e|vwTZ5g(K^A-CC<&#|8wBf;=NBU{mPGPS)yg~Vwr0B6D~jyJ z=H|h{!A2%$J3AYGI#{fF6v2SlO$0qlwp3MmBGoi+{ROf*4*i$9p#a8~c$$s#DBLTA48-Z0 zPT%C3YET1rU{KW`){kp-RIWHeoE*+LNwZ;eQ6ovVy7cd0cu6?&!eA+8m?OkX0$48A XE~oy{1dFBrsNhiW6X*DRb^h=-&VtJH delta 118 zcmbQRUhLr|fep-zlT{dn8C54+Fskw~FoZb!1~4!%FaxpSLHP?K|l^05E~g7 znlU&AcsesM<^Yv4WacKOr|M@Fq^2`4x4+k7+5TROl`&`gv^+*Ww&@%47~i)qDPaU+ RrtM2gm~FRA7nsi40053)Ab diff --git a/tests/media/audiobook-test-2.mp3 b/tests/media/audiobook-test-2.mp3 index e60e8a5fd6f50e95bb955ca702ece562e6da6af0..9907f28d4abeade9259197ff0bb63306ba0d5455 100644 GIT binary patch delta 801 zcmZ`%Pm9w)9DUO*{$W*C&{Y&MC)vGpt*{;9=RT9)x}k@f++HY5gT8)r$j}Ox}CE_cAk=zjhYicE4}2N8GXj+ymHp#StUH z3@Jhc7$Ez+HeM>KOM<(Fz$G#&L}QYS2^YF-ZfG4I(E%p(4&Vb{-m=4a+tme0?vsNb z1?v^CUg>2@?~h4Wbx3iAo@Y;+&mlUU4y_N1Oa&@ja5&IlL(ps?k6f=5i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iKG)e!UK88p zB|E0~DLEtW+#GW_mdI>XI42uaHN^ls30J19x+e&Pze(jR-h_Nx)V>2CO2awRHe6|sjen- zH`O$>z^zdxd_m1B$B8GwhifGMK6m}a*>Ku7u9o2FFWQVZWKWXrKDK8igZV& zw7gstQ`)5V?7pcYg;4y^*vJxyP=z3AC*pKoAs!I&UYRt{p$yCjG*6g1wpR2>mAza- z9xuFGn1|LQhc6AZ&keMbSu*^Qmeec;TWBelVQFZu7M}pWY*h8v!bZJvN`CvQm-yXy ztvE^(PCNX%?eAXF?fH$MRk-qtmO@mc!{u@0u#y)W?q7HX{}nIs&%9b;!c^58N89>t foNn9vfBo0sy5+u1eFPVWs{vOdE`E;s1o^^G%Ba|s delta 399 zcmdmZRqpCasR^>ojAEf16_)eHGm14bFdENgU<~YHVDU9)V9B;%VCg=>z_PlMf#p;M z1ItTm23Afc23E}l46L4N46Hsy46NBX46HpV46IXG7+AOYF|b}2U|{|Bje$*c0|T2$ zFaui%F9TayCEV4d=ofstiuX-Y{VknYV*1=0|p zl#!BC1Z6Yireqc+78K;b_&}PGB|bB!xkF@ohX~_k#>s}lYLjJz6eg#Os7$UEQklF< zNLyMixuB>7s8lQ^5o|0YNV|JxiAQPDWO)&f>Cs}0>YP3+OY-x9;x3a5M8qbu2A?I$l3l57vqVFF@i SAZ7t#Rv>2E9-zaXSO);W23tb_ diff --git a/tests/media/audiobook.m4b b/tests/media/audiobook.m4b index 45a0390e64e813d4c755b5743d83d171013f8451..fdc9008287d244a908b3b694165d6383f3d477af 100644 GIT binary patch delta 282 zcmaFzi~q?l{t5Dow>B!UaB*HOO({uaV9Yx^S(i(jDR05#D6TjM<&@OoWCjKX>6ApE zBm)B@5Hq*{#fmZuN;32FfINj9pc)`8fvhCBGB3ZNIJ0>2R<8bfxs^GUML-o|$SQm) zi!zfz`T}%;07%Q^rY3^SV@S@=)k`cW$Vt`93@Ob6n=O);n41cc^KtZZ4|Q~R1u{|W z^GVE0FHKAbsZmTWC@KNck}%tNfgA?s`~skb=@})>j@;WFxf!44u<_fZ6{V(bH>_YZ S$~`wZiYspNZ>}Cr)s^K%B@7G< yvXdw9h%_7XY&Yg%JetEMz?W8(n!25_lF^8Nx;9=RT9)x}k@f++HY5gT8)r$j}Ox}CE_cAk=zjhYicE4}2N8GXj+ymHp#StUH z3@Jhc7$Ez+HeM>KOM<(Fz$G#&L}QYS2^YF-ZfG4I(E%p(4&Vb{-m=4a+tme0?vsNb z1?v^CUg>2@?~h4Wbx3iAo@Y;+&mlUU4y_N1Oa&@ja5&IlL(ps?k6f=5iWs9;)J>34 zqnP3W+15DN@D?q@k+(Qw%QMDW>8JCI(NkNVXIrm+yq9fN$St+=^D0n_7;clC#@Aw| z=|;H_n$T5fQI^L2NiPfI=vv9hj?i2IBbDqho*X}@VEw3VoIc*KKb+S~sH@6O@oTIy zb!7ey&7JbIrJ9ZkCm#CA(3^!(AO+sYzf-c@G7Qxe7-U)U;^1I9oi>tY((gBV@u+f; z^U$)8-Lw@&dLkL~vf0hQMz-bBURR2uchyPJTyD0FBjTGCM$xvW%R;kEG`C9|x)I#b z>;hE$aW4&%d|R$>QtYmywcZHKd7RABFc@U{(dMIVx?Pj2icSjdLMOI2uJ+Tm6fV0W zw}(56;$$3dIJ#!7HXRpqFA64J;O`C@YUIe{kA5o2X(sKxPU9%s{|DJFp~i V1!HU|{pa9M@_zX^z1*vx{08^`wA%mx delta 66 zcmZo(FZS?~zy@Z<$tsMVlUFku^M^#b1~D)&umQ1=fuUKmAJcX}CdRO$=?!^|2iljE UFaj~t_9Z3Ewp*q%PiJia0Gr1Y_y7O^ From 0e8c55d1dffb3e47d2ede1bc5f3a1ac91c776841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Sun, 4 Feb 2024 13:05:36 +0100 Subject: [PATCH 2/2] docs --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2d3e208..258b444 100644 --- a/README.md +++ b/README.md @@ -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` ``` @@ -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`.