diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b493ad1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/vendor/* +.idea diff --git a/composer.json b/composer.json index 1af9277..02395e3 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,8 @@ "description": "Package to find a book and return a book info from lubimyczytac.pl", "type": "library", "require": { - "guzzlehttp/guzzle": "^7.4" + "guzzlehttp/guzzle": "^7.4", + "imangazaliev/didom": "^2.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index ceffdbe..d9d2cb1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8d616a1551c2cc41cae1d8acc5073d2f", + "content-hash": "4dd12205ae74abc5b0e4c70db59e99ab", "packages": [ { "name": "guzzlehttp/guzzle", @@ -329,6 +329,58 @@ ], "time": "2022-03-20T21:55:58+00:00" }, + { + "name": "imangazaliev/didom", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/Imangazaliev/DiDOM.git", + "reference": "87f7089d95aef7fd09dc68826cfa245b90f3040b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/87f7089d95aef7fd09dc68826cfa245b90f3040b", + "reference": "87f7089d95aef7fd09dc68826cfa245b90f3040b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-iconv": "*", + "php": ">=7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "DiDom\\": "src/DiDom/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Imangazaliev Muhammad", + "email": "imangazalievm@gmail.com" + } + ], + "description": "Simple and fast HTML parser", + "homepage": "https://github.com/Imangazaliev/DiDOM", + "keywords": [ + "didom", + "html", + "parser", + "xml" + ], + "support": { + "issues": "https://github.com/Imangazaliev/DiDOM/issues", + "source": "https://github.com/Imangazaliev/DiDOM/tree/2.0" + }, + "time": "2022-05-08T01:48:13+00:00" + }, { "name": "psr/http-client", "version": "1.0.1", diff --git a/src/Api/AbstractBookInfo.php b/src/Api/AbstractBookInfo.php new file mode 100644 index 0000000..fae3f5f --- /dev/null +++ b/src/Api/AbstractBookInfo.php @@ -0,0 +1,19 @@ +first('script[type="application/ld+json"]')->text()); + $this->author = $document->first('meta[property="books:author"]')->getAttribute('content'); + $this->isbn = $document->first('meta[property="books:isbn"]')->getAttribute('content'); + $this->description = $document->first('meta[property="og:description"]')->getAttribute('content'); + $this->title = trim($document->first('h1.book__title')->text()); + $this->category = trim($document->first('.book__category')->text()); + $this->cover_url = $document->first('meta[property="og:image"]')->getAttribute('content'); + $this->pages = (int)$document->first('span.book__pages')?->text(); + if (preg_match('#(.*) \(tom (\d*)\)#ism', trim($document->first('a[href*="/cykl/"]')->text()), $series)) { + $this->series = $series[1]; + $this->volume = $series[2]; + } + $this->language = $jsonInfo->inLanguage ?? null; + $this->datePublished = $jsonInfo->datePublished ?? null; + } +} +