From 406d6a8f8d5d2a35db6ab575bcedf1b4c55adf40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?= Date: Thu, 2 Oct 2025 12:15:17 +0200 Subject: [PATCH 1/4] Update search to website changes --- src/Api/AbstractBookInfo.php | 3 ++- src/BookFinder.php | 2 +- src/DataParser.php | 11 +++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Api/AbstractBookInfo.php b/src/Api/AbstractBookInfo.php index 99cecb4..54ecf7a 100644 --- a/src/Api/AbstractBookInfo.php +++ b/src/Api/AbstractBookInfo.php @@ -13,7 +13,8 @@ abstract class AbstractBookInfo public array $cover_url; public int $pages; public string $cycle; - public int $volume; + public string $cycleUrl; + public string $volume; public ?string $language; public string $datePublished; public ?string $publisher; diff --git a/src/BookFinder.php b/src/BookFinder.php index ee7ec90..d0c8389 100644 --- a/src/BookFinder.php +++ b/src/BookFinder.php @@ -28,7 +28,7 @@ class BookFinder private function getSearchUrl(string $phrase): string { - return self::$searchUrl . $phrase; + return sprintf('%s%s', self::$searchUrl, $phrase); } } diff --git a/src/DataParser.php b/src/DataParser.php index 189113d..8e7f8d3 100644 --- a/src/DataParser.php +++ b/src/DataParser.php @@ -46,8 +46,10 @@ class DataParser */ public function searchPage(Document $document): array { - $books = $document->find('#search .authorAllBooks__single'); - + $books = $document->find('#ksiazki .authorAllBooks__single'); + //https://lubimyczytac.pl/searcher/getNextResults/ksiazki + //echo $document->html(); + print_r($books); $booksInfo = []; if ($document->has('#searchksiazki')) { foreach ($books as $book) { @@ -56,6 +58,11 @@ class DataParser $bookInfo->author = trim($book->first('.authorAllBooks__singleTextAuthor')->text()); $bookInfo->url = $book->first('button[data-book-url]')->getAttribute('data-book-url'); $bookInfo->cover_url = $this->generateCoverUrls($book->first('.img-fluid')->getAttribute('data-src')); + if (preg_match('#(.*) \(tom (.*)\)#ism', trim($book->first('a[href*="/cykl/"]')?->text() ?? ''), $series)) { + $bookInfo->cycle = $series[1]; + $bookInfo->volume = $series[2]; + $bookInfo->cycleUrl = $book->first('a[href*="/cykl/"]')?->href; + } $booksInfo[] = $bookInfo; } } -- 2.52.0 From 8c5ae22081fc497d1a46fdc40c3679e19bbf29fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?= Date: Thu, 2 Oct 2025 12:44:04 +0200 Subject: [PATCH 2/4] Add translator --- src/Api/AbstractBookInfo.php | 1 + src/DataParser.php | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/AbstractBookInfo.php b/src/Api/AbstractBookInfo.php index 54ecf7a..bf07c07 100644 --- a/src/Api/AbstractBookInfo.php +++ b/src/Api/AbstractBookInfo.php @@ -18,4 +18,5 @@ abstract class AbstractBookInfo public ?string $language; public string $datePublished; public ?string $publisher; + public ?string $translator; } \ No newline at end of file diff --git a/src/DataParser.php b/src/DataParser.php index 8e7f8d3..7417896 100644 --- a/src/DataParser.php +++ b/src/DataParser.php @@ -4,6 +4,7 @@ namespace Techtube\Bookinfo; use DiDom\Document; use DiDom\Exceptions\InvalidSelectorException; +use DiDom\Query; use JetBrains\PhpStorm\ArrayShape; use Techtube\Bookinfo\Api\AbstractBookInfo; @@ -35,6 +36,7 @@ class DataParser } $info->language = $jsonInfo?->inLanguage ?? trim($document->xpath("//*[contains(text(), 'Język:')]")[0]->nextSibling('dd')->text()); $info->datePublished = $jsonInfo?->datePublished ?? null; + $info->translator = trim($document->first("//*[contains(text(), 'Tłumacz:')]", Query::TYPE_XPATH)?->nextSibling('dd')?->text() ?? ''); return $info; } @@ -47,9 +49,6 @@ class DataParser public function searchPage(Document $document): array { $books = $document->find('#ksiazki .authorAllBooks__single'); - //https://lubimyczytac.pl/searcher/getNextResults/ksiazki - //echo $document->html(); - print_r($books); $booksInfo = []; if ($document->has('#searchksiazki')) { foreach ($books as $book) { -- 2.52.0 From e8081cd898d497c7525c565007bfa4b263b1cf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?= Date: Thu, 2 Oct 2025 13:01:28 +0200 Subject: [PATCH 3/4] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 02395e3..a8a3cc3 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ }, "authors": [ { - "name": "kplaczek", - "email": "kplaczek@wi.ps.pl" + "name": "Krzysztof Płaczek", + "email": "krzysztofplaczek@techtube.pl" } ] } -- 2.52.0 From 171c0503684cd35e0cac050f3928b98880ee1d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?= Date: Fri, 3 Oct 2025 15:08:45 +0200 Subject: [PATCH 4/4] Add original title --- README.md | 8 +++++++- src/Api/AbstractBookInfo.php | 1 + src/DataParser.php | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 47f6796..d70b9f0 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,13 @@ Place this in the composer.json. }] } ``` -Then execute +Then execute to get latest version: + +```bash +composer require techtube/bookinfo +``` + +or this to get specific version: ```bash composer require techtube/bookinfo:"1.0.4" diff --git a/src/Api/AbstractBookInfo.php b/src/Api/AbstractBookInfo.php index bf07c07..75410d2 100644 --- a/src/Api/AbstractBookInfo.php +++ b/src/Api/AbstractBookInfo.php @@ -9,6 +9,7 @@ abstract class AbstractBookInfo public string $isbn; public string $description; public string $title; + public string $originalTitle; public string $category; public array $cover_url; public int $pages; diff --git a/src/DataParser.php b/src/DataParser.php index 7417896..d0722a7 100644 --- a/src/DataParser.php +++ b/src/DataParser.php @@ -25,6 +25,7 @@ class DataParser $info->isbn = $document->first('meta[property="books:isbn"]')->getAttribute('content'); $info->description = trim($document->first('#book-description p')->text()); $info->title = trim($document->first('h1.book__title')->text()); + $info->originalTitle = trim($document->first("//*[contains(text(), 'Tytuł oryginału:')]", Query::TYPE_XPATH)?->nextSibling('dd')?->text() ?? ''); $info->category = trim($document->first('.book__category')->text()); $info->cover_url = $this->generateCoverUrls( $document->first('meta[property="og:image"]')->getAttribute('content') -- 2.52.0