mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-10 08:58:50 +00:00
* refactor * feat: custom http ua in AO3, #3188
This commit is contained in:
parent
933be15a77
commit
a13c4624fb
@ -34,8 +34,30 @@ class AO3Bridge extends BridgeAbstract
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
// Feed for lists of works (e.g. recent works, search results, filtered tags,
|
public function collectData()
|
||||||
// bookmarks, series, collections).
|
{
|
||||||
|
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).
|
||||||
|
*/
|
||||||
private function collectList($url)
|
private function collectList($url)
|
||||||
{
|
{
|
||||||
$html = getSimpleHTMLDOM($url);
|
$html = getSimpleHTMLDOM($url);
|
||||||
@ -64,11 +86,14 @@ class AO3Bridge extends BridgeAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feed for recent chapters of a specific work.
|
/**
|
||||||
|
* Feed for recent chapters of a specific work.
|
||||||
|
*/
|
||||||
private function collectWork($id)
|
private function collectWork($id)
|
||||||
{
|
{
|
||||||
$url = self::URI . "/works/$id/navigate";
|
$url = self::URI . "/works/$id/navigate";
|
||||||
$html = getSimpleHTMLDOM($url);
|
$response = _http_request($url, ['useragent' => 'rss-bridge bot (https://github.com/RSS-Bridge/rss-bridge)']);
|
||||||
|
$html = \str_get_html($response['body']);
|
||||||
$html = defaultLinkTo($html, self::URI);
|
$html = defaultLinkTo($html, self::URI);
|
||||||
|
|
||||||
$this->title = $html->find('h2 a', 0)->plaintext;
|
$this->title = $html->find('h2 a', 0)->plaintext;
|
||||||
@ -93,27 +118,6 @@ class AO3Bridge extends BridgeAbstract
|
|||||||
$this->items = array_reverse($this->items);
|
$this->items = array_reverse($this->items);
|
||||||
}
|
}
|
||||||
|
|
||||||
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';
|
|
||||||
return $this->collectList($url);
|
|
||||||
case 'List':
|
|
||||||
return $this->collectList(
|
|
||||||
$this->getInput('url')
|
|
||||||
);
|
|
||||||
case 'Work':
|
|
||||||
return $this->collectWork(
|
|
||||||
$this->getInput('id')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
$name = parent::getName() . " $this->queriedContext";
|
$name = parent::getName() . " $this->queriedContext";
|
||||||
|
@ -125,6 +125,8 @@ function getContents(
|
|||||||
$httpHeadersNormalized[$headerName] = $headerValue;
|
$httpHeadersNormalized[$headerName] = $headerValue;
|
||||||
}
|
}
|
||||||
$config = [
|
$config = [
|
||||||
|
'useragent' => Configuration::getConfig('http', 'useragent'),
|
||||||
|
'timeout' => Configuration::getConfig('http', 'timeout'),
|
||||||
'headers' => array_merge($defaultHttpHeaders, $httpHeadersNormalized),
|
'headers' => array_merge($defaultHttpHeaders, $httpHeadersNormalized),
|
||||||
'curl_options' => $curlOptions,
|
'curl_options' => $curlOptions,
|
||||||
];
|
];
|
||||||
@ -215,8 +217,8 @@ function getContents(
|
|||||||
function _http_request(string $url, array $config = []): array
|
function _http_request(string $url, array $config = []): array
|
||||||
{
|
{
|
||||||
$defaults = [
|
$defaults = [
|
||||||
'useragent' => Configuration::getConfig('http', 'useragent'),
|
'useragent' => null,
|
||||||
'timeout' => Configuration::getConfig('http', 'timeout'),
|
'timeout' => 5,
|
||||||
'headers' => [],
|
'headers' => [],
|
||||||
'proxy' => null,
|
'proxy' => null,
|
||||||
'curl_options' => [],
|
'curl_options' => [],
|
||||||
@ -236,7 +238,9 @@ function _http_request(string $url, array $config = []): array
|
|||||||
$httpHeaders[] = sprintf('%s: %s', $name, $value);
|
$httpHeaders[] = sprintf('%s: %s', $name, $value);
|
||||||
}
|
}
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']);
|
if ($config['useragent']) {
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']);
|
||||||
|
}
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']);
|
curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']);
|
||||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||||
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||||
|
Loading…
Reference in New Issue
Block a user