[TraktBridge] new bridge (#3534)

This commit is contained in:
Ryan Stafford 2023-07-15 09:12:11 -04:00 committed by GitHub
parent 73d88dda46
commit c8039d483b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 70 additions and 0 deletions

70
bridges/TraktBridge.php Normal file
View 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;
}
}
}