1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

Add rating on XML API

This commit is contained in:
Afterster 2015-10-16 22:47:01 +02:00
parent 32c6e77806
commit bda9389c26
4 changed files with 77 additions and 57 deletions

View file

@ -1009,5 +1009,31 @@ class Api
debug_event('api', 'Sociable feature is not enabled.', 3); debug_event('api', 'Sociable feature is not enabled.', 3);
} }
} // last_shouts } // last_shouts
/**
* rate
* This rate a library item
* @param array $input
*/
public static function rate($input)
{
ob_end_clean();
$type = $input['type'];
$id = $input['id'];
$rating = $input['rating'];
if (!Core::is_library_item($type) || !$id) {
echo XML_Data::error('401', T_('Wrong library item type.'));
} else {
$item = new $type($id);
if (!$item->id) {
echo XML_Data::error('404', T_('Library item not found.'));
} else {
$rating = new Rating($id, $type);
$rating->set_rating($rating);
echo XML_Data::single_string('success');
}
}
} // rate
} // API class } // API class

View file

@ -447,7 +447,6 @@ class vainfo
$arr[] = trim($genre); $arr[] = trim($genre);
} }
} }
} else { } else {
$arr = $info[$field]; $arr = $info[$field];
} }
@ -1037,9 +1036,9 @@ class vainfo
$slash_type_preg = trim($slash_type,"~") . trim($slash_type,"~"); $slash_type_preg = trim($slash_type,"~") . trim($slash_type,"~");
} }
$file = pathinfo($filepath,PATHINFO_FILENAME); $file = pathinfo($filepath,PATHINFO_FILENAME);
preg_match("~(?<=\(\[\<\{)[1|2][0-9]{3}|[1|2][0-9]{3}~", $filepath,$tvyear); preg_match("~(?<=\(\[\<\{)[1|2][0-9]{3}|[1|2][0-9]{3}~", $filepath,$tvyear);
$results['year'] = !empty($tvyear) ? intval($tvyear[0]) : null; $results['year'] = !empty($tvyear) ? intval($tvyear[0]) : null;
if (in_array('tvshow', $this->gather_types)) { if (in_array('tvshow', $this->gather_types)) {
if (preg_match("~[Ss](\d+)[Ee](\d+)~", $file, $seasonEpisode)) { if (preg_match("~[Ss](\d+)[Ee](\d+)~", $file, $seasonEpisode)) {
$temp = preg_split("~(((\.|_|\s)[Ss]\d+(\.|_)*[Ee]\d+))~",$file,2); $temp = preg_split("~(((\.|_|\s)[Ss]\d+(\.|_)*[Ee]\d+))~",$file,2);
preg_match("~(?<=[Ss])\d+~", $file, $season); preg_match("~(?<=[Ss])\d+~", $file, $season);
@ -1054,8 +1053,7 @@ class vainfo
$temp = preg_split("~[\.\s\-\_][S|s]eason[\s\-\.\_](\d+)[\.\s\-\_]?\s?[e|E]pisode[\s\-\.\_](\d+)([\s\-\.\_])*~",$file,3); $temp = preg_split("~[\.\s\-\_][S|s]eason[\s\-\.\_](\d+)[\.\s\-\_]?\s?[e|E]pisode[\s\-\.\_](\d+)([\s\-\.\_])*~",$file,3);
preg_match("~(?<=[Ss]eason[\.\s\-\_])\d+~", $file, $season); preg_match("~(?<=[Ss]eason[\.\s\-\_])\d+~", $file, $season);
preg_match("~(?<=[Ee]pisode[\.\s\-\_])\d+~", $file, $episode); preg_match("~(?<=[Ee]pisode[\.\s\-\_])\d+~", $file, $episode);
} } else {
else {
if (preg_match("~[\_\-\.\s](\d)(\d\d)[\_\-\.\s]*~", $file, $seasonEpisode)) { if (preg_match("~[\_\-\.\s](\d)(\d\d)[\_\-\.\s]*~", $file, $seasonEpisode)) {
$temp = preg_split("~[\.\s\-\_](\d)(\d\d)[\.\s\-\_]~",$file); $temp = preg_split("~[\.\s\-\_](\d)(\d\d)[\.\s\-\_]~",$file);
$season[0] = $seasonEpisode[1]; $season[0] = $seasonEpisode[1];
@ -1159,11 +1157,10 @@ class vainfo
$commonabbr[] = '[1|2][0-9]{3}'; //Remove release year $commonabbr[] = '[1|2][0-9]{3}'; //Remove release year
//scan for brackets, braces, etc and ignore case. //scan for brackets, braces, etc and ignore case.
for ($i=0; $i< count($commonabbr);$i++) for ($i=0; $i< count($commonabbr);$i++) {
{ $commonabbr[$i] = "~\[*|\(*|\<*|\{*\b(?i)" . trim($commonabbr[$i]) . "\b\]*|\)*|\>*|\}*~";
$commonabbr[$i] = "~\[*|\(*|\<*|\{*\b(?i)" . trim($commonabbr[$i]) . "\b\]*|\)*|\>*|\}*~"; }
} $string = preg_replace($commonabbr,'',$name);
$string = preg_replace($commonabbr,'',$name);
return $string; return $string;
} }

View file

@ -113,7 +113,7 @@ class AmpacheTmdb
$title = $media_info['original_name'] ?: $media_info['title']; $title = $media_info['original_name'] ?: $media_info['title'];
$results = array(); $results = array();
if (in_array('movie', $gather_types)) { if (in_array('movie', $gather_types)) {
if (!empty($media_info['title'])) { if (!empty($media_info['title'])) {
$apires = $client->getSearchApi()->searchMovies($media_info['title']); $apires = $client->getSearchApi()->searchMovies($media_info['title']);
if (count($apires['results']) > 0) { if (count($apires['results']) > 0) {

View file

@ -115,58 +115,58 @@ class AmpacheTvdb
} }
// Get first match // Get first match
$release = $this->getReleaseByTitle($releases, $media_info['tvshow'], $media_info['year']); $release = $this->getReleaseByTitle($releases, $media_info['tvshow'], $media_info['year']);
$results['tvdb_tvshow_id'] = $release->id; $results['tvdb_tvshow_id'] = $release->id;
$results['tvshow_imdb_id'] = $release->imdbId ; $results['tvshow_imdb_id'] = $release->imdbId ;
$results['summary'] = substr($release->overview,0,255); //Summary column in db is only 256 characters. $results['summary'] = substr($release->overview,0,255); //Summary column in db is only 256 characters.
$results['tvshow'] = $release->name; $results['tvshow'] = $release->name;
if ($release->FirstAired) { if ($release->FirstAired) {
$results['tvshow_year'] = $release->firstAired->format('Y'); $results['tvshow_year'] = $release->firstAired->format('Y');
} }
if ($release->banner) { if ($release->banner) {
$results['tvshow_banner_art'] = $tvdburl . '/banners/' . $release->banner; $results['tvshow_banner_art'] = $tvdburl . '/banners/' . $release->banner;
} }
$baseSeries = $client->getSerie($results['tvdb_tvshow_id']); $baseSeries = $client->getSerie($results['tvdb_tvshow_id']);
if (count($baseSeries->genres) > 0) { if (count($baseSeries->genres) > 0) {
$results['genre'] = $baseSeries->genres; $results['genre'] = $baseSeries->genres;
} }
$banners = $client->getBanners($results['tvdb_tvshow_id']); $banners = $client->getBanners($results['tvdb_tvshow_id']);
foreach ($banners as $banner) { foreach ($banners as $banner) {
if ($banner->language == "en") { if ($banner->language == "en") {
if (!$results['tvshow_art']) { if (!$results['tvshow_art']) {
if ($banner->type == "poster") { if ($banner->type == "poster") {
$results['tvshow_art'] = $tvdburl . '/banners/' . $banner->path; $results['tvshow_art'] = $tvdburl . '/banners/' . $banner->path;
}
} }
}
if ($media_info['tvshow_season'] && !$results['tvshow_season_art']) { if ($media_info['tvshow_season'] && !$results['tvshow_season_art']) {
if ($banner->type == "season" && $banner->season == $media_info['tvshow_season']) { if ($banner->type == "season" && $banner->season == $media_info['tvshow_season']) {
$results['tvshow_season_art'] = $tvdburl . '/banners/' . $banner->path; $results['tvshow_season_art'] = $tvdburl . '/banners/' . $banner->path;
}
} }
} }
} }
}
if ($media_info['tvshow_season'] && $media_info['tvshow_episode']) { if ($media_info['tvshow_season'] && $media_info['tvshow_episode']) {
$release = $client->getEpisode($results['tvdb_tvshow_id'], $media_info['tvshow_season'], $media_info['tvshow_episode']); $release = $client->getEpisode($results['tvdb_tvshow_id'], $media_info['tvshow_season'], $media_info['tvshow_episode']);
if ($release->id) { if ($release->id) {
$results['tvdb_id'] = $release->id; $results['tvdb_id'] = $release->id;
$results['tvshow_season'] = $release->season; $results['tvshow_season'] = $release->season;
$results['tvshow_episode'] = $release->number; $results['tvshow_episode'] = $release->number;
$results['original_name'] = $release->name; $results['original_name'] = $release->name;
$results['imdb_id'] = $release->imdbId ; $results['imdb_id'] = $release->imdbId ;
if ($release->firstAired) { if ($release->firstAired) {
$results['release_date'] = $release->firstAired->getTimestamp(); $results['release_date'] = $release->firstAired->getTimestamp();
$results['year'] = $release->firstAired->format('Y'); $results['year'] = $release->firstAired->format('Y');
; ;
} }
$results['description'] = $release->overview; $results['description'] = $release->overview;
if ($release->thumbnail) { if ($release->thumbnail) {
$results['art'] = $tvdburl . '/banners/' . $release->thumbnail; $results['art'] = $tvdburl . '/banners/' . $release->thumbnail;
}
} }
} }
}
} }
} catch (Exception $e) { } catch (Exception $e) {
debug_event('tvdb', 'Error getting metadata: ' . $e->getMessage(), '1'); debug_event('tvdb', 'Error getting metadata: ' . $e->getMessage(), '1');
@ -184,8 +184,7 @@ class AmpacheTvdb
private function getReleaseByTitle($results, $title, $year) private function getReleaseByTitle($results, $title, $year)
{ {
$titles = array(); $titles = array();
foreach ($results as $index) foreach ($results as $index) {
{
$pos = strpos($index->name, $title); $pos = strpos($index->name, $title);
if ($pos !== false) { if ($pos !== false) {
$titles[] = $index; $titles[] = $index;
@ -193,8 +192,7 @@ class AmpacheTvdb
} }
if ((count($titles) > 1) && ($year != null)) { if ((count($titles) > 1) && ($year != null)) {
foreach ($titles as $index) foreach ($titles as $index) {
{
$y = $index->firstAired->format('Y'); $y = $index->firstAired->format('Y');
if ($year == $y) { if ($year == $y) {
return $index; return $index;
@ -203,6 +201,5 @@ class AmpacheTvdb
} }
return count($titles) > 0 ? $titles[0] : $results[0]; return count($titles) > 0 ? $titles[0] : $results[0];
} }
} // end AmpacheTvdb } // end AmpacheTvdb
?> ?>