From 7d5698a75fcc5b4a7c201e5bbb5b81787516ac78 Mon Sep 17 00:00:00 2001 From: Ololbu Date: Fri, 9 Dec 2022 15:05:08 +0500 Subject: [PATCH] [TapasBridge] New bridge (#3184) * [TapasBridge] New bridge * [TapasBridge] Delete comment * [TapasBridge] Delete context * [TapasBridge] Delete context again * [TapasBridge] Convert double quotes do single quotes * [TapasBridge] Fix some lint errors * [TapasBridge] Fix indentation style * [TapasBridge] Fix some lint errors --- bridges/TapasBridge.php | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 bridges/TapasBridge.php diff --git a/bridges/TapasBridge.php b/bridges/TapasBridge.php new file mode 100644 index 00000000..e512ad48 --- /dev/null +++ b/bridges/TapasBridge.php @@ -0,0 +1,87 @@ + [ + 'name' => 'URL\'s title / ID', + 'type' => 'text', + 'required' => true, + 'title' => 'Insert title from URL (tapas.io/series/THIS_TITLE/info) or title ID', + ], + 'extend_content' => [ + 'name' => 'Include on-site content', + 'type' => 'checkbox', + 'title' => 'Activate to include images or chapter text', + ], +// 'force_title' => [ +// 'name' => 'Force title use', +// 'type' => 'checkbox', +// 'title' => 'If you have trouble with feed getting, try this option.', +// ], + ] + ]; + + protected $id; + + public function getURI() + { + if ($this->id) { + return self::URI . 'rss/series/' . $this->id; + } else { + return self::URI . 'series/' . $this->getInput('title') . '/info/'; + } + return self::URI; + } + + protected function parseItem($feedItem) + { + $item = parent::parseItem($feedItem); + + $namespaces = $feedItem->getNamespaces(true); + if (isset($namespaces['content'])) { + $description = $feedItem->children($namespaces['content']); + if (isset($description->encoded)) { + $item['content'] = (string)$description->encoded; + } + } + + if ($this->getInput('extend_content')) { + $html = getSimpleHTMLDOM($item['uri']) or returnServerError('Could not request ' . $this->getURI()); + if (!$item['content']) { + $item['content'] = ''; + } + if ($html->find('article.main__body', 0)) { + foreach ($html->find('article', 0)->find('img') as $line) { + $item['content'] .= ''; + } + } elseif ($html->find('article.main__body--book', 0)) { + $item['content'] .= $html->find('article.viewer__body', 0)->innertext; + } else { + $item['content'] .= '

Locked episode

'; + $item['content'] .= '
' . $html->find('div.js-viewer-filter h5', 0)->plaintext . '
'; + } + } + + return $item; + } + + public function collectData() + { + if (preg_match('/^[\d]+$/', $this->getInput('title'))) { + $this->id = $this->getInput('title'); + } + if ($this->getInput('force_title') or !$this->id) { + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request ' . $this->getURI()); + $this->id = $html->find('meta[property$=":url"]', 0)->content; + $this->id = str_ireplace(['tapastic://series/', '/info'], '', $this->id); + } + $this->collectExpandableDatas($this->getURI()); + } +}