Initial bookinfo
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/vendor/*
|
||||
.idea
|
||||
@@ -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": {
|
||||
|
||||
54
composer.lock
generated
54
composer.lock
generated
@@ -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",
|
||||
|
||||
19
src/Api/AbstractBookInfo.php
Normal file
19
src/Api/AbstractBookInfo.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Techtube\Bookinfo\Api;
|
||||
|
||||
abstract class AbstractBookInfo
|
||||
{
|
||||
protected string $author;
|
||||
protected string $isbn;
|
||||
protected string $description;
|
||||
protected string $title;
|
||||
protected string $category;
|
||||
protected string $cover_url;
|
||||
protected int $pages;
|
||||
protected string $series;
|
||||
protected int $volume;
|
||||
protected string $language;
|
||||
protected string $datePublished;
|
||||
|
||||
}
|
||||
29
src/BookInfo.php
Normal file
29
src/BookInfo.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Techtube\Bookinfo;
|
||||
|
||||
use DiDom\Document;
|
||||
use Techtube\Bookinfo\Api\AbstractBookInfo;
|
||||
|
||||
class BookInfo extends AbstractBookInfo
|
||||
{
|
||||
public function __construct($url)
|
||||
{
|
||||
$document = new Document($url, true);
|
||||
$jsonInfo = json_decode($document->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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user