-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTraktBridge.php
75 lines (65 loc) · 2.59 KB
/
TraktBridge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class TraktBridge extends BridgeAbstract
{
const MAINTAINER = 'philipp-r';
const NAME = 'Trakt.tv';
const URI = 'https://trakt.tv/';
const CACHE_TIMEOUT = 3600; // 1hrs
const DESCRIPTION = 'Returns history or ratings for a public profile.';
const PARAMETERS = [ [
'u' => [
'type' => 'text',
'name' => 'username',
'exampleValue' => 'johndoe',
'title' => 'The profile must be public (Trakt.tv > Settings > uncheck Private)',
'required' => true,
],
'c' => [
'name' => 'contents',
'type' => 'list',
'required' => true,
'values' => array(
'history' => 'history',
'ratings' => 'ratings'
)
],
] ];
protected function getFullURI()
{
return $this->getURI()
. 'users/' . urlencode($this->getInput('u'))
. '/' . urlencode($this->getInput('c'));
}
protected function getItemFromElement($element)
{
$item = [];
$item['uri'] = html_entity_decode($element->find('meta[itemprop="url"]', 0)->content);
$item['uid'] = $item['uri'];
$item['author'] = urlencode($this->getInput('u'));
$item['timestamp'] = $element->find('div[class*="titles"]',0)->find('span[class="format-date"]', 0)->innertext;
$item['title'] = $element->find('meta[itemprop="name"]',0)->content;
if($element->find('meta[itemprop="name"]',1)->content){
// add the episode title
$item['title'] .= ": ".$element->find('meta[itemprop="name"]',1)->content;
}
// ratings: only show number of stars
if( $this->getInput('c') == "ratings" ){
$item['content'] = strip_tags( $element->find('div[class*="titles"]',0)->find('h4[class="ellipsify"]', 1)->innertext );
}
//history: show title + season x episode
elseif( $this->getInput('c') == "history" ){
$item['content'] = $element->find('meta[itemprop="name"]',0)->content;
if($element->find('div[class*="titles"]',0)->find('span[class="main-title-sxe"]', 0)->innertext){
$item['content'] .= " ".$element->find('div[class*="titles"]',0)->find('span[class="main-title-sxe"]', 0)->innertext;
}
}
return $item;
}
public function collectData()
{
$html = getSimpleHTMLDOMCached( $this->getFullURI() );
foreach ( $html->find('div[class*="grid-item col-xs-6 col-md-2 col-sm-3"]') as $element ) {
$this->items[] = $this->getItemFromElement($element);
}
}
}