-
Notifications
You must be signed in to change notification settings - Fork 1
/
originSearch.php
163 lines (140 loc) · 4.21 KB
/
originSearch.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
require_once(dirname(__FILE__) . '/../util_themoviedb.php');
$SUPPORTED_TYPE = array('movie');
$SUPPORTED_PROPERTIES = array('title');
function GetMovieInfo($movie_data, $data)
{
$data['title'] = $movie_data->title;
$data['original_title'] = $movie_data->original_title;
$data['tagline'] = $movie_data->tagline;
$data['original_available'] = $movie_data->release_date;
$data['summary'] = $movie_data->overview;
foreach ($movie_data->genres as $item) {
if (!in_array($item->name, $data['genre'])) {
array_push($data['genre'], $item->name);
}
}
//extra
$data['extra'] = array();
$data['extra'][PLUGINID] = array('reference' => array());
$data['extra'][PLUGINID]['reference']['themoviedb'] = $movie_data->id;
if (isset($movie_data->imdb_id)) {
$data['extra'][PLUGINID]['reference']['imdb'] = $movie_data->imdb_id;
}
if ((float)$movie_data->vote_average) {
$data['extra'][PLUGINID]['rating'] = array('themoviedb' => (float)$movie_data->vote_average);
}
if (isset($movie_data->poster_path)) {
$data['extra'][PLUGINID]['poster'] = array(BANNER_URL . $movie_data->poster_path);
}
if (isset($movie_data->backdrop_path)) {
$data['extra'][PLUGINID]['backdrop'] = array(BACKDROUP_URL . $movie_data->backdrop_path);
}
if (isset($movie_data->belongs_to_collection)) {
$data['extra'][PLUGINID]['collection_id'] = array('themoviedb' => $movie_data->belongs_to_collection->id);
}
return $data;
}
function GetCastInfo($cast_data, $data)
{
// actor
foreach ($cast_data->cast as $item) {
if (!in_array($item->name, $data['actor'])) {
array_push($data['actor'], $item->name);
}
}
// director & writer
foreach ($cast_data->crew as $item) {
if (strcasecmp($item->department, 'Directing') == 0) {
if (!in_array($item->name, $data['director'])) {
array_push($data['director'], $item->name);
}
}
if (strcasecmp($item->department, 'Writing') == 0) {
if (!in_array($item->name, $data['writer'])) {
array_push($data['writer'], $item->name);
}
}
}
return $data;
}
function GetCertificateInfo($releases_data, $data)
{
$certificate = array();
foreach ($releases_data->countries as $item) {
if ('' === $item->certification) {
continue;
}
$name = strcasecmp($item->iso_3166_1, 'us') == 0 ? 'USA' : $item->iso_3166_1;
$certificate[$name] = $item->certification;
}
$data['certificate'] = $certificate;
return $data;
}
/**
* @brief get metadata for multiple movies
* @param $query_data [in] a array contains multiple movie item
* @param $lang [in] a language
* @return [out] a result array
*/
function GetMetadata($query_data, $lang)
{
global $DATA_TEMPLATE;
//Foreach query result
$result = array();
foreach($query_data as $item) {
//If languages are different, skip it
if (0 != strcmp($item['lang'], $lang)) {
continue;
}
//Copy template
$data = $DATA_TEMPLATE;
//Get movie
$movie_data = GetRawdata("movie", array('id' => $item['id'], 'lang' => $item['lang']), DEFAULT_EXPIRED_TIME);
if (!$movie_data) {
continue;
}
$data = GetMovieInfo($movie_data, $data);
//Get cast
$cast_data = GetRawdata("cast", array('id' => $item['id']), DEFAULT_EXPIRED_TIME);
if ($cast_data) {
$data = GetCastInfo($cast_data, $data);
}
//Get certificates
$releases_data = GetRawdata("releases", array('id' => $item['id']), DEFAULT_EXPIRED_TIME);
if ($releases_data) {
$data = GetCertificateInfo($releases_data, $data);
}
//Append to result
$result[] = $data;
}
return $result;
}
function ProcessOrigin($input, $lang, $type, $limit, $search_properties, $allowguess, $id)
{
$title = $input['title'];
$year = ParseYear($input['original_available']);
$lang = ConvertToAPILang($lang);
if (!$lang) {
return array();
}
if (0 < $id) {
// if haved id, output metadata directly.
return GetMetadata(array(array('id' => $id, 'lang' => $lang)), $lang);
}
//Search
$query_data = array();
$titles = GetGuessingList($title, $allowguess);
foreach ($titles as $checkTitle) {
if (empty($checkTitle)) {
continue;
}
$query_data = Query($checkTitle, $year, $lang, $limit);
if (0 < count($query_data)) {
break;
}
}
//Get metadata
return GetMetadata($query_data, $lang);
}
?>