-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
422 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
require_once(dirname(__FILE__) . '/utils.php'); | ||
|
||
$SUPPORTED_TYPE = array('movie'); | ||
$SUPPORTED_PROPERTIES = array('title'); | ||
|
||
function GetMovieInfoDouban($movie_data, $data) | ||
{ | ||
/** | ||
参考 https://developers.douban.com/wiki/?title=movie_v2#subject | ||
*/ | ||
$data['title'] = $movie_data->title; | ||
$data['original_title'] = $movie_data->original_title; | ||
$data['tagline'] = implode(',', $movie_data->aka); | ||
$data['original_available'] = $movie_data->original_available; // add-on | ||
$data['summary'] = $movie_data->summary; | ||
|
||
//extra | ||
$data['extra'] = array(); | ||
$data['extra'][DOUBAN_PLUGINID] = array('reference' => array()); | ||
$data['extra'][DOUBAN_PLUGINID]['reference']['themoviedb'] = $movie_data->id; | ||
$data['doubandb'] = true; | ||
|
||
if (isset($movie_data->imdb_id)) { | ||
$data['extra'][DOUBAN_PLUGINID]['reference']['imdb'] = $movie_data->imdb; // add-on | ||
} | ||
if ((float)$movie_data->rating) { | ||
$data['extra'][DOUBAN_PLUGINID]['rating'] = array('themoviedb' => $movie_data->rating->average); | ||
} | ||
if (isset($movie_data->images)) { | ||
$data['extra'][DOUBAN_PLUGINID]['poster'] = array($movie_data->images->large); | ||
} | ||
if (isset($movie_data->backdrop_path)) { | ||
$data['extra'][DOUBAN_PLUGINID]['backdrop'] = array($movie_data->backdrop); // add-on | ||
} | ||
if (isset($movie_data->belongs_to_collection)) { | ||
$data['extra'][DOUBAN_PLUGINID]['collection_id'] = array('themoviedb' => $movie_data->belongs_to_collection->id); | ||
} | ||
|
||
// genre | ||
if( isset($movie_data->genres) ){ // add-on | ||
foreach ($movie_data->genres as $item) { | ||
if (!in_array($item, $data['genre'])) { | ||
array_push($data['genre'], $item); | ||
} | ||
} | ||
} | ||
// actor | ||
if( isset($movie_data->casts) ){ // add-on | ||
foreach ($movie_data->casts as $item) { | ||
if (!in_array($item->name, $data['actor'])) { | ||
array_push($data['actor'], $item->name); | ||
} | ||
} | ||
} | ||
|
||
// director | ||
if( isset($movie_data->directors) ){ | ||
foreach ($movie_data->directors as $item) { | ||
if (!in_array($item->name, $data['director'])) { | ||
array_push($data['director'], $item->name); | ||
} | ||
} | ||
} | ||
|
||
// writer | ||
if( isset($movie_data->writers) ){ // add-on | ||
foreach ($movie_data->writers as $item) { | ||
if (!in_array($item->name, $data['writer'])) { | ||
array_push($data['writer'], $item->name); | ||
} | ||
} | ||
} | ||
//error_log(print_r( $movie_data, true), 3, "/var/packages/VideoStation/target/plugins/syno_themoviedb/my-errors.log"); | ||
//error_log(print_r( $data, true), 3, "/var/packages/VideoStation/target/plugins/syno_themoviedb/my-errors.log"); | ||
return $data; | ||
} | ||
|
||
function GetMetadataDouban($query_data, $lang) | ||
{ | ||
global $DATA_TEMPLATE; | ||
|
||
//Foreach query result | ||
$result = array(); | ||
|
||
foreach($query_data as $item) { | ||
//Copy template | ||
$data = $DATA_TEMPLATE; | ||
|
||
//Get movie | ||
$movie_data = getDoubanMovieData($item['id']); | ||
|
||
if (!$movie_data) { | ||
continue; | ||
} | ||
$data = GetMovieInfoDouban($movie_data, $data); | ||
|
||
//Append to result | ||
$result[] = $data; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
function ProcessDouban($input, $lang, $type, $limit, $search_properties, $allowguess, $id) | ||
{ | ||
$title = $input['title']; | ||
if (!$lang) { | ||
return array(); | ||
} | ||
|
||
if (0 < $id) { | ||
// if haved id, output metadata directly. | ||
return GetMetadataDouban(array(array('id' => $id))); | ||
} | ||
|
||
//Search | ||
$query_data = array(); | ||
$query_data = getDoubanRawData($title, $limit); | ||
|
||
//Get metadata | ||
return GetMetadataDouban($query_data['subjects']); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/php | ||
<?php | ||
|
||
require_once(dirname(__FILE__) . '/../search.inc.php'); | ||
|
||
function Process($input, $lang, $type, $limit, $search_properties, $allowguess, $id) | ||
{ | ||
$RET = array(); | ||
if( 'chs' == $lang ){ | ||
require_once(dirname(__FILE__) . '/doubanSearch.php'); | ||
$RET = ProcessDouban($input, $lang, $type, $limit, $search_properties, $allowguess, $id); | ||
}else{ | ||
require_once(dirname(__FILE__) . '/originSearch.php'); | ||
$RET = ProcessOrigin($input, $lang, $type, $limit, $search_properties, $allowguess, $id); | ||
} | ||
return $RET; | ||
} | ||
|
||
PluginRun('Process'); | ||
?> |
Oops, something went wrong.