2019-05-06 14:28:42 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AO3Bridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'AO3';
|
|
|
|
const URI = 'https://archiveofourown.org/';
|
|
|
|
const CACHE_TIMEOUT = 1800;
|
|
|
|
const DESCRIPTION = 'Returns works or chapters from Archive of Our Own';
|
|
|
|
const MAINTAINER = 'Obsidienne';
|
|
|
|
const PARAMETERS = [
|
|
|
|
'List' => [
|
|
|
|
'url' => [
|
|
|
|
'name' => 'url',
|
|
|
|
'required' => true,
|
|
|
|
// Example: F/F tag, complete works only
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => 'https://archiveofourown.org/works?work_search[complete]=T&tag_id=F*s*F',
|
2019-05-06 14:28:42 +03:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'Bookmarks' => [
|
|
|
|
'user' => [
|
|
|
|
'name' => 'user',
|
|
|
|
'required' => true,
|
|
|
|
// Example: Nyaaru's bookmarks
|
|
|
|
'exampleValue' => 'Nyaaru',
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
2019-05-06 14:28:42 +03:00
|
|
|
],
|
|
|
|
'Work' => [
|
|
|
|
'id' => [
|
|
|
|
'name' => 'id',
|
|
|
|
'required' => true,
|
|
|
|
// Example: latest chapters from A Better Past by LysSerris
|
|
|
|
'exampleValue' => '18181853',
|
|
|
|
],
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2019-05-06 14:28:42 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-12-13 11:53:42 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'Bookmarks':
|
|
|
|
$user = $this->getInput('user');
|
|
|
|
$this->title = $user;
|
|
|
|
$url = self::URI
|
|
|
|
. '/users/' . $user
|
|
|
|
. '/bookmarks?bookmark_search[sort_column]=bookmarkable_date';
|
|
|
|
$this->collectList($url);
|
|
|
|
break;
|
|
|
|
case 'List':
|
|
|
|
$this->collectList($this->getInput('url'));
|
|
|
|
break;
|
|
|
|
case 'Work':
|
|
|
|
$this->collectWork($this->getInput('id'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Feed for lists of works (e.g. recent works, search results, filtered tags,
|
|
|
|
* bookmarks, series, collections).
|
|
|
|
*/
|
2019-05-06 14:28:42 +03:00
|
|
|
private function collectList($url)
|
|
|
|
{
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($url);
|
2019-05-06 14:28:42 +03:00
|
|
|
$html = defaultLinkTo($html, self::URI);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
foreach ($html->find('.index.group > li') as $element) {
|
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$title = $element->find('div h4 a', 0);
|
|
|
|
if (!isset($title)) {
|
|
|
|
continue; // discard deleted works
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-05-06 14:28:42 +03:00
|
|
|
$item['title'] = $title->plaintext;
|
|
|
|
$item['content'] = $element;
|
|
|
|
$item['uri'] = $title->href;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$strdate = $element->find('div p.datetime', 0)->plaintext;
|
|
|
|
$item['timestamp'] = strtotime($strdate);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$chapters = $element->find('dl dd.chapters', 0);
|
|
|
|
// bookmarked series and external works do not have a chapters count
|
|
|
|
$chapters = (isset($chapters) ? $chapters->plaintext : 0);
|
|
|
|
$item['uid'] = $item['uri'] . "/$strdate/$chapters";
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-05-06 14:28:42 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-12-13 11:53:42 +03:00
|
|
|
/**
|
|
|
|
* Feed for recent chapters of a specific work.
|
|
|
|
*/
|
2019-05-06 14:28:42 +03:00
|
|
|
private function collectWork($id)
|
|
|
|
{
|
|
|
|
$url = self::URI . "/works/$id/navigate";
|
2023-07-16 23:07:34 +03:00
|
|
|
$httpClient = RssBridge::getHttpClient();
|
|
|
|
|
|
|
|
$response = $httpClient->request($url, [
|
|
|
|
'useragent' => 'rss-bridge bot (https://github.com/RSS-Bridge/rss-bridge)',
|
|
|
|
]);
|
|
|
|
|
2022-12-13 11:53:42 +03:00
|
|
|
$html = \str_get_html($response['body']);
|
2019-05-06 14:28:42 +03:00
|
|
|
$html = defaultLinkTo($html, self::URI);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$this->title = $html->find('h2 a', 0)->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
foreach ($html->find('ol.index.group > li') as $element) {
|
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$item['title'] = $element->find('a', 0)->plaintext;
|
|
|
|
$item['content'] = $element;
|
|
|
|
$item['uri'] = $element->find('a', 0)->href;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$strdate = $element->find('span.datetime', 0)->plaintext;
|
|
|
|
$strdate = str_replace('(', '', $strdate);
|
|
|
|
$strdate = str_replace(')', '', $strdate);
|
|
|
|
$item['timestamp'] = strtotime($strdate);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$item['uid'] = $item['uri'] . "/$strdate";
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
$this->items = array_reverse($this->items);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
$name = parent::getName() . " $this->queriedContext";
|
|
|
|
if (isset($this->title)) {
|
|
|
|
$name .= " - $this->title";
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-05-06 14:28:42 +03:00
|
|
|
return $name;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-06 14:28:42 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return self::URI . '/favicon.ico';
|
|
|
|
}
|
|
|
|
}
|