-
Notifications
You must be signed in to change notification settings - Fork 2
/
film.php
142 lines (119 loc) · 3.86 KB
/
film.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace jinni;
/**
* A model to represent a film on Jinni.
* This is initialised internally
*/
class film {
const CONTENT_FILM = 'FeatureFilm';
const CONTENT_TV = 'TvSeries';
const CONTENT_SHORTFILM = 'Short';
/**
* @var http
*/
protected $http;
/**
* @var string i.e. /movies/$urlName/
*/
public $urlName;
protected $rating;
protected $name;
protected $filmId;
protected $year;
protected $contentType;
protected $imdb;
public function __construct(http $http) {
$this->http = $http;
}
public static function validContentType($type) {
if (in_array($type, array(static::CONTENT_FILM, static::CONTENT_TV, static::CONTENT_SHORTFILM))) {
return true;
}
return false;
}
public function rate($rating) {
//callCount=1 page=/movies/the-corporation/ httpSessionId=1C3514898A5FED51780407C569A6316E.web2_node3 scriptSessionId=3C675DDBB02222BE8CB51E2415259E99676 c0-scriptName=AjaxUserRatingBean c0-methodName=submiteContentUserRating c0-id=0 c0-param0=number:4060 c0-param1=number:7 batchId=0
$response = $this->http->apiCall('AjaxUserRatingBean', 'submitContentUserRating', array($this->getFilmId(), $rating));
if (false === strpos($response, 'Thank you for rating')) {
throw new \Exception('Invalid response from server');
}
$this->setRating($rating);
}
public function setRating($rating) {
$this->rating = (int)$rating;
}
public function getRating() {
if (!isset($this->rating)) {
// can get this via the ajax api
$rating = $this->http->apiCall('AjaxUserRatingBean', 'getContentRating', array($this->getFilmId()));
if (is_object($rating)) {
$this->rating = $rating->rate;
}
}
return $this->rating;
}
public function setName($name) {
$this->name = $name;
}
public function getName() {
if (!isset($this->name)) {
$this->getInfo();
}
return $this->name;
}
public function setFilmId($id) {
$this->filmId = (int)$id;
}
public function getFilmId() {
if (!isset($this->filmId)) {
$this->getInfo();
}
return $this->filmId;
}
public function setUrlName($urlName) {
$this->urlName = $urlName;
}
public function getUrlName() {
if (!isset($this->urlName)) {
$headers = $this->http->getPage('/discovery.html', array('search' => '@#@test-['.$this->getFilmId().']T'), false, true);
if (0 == preg_match("@Location: http://www.jinni.com/(?:movies|tv)/([^/]+)/@i", $headers, $matches)) {
throw new \Exception('No urlName available');
}
$this->urlName = $matches[1];
}
return $this->urlName;
}
public function setYear($year) {
$this->year = (int)$year;
}
public function getYear() {
if (!isset($this->year)) {
$this->getInfo();
}
return $this->year;
}
public function setContentType($type) {
$this->contentType = $type;
}
public function getContentType() {
return $this->contentType;
}
public function getImdb() {
if (!isset($this->imdb)) {
$this->getInfo();
}
return $this->imdb;
}
public function setImdb($imdb) {
$this->imdb = (int)$imdb;
}
protected function getInfo() {
$content = $this->http->getPage('/movies/'.$this->getUrlName(), null, true);
if (preg_match('@"http://www.imdb.com/title/tt(\d+)"@', $content, $matches)) {
$this->imdb = (int)$matches[1];
}
if (preg_match("@<title>.+, (\d{4})<\/title>@", $content, $matches)) {
$this->setYear($matches[1]);
}
}
}