mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-21 17:15:25 +03:00
[TraktBridge] new bridge (#3534)
This commit is contained in:
parent
73d88dda46
commit
c8039d483b
1 changed files with 70 additions and 0 deletions
70
bridges/TraktBridge.php
Normal file
70
bridges/TraktBridge.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
class TraktBridge extends BridgeAbstract
|
||||
{
|
||||
const NAME = 'Trakt Bridge';
|
||||
const DESCRIPTION = "Returns a user's watch history";
|
||||
const URI = 'https://www.trakt.tv';
|
||||
|
||||
const PARAMETERS = [
|
||||
[
|
||||
'username' => [
|
||||
'name' => 'username',
|
||||
'required' => true
|
||||
],
|
||||
'hide_shows' => [
|
||||
'name' => 'Hide shows',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Hide shows',
|
||||
],
|
||||
|
||||
],
|
||||
];
|
||||
|
||||
public function detectParameters($url)
|
||||
{
|
||||
if (preg_match('/trakt\.tv\/users\/(.*?)\//', $url, $matches) > 0) {
|
||||
return [
|
||||
'username' => $matches[1]
|
||||
];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
$username = $this->getInput('username');
|
||||
$dom = getSimpleHTMLDOMCached(self::URI . '/users/' . $username . '/history');
|
||||
$this->feedName = $dom->find('#avatar-wrapper h1 a', 0)->plaintext;
|
||||
$this->iconURL = $dom->find('img.avatar', 0)->{'src'};
|
||||
|
||||
foreach ($dom->find('#history-items .posters', 0)->find('div.grid-item') as $div) {
|
||||
if ($this->getInput('hide_shows') && $div->{'data-type'} != 'movie') {
|
||||
continue;
|
||||
}
|
||||
$item = [];
|
||||
$item['author'] = $this->feedName;
|
||||
$item['title'] = $div->find('img.real', 0)->{'title'};
|
||||
$item['timestamp'] = $div->find('.format-date', 0)->plaintext;
|
||||
$item['content'] = '<img src="' . $div->find('img.real', 0)->{'data-original'} . '">';
|
||||
$item['uri'] = self::URI . $div->{'data-url'};
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
public function getName()
|
||||
{
|
||||
if (empty($this->feedName)) {
|
||||
return parent::getName();
|
||||
} else {
|
||||
return $this->feedName;
|
||||
}
|
||||
}
|
||||
public function getIcon()
|
||||
{
|
||||
if (empty($this->iconURL)) {
|
||||
return parent::getIcon();
|
||||
} else {
|
||||
return $this->iconURL;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue