mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-04 10:19:25 +02:00
Add art on Videos
Add videos support to Subsonic and UPnP APIs Update Tmdb module
This commit is contained in:
parent
3fc08b17d4
commit
d842ebbb00
246 changed files with 5530 additions and 2127 deletions
|
@ -380,24 +380,16 @@ notify = "true"
|
|||
; methods simply leave it out. DB should be left as the first
|
||||
; method unless you want it to overwrite what's already in the
|
||||
; database
|
||||
; POSSIBLE VALUES: db tags folder amazon lastfm musicbrainz google
|
||||
; POSSIBLE VALUES (builtins): db tags folder lastfm musicbrainz google
|
||||
; POSSIBLE VALUES (plugins): amazon
|
||||
; DEFAULT: db,tags,folder,musicbrainz,lastfm,google
|
||||
art_order = "db,tags,folder,musicbrainz,lastfm,google"
|
||||
|
||||
; Amazon Developer Key
|
||||
; These are needed in order to actually use the amazon album art
|
||||
; Your public key is your 'Access Key ID'
|
||||
; Your private key is your 'Secret Access Key'
|
||||
; DEFAULT: false
|
||||
;amazon_developer_public_key = ""
|
||||
;amazon_developer_private_key = ""
|
||||
;amazon_developer_associate_tag = ""
|
||||
|
||||
; Recommendations
|
||||
; Set this to true to enable display of similar artists or albums
|
||||
; while browsing. Requires Last.FM.
|
||||
; DEFAULT: false
|
||||
;show_similar = "false"
|
||||
show_similar = "true"
|
||||
|
||||
; Concerts
|
||||
; Set this to true to enable display of artist concerts
|
||||
|
@ -407,14 +399,14 @@ art_order = "db,tags,folder,musicbrainz,lastfm,google"
|
|||
|
||||
; Last.FM API Key
|
||||
; Set this to your Last.FM api key to actually use Last.FM for
|
||||
; recommendations.
|
||||
;lastfm_api_key = ""
|
||||
; recommendations and metadata.
|
||||
lastfm_api_key = "d5df942424c71b754e54ce1832505ae2"
|
||||
|
||||
; Wanted
|
||||
; Set this to true to enable display missing albums and the
|
||||
; possibility for users to mark it as wanted.
|
||||
; DEFAULT: false
|
||||
;wanted = "false"
|
||||
wanted = "true"
|
||||
|
||||
; Wanted types
|
||||
; Set the allowed types of wanted releases (album,compilation,single,ep,live,remix,promotion,official)
|
||||
|
@ -441,32 +433,6 @@ wanted_types = "album,official"
|
|||
; DEFAULT: determined automatically
|
||||
;websocket_address = "ws://localhost:8100"
|
||||
|
||||
; Amazon base urls
|
||||
; An array of Amazon sites to search.
|
||||
; NOTE: This will search each of these sites in turn so don't expect it
|
||||
; to be lightning fast!
|
||||
; It is strongly recommended that only one of these is selected at any
|
||||
; one time
|
||||
; POSSIBLE VALUES:
|
||||
; http://webservices.amazon.com
|
||||
; http://webservices.amazon.co.uk
|
||||
; http://webservices.amazon.de
|
||||
; http://webservices.amazon.co.jp
|
||||
; http://webservices.amazon.fr
|
||||
; http://webservices.amazon.ca
|
||||
; Default: http://webservices.amazon.com
|
||||
amazon_base_urls = "http://webservices.amazon.com"
|
||||
|
||||
; max_amazon_results_pages
|
||||
; The maximum number of results pages to pull from EACH amazon site
|
||||
; NOTE: The art search pages through the results returned by your search
|
||||
; up to this number of pages. As with the base_urls above, this is going
|
||||
; to take more time, the more pages you ask it to process.
|
||||
; Of course a good search will return only a few matches anyway.
|
||||
; It is strongly recommended that you do _not_ change this value
|
||||
; DEFAULT: 1 page (10 items)
|
||||
max_amazon_results_pages = 1
|
||||
|
||||
; Debug
|
||||
; If this is enabled Ampache will write debugging information to the log file
|
||||
; DEFAULT: false
|
||||
|
|
27
image.php
27
image.php
|
@ -74,6 +74,11 @@ switch ($_GET['thumb']) {
|
|||
$size['height'] = 32;
|
||||
$size['width'] = 32;
|
||||
break;
|
||||
case '6':
|
||||
/* Video browsing size */
|
||||
$size['height'] = 150;
|
||||
$size['width'] = 100;
|
||||
break;
|
||||
default:
|
||||
$size['height'] = '275';
|
||||
$size['width'] = '275';
|
||||
|
@ -103,10 +108,10 @@ if (isset($_GET['type'])) {
|
|||
}
|
||||
}
|
||||
if (!$typeManaged) {
|
||||
$media = new $type($_GET['id']);
|
||||
$filename = $media->name;
|
||||
$item = new $type($_GET['object_id']);
|
||||
$filename = $item->name ?: $item->title;
|
||||
|
||||
$art = new Art($media->id,$type);
|
||||
$art = new Art($item->id, $type);
|
||||
$art->get_db();
|
||||
$etag = $art->id;
|
||||
|
||||
|
@ -126,10 +131,20 @@ if (!$typeManaged) {
|
|||
}
|
||||
|
||||
if (!$art->raw_mime) {
|
||||
$defaultimg = AmpConfig::get('prefix') . AmpConfig::get('theme_path') . '/images/';
|
||||
switch ($type) {
|
||||
case 'video':
|
||||
case 'tvshow':
|
||||
case 'tvshow_season':
|
||||
$mime = 'image/png';
|
||||
$defaultimg .= "blankmovie.png";
|
||||
break;
|
||||
default:
|
||||
$mime = 'image/jpeg';
|
||||
$image = file_get_contents(AmpConfig::get('prefix') .
|
||||
AmpConfig::get('theme_path') .
|
||||
'/images/blankalbum.jpg');
|
||||
$defaultimg .= "blankalbum.jpg";
|
||||
break;
|
||||
}
|
||||
$image = file_get_contents($defaultimg);
|
||||
} else {
|
||||
if ($_GET['thumb']) {
|
||||
$thumb_data = $art->get_thumb($size);
|
||||
|
|
|
@ -135,6 +135,8 @@ class Art extends database_object
|
|||
case 'artist':
|
||||
case 'video':
|
||||
case 'user':
|
||||
case 'tvshow':
|
||||
case 'tvshow_season':
|
||||
return $type;
|
||||
default:
|
||||
return 'album';
|
||||
|
@ -246,6 +248,27 @@ class Art extends database_object
|
|||
|
||||
} // get_db
|
||||
|
||||
public static function has_db($object_id, $object_type)
|
||||
{
|
||||
$sql = "SELECT COUNT(`id`) AS `nb_img` FROM `image` WHERE `object_type` = ? AND `object_id` = ?";
|
||||
$db_results = Dba::read($sql, array($object_type, $object_id));
|
||||
$nb_img = 0;
|
||||
if ($results = Dba::fetch_assoc($db_results)) {
|
||||
$nb_img = $results['nb_img'];
|
||||
}
|
||||
|
||||
return ($nb_img > 0);
|
||||
}
|
||||
|
||||
public function insert_url($url)
|
||||
{
|
||||
debug_event('art', 'Insert art from url ' . $url, '5');
|
||||
$image = Art::get_from_source(array('url' => $url), $this->type);
|
||||
$rurl = pathinfo($url);
|
||||
$mime = "image/" . $rurl['extension'];
|
||||
$this->insert($image, $mime);
|
||||
}
|
||||
|
||||
/**
|
||||
* insert
|
||||
* This takes the string representation of an image and inserts it into
|
||||
|
@ -554,9 +577,9 @@ class Art extends database_object
|
|||
if (empty($extension)) {
|
||||
$extension = 'jpg';
|
||||
}
|
||||
$url = AmpConfig::get('web_path') . '/play/art/' . $sid . '/' . scrub_out($uid) . '/thumb.' . $extension;
|
||||
$url = AmpConfig::get('web_path') . '/play/art/' . $sid . '/' . scrub_out($type) . '/' . scrub_out($uid) . '/thumb.' . $extension;
|
||||
} else {
|
||||
$url = AmpConfig::get('web_path') . '/image.php?id=' . scrub_out($uid) . '&object_type=' . scrub_out($type) . '&auth=' . $sid;
|
||||
$url = AmpConfig::get('web_path') . '/image.php?object_id=' . scrub_out($uid) . '&object_type=' . scrub_out($type) . '&auth=' . $sid;
|
||||
if (!empty($extension)) {
|
||||
$name = 'art.' . $extension;
|
||||
$url .= '&name=' . $name;
|
||||
|
@ -592,15 +615,51 @@ class Art extends database_object
|
|||
// Define vars
|
||||
$results = array();
|
||||
|
||||
if (count($options) == 0) {
|
||||
switch ($this->type) {
|
||||
case 'album':
|
||||
$allowed_methods = array('db','lastfm','folder','amazon','google','musicbrainz','tags');
|
||||
$album = new Album($this->uid);
|
||||
$album->format();
|
||||
$options['artist'] = $album->f_artist;
|
||||
$options['album'] = $album->f_name;
|
||||
$options['keyword'] = $options['artist'] . ' ' . $options['album'];
|
||||
break;
|
||||
case 'artist':
|
||||
case 'video':
|
||||
default:
|
||||
$allowed_methods = array();
|
||||
$artist = new Artist($this->uid);
|
||||
$artist->format();
|
||||
$options['artist'] = $album->f_artist;
|
||||
$options['keyword'] = $options['artist'];
|
||||
break;
|
||||
case 'tvshow':
|
||||
$tvshow = new TVShow($this->uid);
|
||||
$tvshow->format();
|
||||
$options['tvshow'] = $tvshow->f_name;
|
||||
$options['keyword'] = $options['tvshow'];
|
||||
break;
|
||||
case 'tvshow_season':
|
||||
$season = new TVShow_Season($this->uid);
|
||||
$season->format();
|
||||
$options['tvshow'] = $season->f_tvshow;
|
||||
$options['tvshow_season'] = $season->f_name;
|
||||
$options['keyword'] = $options['tvshow'];
|
||||
break;
|
||||
case 'tvshow_episode':
|
||||
$video = new TVShow_Episode($this->uid);
|
||||
$video->format();
|
||||
$options['tvshow'] = $video->f_tvshow;
|
||||
$options['tvshow_season'] = $video->f_tvshow_season;
|
||||
$options['tvshow_episode'] = $video->episode_number;
|
||||
$options['keyword'] = $options['tvshow'] . " " . $video->f_title;
|
||||
break;
|
||||
case 'video':
|
||||
case 'clip':
|
||||
case 'movie':
|
||||
case 'personal_video':
|
||||
$video = new Video($this->uid);
|
||||
$video->format();
|
||||
$options['keyword'] = $video->f_title;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$config = AmpConfig::get('art_order');
|
||||
|
@ -617,25 +676,31 @@ class Art extends database_object
|
|||
|
||||
debug_event('Art','Searching using:' . json_encode($config), 3);
|
||||
|
||||
$plugin_names = Plugin::get_plugins('gather_arts');
|
||||
foreach ($config as $method) {
|
||||
|
||||
if (!in_array($method, $allowed_methods)) {
|
||||
debug_event('Art', "$method not in allowed_methods, skipping", 3);
|
||||
continue;
|
||||
}
|
||||
|
||||
$method_name = "gather_" . $method;
|
||||
|
||||
if (in_array($method_name, $methods)) {
|
||||
if (in_array($method, $plugin_names)) {
|
||||
$plugin = new Plugin($method);
|
||||
$installed_version = Plugin::get_plugin_version($plugin->_plugin->name);
|
||||
if ($installed_version) {
|
||||
if ($plugin->load($GLOBALS['user'])) {
|
||||
$data = $plugin->_plugin->gather_arts($this->type, $options, $limit);
|
||||
}
|
||||
}
|
||||
} else if (in_array($method_name, $methods)) {
|
||||
debug_event('Art', "Method used: $method_name", 3);
|
||||
// Some of these take options!
|
||||
switch ($method_name) {
|
||||
case 'gather_amazon':
|
||||
$data = $this->{$method_name}($limit, $options['keyword']);
|
||||
$data = $this->{$method_name}($limit, $options);
|
||||
break;
|
||||
case 'gather_lastfm':
|
||||
$data = $this->{$method_name}($limit, $options);
|
||||
break;
|
||||
case 'gather_google':
|
||||
$data = $this->{$method_name}($limit, $options);
|
||||
break;
|
||||
default:
|
||||
$data = $this->{$method_name}($limit);
|
||||
break;
|
||||
|
@ -647,10 +712,8 @@ class Art extends database_object
|
|||
if ($limit && count($results) >= $limit) {
|
||||
return array_slice($results, 0, $limit);
|
||||
}
|
||||
|
||||
} // if the method exists
|
||||
else {
|
||||
debug_event("Art", "$method_name not defined", 1);
|
||||
} else {
|
||||
debug_event("Art", $method_name . " not defined", 1);
|
||||
}
|
||||
|
||||
} // end foreach
|
||||
|
@ -682,19 +745,17 @@ class Art extends database_object
|
|||
* This function retrieves art based on MusicBrainz' Advanced
|
||||
* Relationships
|
||||
*/
|
||||
public function gather_musicbrainz($limit = 5)
|
||||
public function gather_musicbrainz($limit = 5, $data = array())
|
||||
{
|
||||
$images = array();
|
||||
$num_found = 0;
|
||||
|
||||
if ($this->type == 'album') {
|
||||
$album = new Album($this->uid);
|
||||
} else {
|
||||
if ($this->type != 'album') {
|
||||
return $images;
|
||||
}
|
||||
|
||||
if ($album->mbid) {
|
||||
debug_event('mbz-gatherart', "Album MBID: " . $album->mbid, '5');
|
||||
if ($data['mbid']) {
|
||||
debug_event('mbz-gatherart', "Album MBID: " . $data['mbid'], '5');
|
||||
} else {
|
||||
return $images;
|
||||
}
|
||||
|
@ -704,7 +765,7 @@ class Art extends database_object
|
|||
'url-rels'
|
||||
);
|
||||
try {
|
||||
$release = $mb->lookup('release', $album->mbid, $includes);
|
||||
$release = $mb->lookup('release', $data['mbid'], $includes);
|
||||
} catch (Exception $e) {
|
||||
return $images;
|
||||
}
|
||||
|
@ -836,142 +897,6 @@ class Art extends database_object
|
|||
|
||||
} // gather_musicbrainz
|
||||
|
||||
/**
|
||||
* gather_amazon
|
||||
* This takes keywords and performs a search of the Amazon website
|
||||
* for the art. It returns an array of found objects with mime/url keys
|
||||
*/
|
||||
public function gather_amazon($limit = 5, $keywords = '')
|
||||
{
|
||||
$images = array();
|
||||
$final_results = array();
|
||||
$possible_keys = array(
|
||||
'LargeImage',
|
||||
'MediumImage',
|
||||
'SmallImage'
|
||||
);
|
||||
|
||||
if ($this->type == 'album') {
|
||||
$album = new Album($this->uid);
|
||||
} else {
|
||||
return $images;
|
||||
}
|
||||
|
||||
// Prevent the script from timing out
|
||||
set_time_limit(0);
|
||||
|
||||
if (empty($keywords)) {
|
||||
$keywords = $album->full_name;
|
||||
/* If this isn't a various album combine with artist name */
|
||||
if ($album->artist_count == '1') { $keywords .= ' ' . $album->artist_name; }
|
||||
}
|
||||
|
||||
/* Attempt to retrieve the album art order */
|
||||
$amazon_base_urls = AmpConfig::get('amazon_base_urls');
|
||||
|
||||
/* If it's not set */
|
||||
if (!count($amazon_base_urls)) {
|
||||
$amazon_base_urls = array('http://webservices.amazon.com');
|
||||
}
|
||||
|
||||
/* Foreach through the base urls that we should check */
|
||||
foreach ($amazon_base_urls as $amazon_base) {
|
||||
|
||||
// Create the Search Object
|
||||
$amazon = new AmazonSearch(AmpConfig::get('amazon_developer_public_key'), AmpConfig::get('amazon_developer_private_key'), AmpConfig::get('amazon_developer_associate_tag'), $amazon_base);
|
||||
if (AmpConfig::get('proxy_host') AND AmpConfig::get('proxy_port')) {
|
||||
$proxyhost = AmpConfig::get('proxy_host');
|
||||
$proxyport = AmpConfig::get('proxy_port');
|
||||
$proxyuser = AmpConfig::get('proxy_user');
|
||||
$proxypass = AmpConfig::get('proxy_pass');
|
||||
debug_event('amazon', 'setProxy', 5);
|
||||
$amazon->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass);
|
||||
}
|
||||
|
||||
$search_results = array();
|
||||
|
||||
/* Set up the needed variables */
|
||||
$max_pages_to_search = max(AmpConfig::get('max_amazon_results_pages'),$amazon->_default_results_pages);
|
||||
// while we have pages to search
|
||||
do {
|
||||
$raw_results = $amazon->search(array('artist'=>'', 'album'=>'', 'keywords'=>$keywords));
|
||||
$total = count($raw_results) + count($search_results);
|
||||
|
||||
// If we've gotten more then we wanted
|
||||
if ($limit && $total > $limit) {
|
||||
$raw_results = array_slice($raw_results, 0, -($total - $limit), true);
|
||||
|
||||
debug_event('amazon-xml', "Found $total, limit $limit; reducing and breaking from loop", 5);
|
||||
// Merge the results and BREAK!
|
||||
$search_results = array_merge($search_results,$raw_results);
|
||||
break;
|
||||
} // if limit defined
|
||||
|
||||
$search_results = array_merge($search_results,$raw_results);
|
||||
$pages_to_search = min($max_pages_to_search, $amazon->_maxPage);
|
||||
debug_event('amazon-xml', "Searched results page " . ($amazon->_currentPage+1) . "/" . $pages_to_search,'5');
|
||||
$amazon->_currentPage++;
|
||||
|
||||
} while ($amazon->_currentPage < $pages_to_search);
|
||||
|
||||
|
||||
// Only do the second search if the first actually returns something
|
||||
if (count($search_results)) {
|
||||
$final_results = $amazon->lookup($search_results);
|
||||
}
|
||||
|
||||
/* Log this if we're doin debug */
|
||||
debug_event('amazon-xml',"Searched using $keywords with " . AmpConfig::get('amazon_developer_key') . " as key, results: " . count($final_results), 5);
|
||||
|
||||
// If we've hit our limit
|
||||
if (!empty($limit) && count($final_results) >= $limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
} // end foreach
|
||||
|
||||
/* Foreach through what we've found */
|
||||
foreach ($final_results as $result) {
|
||||
|
||||
$key = '';
|
||||
/* Recurse through the images found */
|
||||
foreach ($possible_keys as $k) {
|
||||
if (strlen($result[$k])) {
|
||||
$key = $k;
|
||||
break;
|
||||
}
|
||||
} // foreach
|
||||
|
||||
// Rudimentary image type detection, only JPG and GIF allowed.
|
||||
if (substr($result[$key], -4) == '.jpg') {
|
||||
$mime = "image/jpeg";
|
||||
} elseif (substr($result[$key], -4) == '.gif') {
|
||||
$mime = "image/gif";
|
||||
} elseif (substr($result[$key], -4) == '.png') {
|
||||
$mime = "image/png";
|
||||
} else {
|
||||
/* Just go to the next result */
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['url'] = $result[$key];
|
||||
$data['mime'] = $mime;
|
||||
|
||||
$images[] = $data;
|
||||
|
||||
if (!empty($limit)) {
|
||||
if (count($images) >= $limit) {
|
||||
return $images;
|
||||
}
|
||||
}
|
||||
|
||||
} // if we've got something
|
||||
|
||||
return $images;
|
||||
|
||||
} // gather_amazon
|
||||
|
||||
/**
|
||||
* gather_folder
|
||||
* This returns the art from the folder of the files
|
||||
|
@ -1142,23 +1067,16 @@ class Art extends database_object
|
|||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function gather_google($limit = 5)
|
||||
public function gather_google($limit = 5, $data = array())
|
||||
{
|
||||
$images = array();
|
||||
$media = new $this->type($this->uid);
|
||||
$media->format();
|
||||
|
||||
$search = $media->full_name;
|
||||
|
||||
if ($media->artist_count == '1')
|
||||
$search = $media->artist_name . ', ' . $search;
|
||||
|
||||
$search = rawurlencode($search);
|
||||
$search = rawurlencode($data['keyword']);
|
||||
|
||||
$size = '&imgsz=m'; // Medium
|
||||
//$size = '&imgsz=l'; // Large
|
||||
|
||||
$html = file_get_contents("http://images.google.com/images?source=hp&q=$search&oq=&um=1&ie=UTF-8&sa=N&tab=wi&start=0&tbo=1$size");
|
||||
$url = "http://images.google.com/images?source=hp&q=" . $search . "&oq=&um=1&ie=UTF-8&sa=N&tab=wi&start=0&tbo=1" . $size;
|
||||
$html = file_get_contents($url);
|
||||
|
||||
if(preg_match_all("|\ssrc\=\"(http.+?)\"|", $html, $matches, PREG_PATTERN_ORDER))
|
||||
foreach ($matches[1] as $match) {
|
||||
|
@ -1178,43 +1096,20 @@ class Art extends database_object
|
|||
* This returns the art from lastfm. It doesn't currently require an
|
||||
* account but may in the future.
|
||||
*/
|
||||
public function gather_lastfm($limit, $options = false)
|
||||
public function gather_lastfm($limit = 5, $data = array())
|
||||
{
|
||||
$data = array();
|
||||
// Create the parser object
|
||||
$lastfm = new LastFMSearch();
|
||||
$images = array();
|
||||
|
||||
switch ($this->type) {
|
||||
case 'album':
|
||||
if (is_array($options)) {
|
||||
$artist = $options['artist'];
|
||||
$album = $options['album_name'];
|
||||
} else {
|
||||
$media = new Album($this->uid);
|
||||
$media->format();
|
||||
$artist = $media->artist_name;
|
||||
$album = $media->full_name;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return $data;
|
||||
if ($this->type != 'album' || empty($data['artist']) || empty($data['album'])) {
|
||||
return $images;
|
||||
}
|
||||
|
||||
if (AmpConfig::get('proxy_host') AND AmpConfig::get('proxy_port')) {
|
||||
$proxyhost = AmpConfig::get('proxy_host');
|
||||
$proxyport = AmpConfig::get('proxy_port');
|
||||
$proxyuser = AmpConfig::get('proxy_user');
|
||||
$proxypass = AmpConfig::get('proxy_pass');
|
||||
debug_event('LastFM', 'proxy set', 5);
|
||||
$lastfm->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass);
|
||||
}
|
||||
$xmldata = Recommendation::album_search($data['artist'], $data['album']);
|
||||
|
||||
$raw_data = $lastfm->album_search($artist, $album);
|
||||
if (!count($xmldata)) { return array(); }
|
||||
|
||||
if (!count($raw_data)) { return array(); }
|
||||
|
||||
$coverart = $raw_data['coverart'];
|
||||
if (!is_array($coverart)) { return array(); }
|
||||
$coverart = (array) $xmldata->coverart;
|
||||
if (!$coverart) { return array(); }
|
||||
|
||||
ksort($coverart);
|
||||
foreach ($coverart as $url) {
|
||||
|
@ -1227,14 +1122,65 @@ class Art extends database_object
|
|||
// HACK: we shouldn't rely on the extension to determine file type
|
||||
$results = pathinfo($url);
|
||||
$mime = 'image/' . $results['extension'];
|
||||
$data[] = array('url' => $url, 'mime' => $mime);
|
||||
if ($limit && count($data) >= $limit) {
|
||||
return $data;
|
||||
$images[] = array('url' => $url, 'mime' => $mime);
|
||||
if ($limit && count($images) >= $limit) {
|
||||
return $images;
|
||||
}
|
||||
} // end foreach
|
||||
|
||||
return $data;
|
||||
return $images;
|
||||
|
||||
} // gather_lastfm
|
||||
|
||||
public static function gather_metadata_plugin($plugin, $type, $options)
|
||||
{
|
||||
$gtypes = array();
|
||||
switch ($type) {
|
||||
case 'tvshow':
|
||||
case 'tvshow_season':
|
||||
case 'tvshow_episode':
|
||||
$gtypes[] = 'tvshow';
|
||||
$media_info = array(
|
||||
'tvshow' => $options['tvshow'],
|
||||
'tvshow_season' => $options['tvshow_season'],
|
||||
'tvshow_episode' => $options['tvshow_episode'],
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$gtypes[] = 'movie';
|
||||
$media_info = array(
|
||||
'title' => $options['keyword'],
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$meta = $plugin->get_metadata($gtypes, $media_info);
|
||||
$images = array();
|
||||
switch ($type) {
|
||||
case 'tvshow':
|
||||
if ($meta['tvshow_art']) {
|
||||
$url = $meta['tvshow_art'];
|
||||
$ures = pathinfo($url);
|
||||
$images[] = array('url' => $url, 'mime' => 'image/' . $ures['extension']);
|
||||
}
|
||||
break;
|
||||
case 'tvshow_season':
|
||||
if ($meta['tvshow_season_art']) {
|
||||
$url = $meta['tvshow_season_art'];
|
||||
$ures = pathinfo($url);
|
||||
$images[] = array('url' => $url, 'mime' => 'image/' . $ures['extension']);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($meta['art']) {
|
||||
$url = $meta['art'];
|
||||
$ures = pathinfo($url);
|
||||
$images[] = array('url' => $url, 'mime' => 'image/' . $ures['extension']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
} // Art
|
||||
|
|
|
@ -466,24 +466,6 @@ abstract class Catalog extends database_object
|
|||
return $insert_id;
|
||||
}
|
||||
|
||||
public static function insert_video($gtypes, $results)
|
||||
{
|
||||
if (count($gtypes) > 0) {
|
||||
$gtype = $gtypes[0];
|
||||
switch ($gtype) {
|
||||
case 'tvshow':
|
||||
TVShow_Episode::insert($results);
|
||||
break;
|
||||
case 'movie':
|
||||
Movie::insert($results);
|
||||
break;
|
||||
default:
|
||||
// Do nothing, video entry already created and no additional data for now
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* count_tags
|
||||
*
|
||||
|
@ -605,9 +587,129 @@ abstract class Catalog extends database_object
|
|||
}
|
||||
|
||||
/**
|
||||
* get_artist
|
||||
* get_video_ids
|
||||
*
|
||||
* This returns an array of ids of artists that have songs in the catalogs parameter
|
||||
* This returns an array of ids of videos in this catalog
|
||||
*/
|
||||
public function get_video_ids($type = '')
|
||||
{
|
||||
$results = array();
|
||||
|
||||
$sql = 'SELECT DISTINCT(`video`.`id`) FROM `video` ';
|
||||
if (!empty($type)) {
|
||||
$sql .= 'JOIN `' . $type . '` ON `' . $type . '`.`id` = `video`.`id`';
|
||||
}
|
||||
$sql .= 'WHERE `video`.`catalog` = ?';
|
||||
$db_results = Dba::read($sql, array($this->id));
|
||||
|
||||
while ($r = Dba::fetch_assoc($db_results)) {
|
||||
$results[] = $r['id'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function get_videos($catalogs = null, $type = '')
|
||||
{
|
||||
if (!$catalogs) {
|
||||
$catalogs = self::get_catalogs();
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ($catalogs as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$video_ids = $catalog->get_video_ids($type);
|
||||
foreach ($video_ids as $video_id) {
|
||||
$results[] = Video::create_from_id($video_id);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function get_videos_count($catalog_id = null, $type = '')
|
||||
{
|
||||
$sql = "SELECT COUNT(`video`.`id`) AS `video_cnt` FROM `video` ";
|
||||
if (!empty($type)) {
|
||||
$sql .= "JOIN `" . $type . "` ON `" . $type . "`.`id` = `video`.`id` ";
|
||||
}
|
||||
if ($catalogs) {
|
||||
$sql .= "WHERE `video`.`catalog` = `" . intval($catalog_id) . "`";
|
||||
}
|
||||
$db_results = Dba::read($sql);
|
||||
$video_cnt = 0;
|
||||
if ($row = Dba::fetch_row($db_results)) {
|
||||
$video_cnt = $row[0];
|
||||
}
|
||||
|
||||
return $video_cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_tvshow_ids
|
||||
*
|
||||
* This returns an array of ids of tvshows in this catalog
|
||||
*/
|
||||
public function get_tvshow_ids()
|
||||
{
|
||||
$results = array();
|
||||
|
||||
$sql = 'SELECT DISTINCT(`tvshow`.`id`) FROM `tvshow` ';
|
||||
$sql .= 'JOIN `tvshow_season` ON `tvshow_season`.`tvshow` = `tvshow`.`id` ';
|
||||
$sql .= 'JOIN `tvshow_episode` ON `tvshow_episode`.`season` = `tvshow_season`.`id` ';
|
||||
$sql .= 'JOIN `video` ON `video`.`id` = `tvshow_episode`.`id` ';
|
||||
$sql .= 'WHERE `video`.`catalog` = ?';
|
||||
|
||||
$db_results = Dba::read($sql, array($this->id));
|
||||
while ($r = Dba::fetch_assoc($db_results)) {
|
||||
$results[] = $r['id'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function get_tvshows($catalogs = null)
|
||||
{
|
||||
if (!$catalogs) {
|
||||
$catalogs = self::get_catalogs();
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ($catalogs as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$tvshow_ids = $catalog->get_tvshow_ids($type);
|
||||
foreach ($tvshow_ids as $tvshow_id) {
|
||||
$results[] = new TVShow($tvshow_id);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_artist_ids
|
||||
*
|
||||
* This returns an array of ids of artist that have songs in this
|
||||
* catalog
|
||||
*/
|
||||
public function get_artist_ids()
|
||||
{
|
||||
$results = array();
|
||||
|
||||
$sql = 'SELECT DISTINCT(`song`.`artist`) FROM `song` WHERE `song`.`catalog` = ?';
|
||||
$db_results = Dba::read($sql, array($this->id));
|
||||
|
||||
while ($r = Dba::fetch_assoc($db_results)) {
|
||||
$results[] = $r['artist'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_artists
|
||||
*
|
||||
* This returns an array of artists that have songs in the catalogs parameter
|
||||
*/
|
||||
public static function get_artists($catalogs = null)
|
||||
{
|
||||
|
@ -707,7 +809,7 @@ abstract class Catalog extends database_object
|
|||
* This runs through all of the needs art albums and trys
|
||||
* to find the art for them from the mp3s
|
||||
*/
|
||||
public function gather_art()
|
||||
public function gather_art($songs = null, $videos = null)
|
||||
{
|
||||
// Make sure they've actually got methods
|
||||
$art_order = AmpConfig::get('art_order');
|
||||
|
@ -720,28 +822,40 @@ abstract class Catalog extends database_object
|
|||
set_time_limit(0);
|
||||
|
||||
$search_count = 0;
|
||||
$albums = $this->get_album_ids();
|
||||
$searches = array();
|
||||
if ($songs == null) {
|
||||
$searches['album'] = $this->get_album_ids();
|
||||
$searches['artist'] = $this->get_artist_ids();
|
||||
} else {
|
||||
$searches['album'] = array();
|
||||
$searches['artist'] = array();
|
||||
foreach ($songs as $song_id) {
|
||||
$song = new Song($song_id);
|
||||
if (!in_array($song->album, $albums)) {
|
||||
$searches['album'][] = $song->album;
|
||||
}
|
||||
if (!in_array($song->artist, $albums)) {
|
||||
$searches['artist'][] = $song->artist;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($videos == null) {
|
||||
$searches['video'] = $this->get_video_ids();
|
||||
} else {
|
||||
$searches['video'] = $videos;
|
||||
}
|
||||
|
||||
// Run through them and get the art!
|
||||
foreach ($albums as $album_id) {
|
||||
$art = new Art($album_id, 'album');
|
||||
$album = new Album($album_id);
|
||||
// We're going to need the name here
|
||||
$album->format();
|
||||
// Run through items and get the art!
|
||||
foreach ($searches as $key => $values) {
|
||||
foreach ($values as $id) {
|
||||
$art = new Art($id, $key);
|
||||
|
||||
debug_event('gather_art', 'Gathering art for ' . $album->name, 5);
|
||||
|
||||
$options = array(
|
||||
'album_name' => $album->full_name,
|
||||
'artist' => $album->artist_name,
|
||||
'keyword' => $album->artist_name . ' ' . $album->full_name
|
||||
);
|
||||
|
||||
$results = $art->gather($options, 1);
|
||||
debug_event('gather_art', 'Gathering art for ' . $key . '/' . $id . '...', 5);
|
||||
$results = $art->gather(array(), 1);
|
||||
|
||||
if (count($results)) {
|
||||
// Pull the string representation from the source
|
||||
$image = Art::get_from_source($results[0], 'album');
|
||||
$image = Art::get_from_source($results[0], $key);
|
||||
if (strlen($image) > '5') {
|
||||
$art->insert($image, $results[0]['mime']);
|
||||
// If they've enabled resizing of images generate a thumbnail
|
||||
|
@ -768,7 +882,8 @@ abstract class Catalog extends database_object
|
|||
}
|
||||
|
||||
unset($found);
|
||||
} // foreach albums
|
||||
}
|
||||
}
|
||||
|
||||
// One last time for good measure
|
||||
UI::update_text('count_art_' . $this->id, $search_count);
|
||||
|
|
|
@ -63,7 +63,7 @@ class Clip extends Video
|
|||
* create
|
||||
* This takes a key'd array of data as input and inserts a new clip entry, it returns the record id
|
||||
*/
|
||||
public static function insert($data)
|
||||
public static function insert($data, $options = array())
|
||||
{
|
||||
$sql = "INSERT INTO `clip` (`id`,`artist`,`song`) " .
|
||||
"VALUES (?, ?, ?)";
|
||||
|
|
|
@ -61,7 +61,7 @@ class Movie extends Video
|
|||
* create
|
||||
* This takes a key'd array of data as input and inserts a new movie entry, it returns the record id
|
||||
*/
|
||||
public static function insert($data)
|
||||
public static function insert($data, $options = array())
|
||||
{
|
||||
$sql = "INSERT INTO `movie` (`id`,`original_name`,`description`, `year`) " .
|
||||
"VALUES (?, ?, ?, ?)";
|
||||
|
@ -93,7 +93,9 @@ class Movie extends Video
|
|||
{
|
||||
parent::format();
|
||||
|
||||
$this->f_link = '<a href="' . $this->link . '">' . ($this->original_name ?: $this->f_title) . '</a>';
|
||||
$this->f_title = ($this->original_name ?: $this->f_title);
|
||||
$this->f_full_title = $this->f_title;
|
||||
$this->f_link = '<a href="' . $this->link . '">' . $this->f_title . '</a>';
|
||||
|
||||
return true;
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class Personal_Video extends Video
|
|||
* create
|
||||
* This takes a key'd array of data as input and inserts a new personal video entry, it returns the record id
|
||||
*/
|
||||
public static function insert($data)
|
||||
public static function insert($data, $options = array())
|
||||
{
|
||||
$sql = "INSERT INTO `personal_video` (`id`,`location`,`description`) " .
|
||||
"VALUES (?, ?, ?)";
|
||||
|
|
|
@ -363,7 +363,7 @@ class Preference extends database_object
|
|||
public static function fix_preferences($results)
|
||||
{
|
||||
$arrays = array('auth_methods', 'getid3_tag_order',
|
||||
'metadata_order', 'metadata_order_video', 'art_order', 'amazon_base_urls');
|
||||
'metadata_order', 'metadata_order_video', 'art_order');
|
||||
|
||||
foreach ($arrays as $item) {
|
||||
$results[$item] = trim($results[$item])
|
||||
|
|
|
@ -40,6 +40,12 @@ class Recommendation
|
|||
$api_key = AmpConfig::get('lastfm_api_key');
|
||||
$api_base = "http://ws.audioscrobbler.com/2.0/?method=";
|
||||
$url = $api_base . $method . '&api_key=' . $api_key . '&' . $query;
|
||||
|
||||
return self::query_lastfm($url);
|
||||
}
|
||||
|
||||
public static function query_lastfm($url)
|
||||
{
|
||||
debug_event('Recommendation', 'search url : ' . $url, 5);
|
||||
|
||||
$options = array();
|
||||
|
@ -56,7 +62,14 @@ class Recommendation
|
|||
$content = $request->body;
|
||||
|
||||
return simplexml_load_string($content);
|
||||
} // get_lastfm_results
|
||||
}
|
||||
|
||||
public static function album_search($artist, $album)
|
||||
{
|
||||
$url = 'http://ws.audioscrobbler.com/1.0/album/' . urlencode($artist) . '/' . urlencode($album) . '/info.xml';
|
||||
|
||||
return self::query_lastfm($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* gc
|
||||
|
|
|
@ -166,11 +166,11 @@ class Shoutbox
|
|||
{
|
||||
switch ($this->object_type) {
|
||||
case 'album':
|
||||
$image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . AmpConfig::get('web_path') . "/image.php?id=" . $this->object_id . "&thumb=1\" />";
|
||||
$image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . AmpConfig::get('web_path') . "/image.php?object_id=" . $this->object_id . "&object_type=" . $this->object_type . "&thumb=1\" />";
|
||||
break;
|
||||
case 'song':
|
||||
$song = new Song($this->object_id);
|
||||
$image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . AmpConfig::get('web_path') . "/image.php?id=" . $song->album . "&thumb=1\" />";
|
||||
$image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . AmpConfig::get('web_path') . "/image.php?object_id=" . $song->album . "&object_type=album&thumb=1\" />";
|
||||
break;
|
||||
case 'artist':
|
||||
default:
|
||||
|
|
|
@ -375,10 +375,11 @@ class Song extends database_object implements media
|
|||
return 'audio/aacp';
|
||||
case 'mpc':
|
||||
return 'audio/x-musepack';
|
||||
case 'mkv':
|
||||
return 'audio/x-matroska';
|
||||
default:
|
||||
return 'audio/mpeg';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,11 +85,19 @@ class Subsonic_Api
|
|||
public static function follow_stream($url)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ob_end_clean();
|
||||
|
||||
if (function_exists('curl_version')) {
|
||||
$headers = apache_request_headers();
|
||||
$reqheaders = array();
|
||||
$reqheaders[] = "User-Agent: " . $headers['User-Agent'];
|
||||
if (isset($headers['Range'])) {
|
||||
$reqheaders[] = "Range: " . $headers['Range'];
|
||||
}
|
||||
// Curl support, we stream transparently to avoid redirect. Redirect can fail on few clients
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_HTTPHEADER => $reqheaders,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_RETURNTRANSFER => false,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
|
@ -423,14 +431,14 @@ class Subsonic_Api
|
|||
* getVideos
|
||||
* Get all videos.
|
||||
* Takes no parameter.
|
||||
* Not supported yet.
|
||||
*/
|
||||
public static function getvideos($input)
|
||||
{
|
||||
self::check_version($input, "1.7.0");
|
||||
|
||||
$r = Subsonic_XML_Data::createSuccessResponse();
|
||||
Subsonic_XML_Data::addVideos($r);
|
||||
$videos = Catalog::get_videos();
|
||||
Subsonic_XML_Data::addVideos($r, $videos);
|
||||
self::apiOutput($input, $r);
|
||||
}
|
||||
|
||||
|
@ -844,9 +852,18 @@ class Subsonic_Api
|
|||
if ($estimateContentLength == 'true') {
|
||||
$params .= '&content_length=required';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
if (Subsonic_XML_Data::isVideo($fileid)) {
|
||||
$url = Video::play_url(Subsonic_XML_Data::getAmpacheId($fileid), $params);
|
||||
} else if (Subsonic_XML_Data::isSong($fileid)) {
|
||||
$url = Song::play_url(Subsonic_XML_Data::getAmpacheId($fileid), $params);
|
||||
}
|
||||
|
||||
if (!empty($url)) {
|
||||
self::follow_stream($url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* download
|
||||
|
|
|
@ -46,6 +46,7 @@ class Subsonic_XML_Data
|
|||
const AMPACHEID_ALBUM = 200000000;
|
||||
const AMPACHEID_SONG = 300000000;
|
||||
const AMPACHEID_SMARTPL = 400000000;
|
||||
const AMPACHEID_VIDEO = 500000000;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
|
@ -76,6 +77,11 @@ class Subsonic_XML_Data
|
|||
return $id + Subsonic_XML_Data::AMPACHEID_SMARTPL;
|
||||
}
|
||||
|
||||
public static function getVideoId($id)
|
||||
{
|
||||
return $id + Subsonic_XML_Data::AMPACHEID_VIDEO;
|
||||
}
|
||||
|
||||
public static function getAmpacheId($id)
|
||||
{
|
||||
return ($id % Subsonic_XML_Data::AMPACHEID_ARTIST);
|
||||
|
@ -110,6 +116,11 @@ class Subsonic_XML_Data
|
|||
return ($id >= Subsonic_XML_Data::AMPACHEID_SMARTPL);
|
||||
}
|
||||
|
||||
public static function isVideo($id)
|
||||
{
|
||||
return ($id >= Subsonic_XML_Data::AMPACHEID_VIDEO);
|
||||
}
|
||||
|
||||
public static function createFailedResponse($version = "")
|
||||
{
|
||||
$response = self::createResponse($version);
|
||||
|
@ -404,10 +415,48 @@ class Subsonic_XML_Data
|
|||
}
|
||||
}
|
||||
|
||||
public static function addVideos($xml)
|
||||
public static function addVideos($xml, $videos)
|
||||
{
|
||||
// Not supported yet
|
||||
$xml->addChild('videos');
|
||||
$xvideos = $xml->addChild('videos');
|
||||
foreach ($videos as $video) {
|
||||
$video->format();
|
||||
self::addVideo($xvideos, $video);
|
||||
}
|
||||
}
|
||||
|
||||
public static function addVideo($xml, $video)
|
||||
{
|
||||
$xvideo = $xml->addChild('video');
|
||||
$xvideo->addAttribute('id', self::getVideoId($video->id));
|
||||
$xvideo->addAttribute('title', $video->f_full_title);
|
||||
$xvideo->addAttribute('isDir', 'false');
|
||||
$xvideo->addAttribute('coverArt', self::getVideoId($video->id));
|
||||
$xvideo->addAttribute('isVideo', 'true');
|
||||
$xvideo->addAttribute('type', 'video');
|
||||
$xvideo->addAttribute('duration', $video->time);
|
||||
if ($video->year > 0) {
|
||||
$xvideo->addAttribute('year', $video->year);
|
||||
}
|
||||
$tags = Tag::get_object_tags('video', $video->id);
|
||||
if (count($tags) > 0) $xvideo->addAttribute('genre', $tags[0]['name']);
|
||||
$xvideo->addAttribute('size', $video->size);
|
||||
$xvideo->addAttribute('suffix', $video->type);
|
||||
$xvideo->addAttribute('contentType', $video->mime);
|
||||
// Create a clean fake path instead of song real file path to have better offline mode storage on Subsonic clients
|
||||
$path = basename($video->file);
|
||||
$xvideo->addAttribute('path', $path);
|
||||
|
||||
// Set transcoding information if required
|
||||
$transcode_cfg = AmpConfig::get('transcode');
|
||||
$transcode_mode = AmpConfig::get('transcode_' . $video->type);
|
||||
if ($transcode_cfg == 'always' || ($transcode_cfg != 'never' && $transcode_mode == 'required')) {
|
||||
$transcode_settings = $video->get_transcode_settings(null);
|
||||
if ($transcode_settings) {
|
||||
$transcode_type = $transcode_settings['format'];
|
||||
$xvideo->addAttribute('transcodedSuffix', $transcode_type);
|
||||
$xvideo->addAttribute('transcodedContentType', Video::type_to_mime($transcode_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function addPlaylists($xml, $playlists, $smartplaylists = array())
|
||||
|
|
|
@ -288,6 +288,14 @@ class Tag extends database_object
|
|||
"WHERE `tag_map`.`object_type`='video' AND `video`.`id` IS NULL";
|
||||
Dba::write($sql);
|
||||
|
||||
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `tvshow` ON `tvshow`.`id`=`tag_map`.`object_id` " .
|
||||
"WHERE `tag_map`.`object_type`='tvshow' AND `tvshow`.`id` IS NULL";
|
||||
Dba::write($sql);
|
||||
|
||||
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `tvshow_season` ON `tvshow_season`.`id`=`tag_map`.`object_id` " .
|
||||
"WHERE `tag_map`.`object_type`='tvshow_season' AND `tvshow_season`.`id` IS NULL";
|
||||
Dba::write($sql);
|
||||
|
||||
// Now nuke the tags themselves
|
||||
$sql = "DELETE FROM `tag` USING `tag` LEFT JOIN `tag_map` ON `tag`.`id`=`tag_map`.`tag_id` " .
|
||||
"WHERE `tag_map`.`id` IS NULL";
|
||||
|
@ -599,7 +607,7 @@ class Tag extends database_object
|
|||
*/
|
||||
public static function validate_type($type)
|
||||
{
|
||||
$valid_array = array('song','artist','album','video','playlist','live_stream','channel','broadcast');
|
||||
$valid_array = array('song','artist','album','video','tvshow','tvshow_season','playlist','live_stream','channel','broadcast');
|
||||
|
||||
if (in_array($type,$valid_array)) { return $type; }
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ class TVShow_Episode extends Video
|
|||
public $description;
|
||||
|
||||
public $f_link;
|
||||
public $f_season;
|
||||
public $f_season_link;
|
||||
public $f_tvshow;
|
||||
public $f_tvshow_link;
|
||||
|
@ -65,14 +66,33 @@ class TVShow_Episode extends Video
|
|||
* insert
|
||||
* Insert a new tv show episode and related entities.
|
||||
*/
|
||||
public static function insert($data)
|
||||
public static function insert($data, $options = array())
|
||||
{
|
||||
if (empty($data['tvshow'])) {
|
||||
$data['tvshow'] = T_('Unknown');
|
||||
}
|
||||
$tags = $data['genre'];
|
||||
|
||||
$tvshow = TVShow::check($data['tvshow'], $data['tvshow_year']);
|
||||
if ($options['gather_art'] && $tvshow && $data['tvshow_art'] && !Art::has_db($tvshow, 'tvshow')) {
|
||||
$art = new Art($tvshow, 'tvshow');
|
||||
$art->insert_url($data['tvshow_art']);
|
||||
}
|
||||
$tvshow_season = TVShow_Season::check($tvshow, $data['tvshow_season']);
|
||||
if ($options['gather_art'] && $tvshow_season && $data['tvshow_season_art'] && !Art::has_db($tvshow_season, 'tvshow_season')) {
|
||||
$art = new Art($tvshow_season, 'tvshow_season');
|
||||
$art->insert_url($data['tvshow_season_art']);
|
||||
}
|
||||
|
||||
if (is_array($tags)) {
|
||||
foreach ($tags as $tag) {
|
||||
$tag = trim($tag);
|
||||
if (!empty($tag)) {
|
||||
Tag::add('tvshow_season', $tvshow_season, $tag, false);
|
||||
Tag::add('tvshow', $tvshow, $tag, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sdata = $data;
|
||||
// Replace relation name with db ids
|
||||
|
@ -121,8 +141,9 @@ class TVShow_Episode extends Video
|
|||
|
||||
$this->f_title = ($this->original_name ?: $this->f_title);
|
||||
$this->f_link = '<a href="' . $this->link . '">' . $this->f_title . '</a>';
|
||||
$this->f_season = $season->f_name;
|
||||
$this->f_season_link = $season->f_link;
|
||||
$this->f_tvshow = $tvshow->f_tvshow;
|
||||
$this->f_tvshow = $season->f_tvshow;
|
||||
$this->f_tvshow_link = $season->f_tvshow_link;
|
||||
|
||||
$this->f_file = $this->f_tvshow;
|
||||
|
@ -130,6 +151,7 @@ class TVShow_Episode extends Video
|
|||
$this->f_file .= ' - S'. sprintf('%02d', $season->season_number) . 'E'. sprintf('%02d', $this->episode_number);
|
||||
}
|
||||
$this->f_file .= ' - ' . $this->f_title;
|
||||
$this->f_full_title = $this->f_file;
|
||||
|
||||
return true;
|
||||
|
||||
|
|
|
@ -2715,19 +2715,6 @@ class Update
|
|||
$sql = "ALTER TABLE `video` ADD `release_date` int(11) unsigned NULL AFTER `enabled`";
|
||||
Dba::write($sql);
|
||||
|
||||
$sql = "CREATE TABLE `people` (" .
|
||||
"`id` int(11) unsigned NOT NULL AUTO_INCREMENT," .
|
||||
"`name` varchar(256) NOT NULL," .
|
||||
"PRIMARY KEY (`id`)) ENGINE = MYISAM";
|
||||
|
||||
$sql = "CREATE TABLE `people_rel` (" .
|
||||
"`id` int(11) unsigned NOT NULL AUTO_INCREMENT," .
|
||||
"`object_id` int(11) unsigned NOT NULL," .
|
||||
"`object_type` varchar(32) NOT NULL," .
|
||||
"`people_id` int(11) unsigned NOT NULL," .
|
||||
"`rel_type` varchar(32) NOT NULL," .
|
||||
"PRIMARY KEY (`id`)) ENGINE = MYISAM";
|
||||
|
||||
$sql = "CREATE TABLE `tvshow` (" .
|
||||
"`id` int(11) unsigned NOT NULL AUTO_INCREMENT," .
|
||||
"`name` varchar(80) NOT NULL," .
|
||||
|
|
|
@ -572,6 +572,237 @@ class Upnp_Api
|
|||
return $mediaItems;
|
||||
}
|
||||
|
||||
public static function _videoMetadata($prmPath, $prmQuery = '')
|
||||
{
|
||||
$root = 'amp://video';
|
||||
$pathreq = explode('/', $prmPath);
|
||||
if ($pathreq[0] == '' && count($pathreq) > 0) {
|
||||
array_shift($pathreq);
|
||||
}
|
||||
|
||||
$meta = null;
|
||||
switch ($pathreq[0]) {
|
||||
case 'tvshows':
|
||||
switch (count($pathreq)) {
|
||||
case 1:
|
||||
$counts = count(Catalog::get_tvshows());
|
||||
$meta = array(
|
||||
'id' => $root . '/tvshows',
|
||||
'parentID' => $root,
|
||||
'restricted' => '1',
|
||||
'childCount' => $counts,
|
||||
'dc:title' => T_('TV Shows'),
|
||||
'upnp:class' => 'object.container',
|
||||
);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$tvshow = new TVShow($pathreq[1]);
|
||||
if ($tvshow->id) {
|
||||
$tvshow->format();
|
||||
$meta = self::_itemTVShow($tvshow, $root . '/tvshows');
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$season = new TVShow_Season($pathreq[2]);
|
||||
if ($season->id) {
|
||||
$season->format();
|
||||
$meta = self::_itemTVShowSeason($season, $root . '/tvshows/' . $pathreq[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$video = new TVShow_Episode($pathreq[3]);
|
||||
if ($video->id) {
|
||||
$video->format();
|
||||
$meta = self::_itemVideo($video, $root . '/tvshows/' . $pathreq[1] . '/' . $pathreq[2] );
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'clips':
|
||||
switch (count($pathreq)) {
|
||||
case 1:
|
||||
$counts = Catalog::get_videos_count(null, 'clip');
|
||||
$meta = array(
|
||||
'id' => $root . '/clips',
|
||||
'parentID' => $root,
|
||||
'restricted' => '1',
|
||||
'childCount' => $counts,
|
||||
'dc:title' => T_('Clips'),
|
||||
'upnp:class' => 'object.container',
|
||||
);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$video = new Clip($pathreq[1]);
|
||||
if ($video->id) {
|
||||
$video->format();
|
||||
$meta = self::_itemVideo($video, $root . '/clips');
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'movies':
|
||||
switch (count($pathreq)) {
|
||||
case 1:
|
||||
$counts = Catalog::get_videos_count(null, 'movie');
|
||||
$meta = array(
|
||||
'id' => $root . '/movies',
|
||||
'parentID' => $root,
|
||||
'restricted' => '1',
|
||||
'childCount' => $counts,
|
||||
'dc:title' => T_('Movies'),
|
||||
'upnp:class' => 'object.container',
|
||||
);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$video = new Movie($pathreq[1]);
|
||||
if ($video->id) {
|
||||
$video->format();
|
||||
$meta = self::_itemVideo($video, $root . '/movies');
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'personal_videos':
|
||||
switch (count($pathreq)) {
|
||||
case 1:
|
||||
$counts = Catalog::get_videos_count(null, 'personal_video');
|
||||
$meta = array(
|
||||
'id' => $root . '/personal_videos',
|
||||
'parentID' => $root,
|
||||
'restricted' => '1',
|
||||
'childCount' => $counts,
|
||||
'dc:title' => T_('Personal Videos'),
|
||||
'upnp:class' => 'object.container',
|
||||
);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$video = new Personal_Video($pathreq[1]);
|
||||
if ($video->id) {
|
||||
$video->format();
|
||||
$meta = self::_itemVideo($video, $root . '/personal_videos');
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$meta = array(
|
||||
'id' => $root,
|
||||
'parentID' => '0',
|
||||
'restricted' => '1',
|
||||
'childCount' => '4',
|
||||
'dc:title' => T_('Video'),
|
||||
'upnp:class' => 'object.container',
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
public static function _videoChilds($prmPath, $prmQuery)
|
||||
{
|
||||
$mediaItems = array();
|
||||
$queryData = array();
|
||||
parse_str($prmQuery, $queryData);
|
||||
|
||||
$parent = 'amp://video' . $prmPath;
|
||||
$pathreq = explode('/', $prmPath);
|
||||
if ($pathreq[0] == '' && count($pathreq) > 0) {
|
||||
array_shift($pathreq);
|
||||
}
|
||||
|
||||
switch ($pathreq[0]) {
|
||||
case 'tvshows':
|
||||
switch (count($pathreq)) {
|
||||
case 1: // Get tvshow list
|
||||
$tvshows = Catalog::get_tvshows();
|
||||
foreach ($tvshows as $tvshow) {
|
||||
$tvshow->format();
|
||||
$mediaItems[] = self::_itemTVShow($tvshow, $parent);
|
||||
}
|
||||
break;
|
||||
case 2: // Get season list
|
||||
$tvshow = new TVShow($pathreq[1]);
|
||||
if ($tvshow->id) {
|
||||
$season_ids = $tvshow->get_seasons();
|
||||
foreach ($season_ids as $season_id) {
|
||||
$season = new TVShow_Season($season_id);
|
||||
$season->format();
|
||||
$mediaItems[] = self::_itemTVShowSeason($season, $parent);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3: // Get episode list
|
||||
$season = new TVShow_Season($pathreq[2]);
|
||||
if ($season->id) {
|
||||
$episode_ids = $season->get_episodes();
|
||||
foreach ($episode_ids as $episode_id) {
|
||||
$video = new Video($episode_id);
|
||||
$video->format();
|
||||
$mediaItems[] = self::_itemVideo($video, $parent);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'clips':
|
||||
switch (count($pathreq)) {
|
||||
case 1: // Get clips list
|
||||
$videos = Catalog::get_videos(null, 'clip');
|
||||
foreach ($videos as $video) {
|
||||
$video->format();
|
||||
$mediaItems[] = self::_itemVideo($video, $parent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'movies':
|
||||
switch (count($pathreq)) {
|
||||
case 1: // Get clips list
|
||||
$videos = Catalog::get_videos(null, 'movie');
|
||||
foreach ($videos as $video) {
|
||||
$video->format();
|
||||
$mediaItems[] = self::_itemVideo($video, $parent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'personal_videos':
|
||||
switch (count($pathreq)) {
|
||||
case 1: // Get clips list
|
||||
$videos = Catalog::get_videos(null, 'personal_video');
|
||||
foreach ($videos as $video) {
|
||||
$video->format();
|
||||
$mediaItems[] = self::_itemVideo($video, $parent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$mediaItems[] = self::_videoMetadata('clips');
|
||||
$mediaItems[] = self::_videoMetadata('tvshows');
|
||||
$mediaItems[] = self::_videoMetadata('movies');
|
||||
$mediaItems[] = self::_videoMetadata('personal_videos');
|
||||
break;
|
||||
}
|
||||
|
||||
return $mediaItems;
|
||||
}
|
||||
|
||||
public static function _callSearch($criteria)
|
||||
{
|
||||
// Not supported yet
|
||||
|
@ -662,6 +893,54 @@ class Upnp_Api
|
|||
);
|
||||
}
|
||||
|
||||
private static function _itemTVShow($tvshow, $parent)
|
||||
{
|
||||
return array(
|
||||
'id' => 'amp://video/tvshows/' . $tvshow->id,
|
||||
'parentID' => $parent,
|
||||
'restricted' => '1',
|
||||
'childCount' => count($tvshow->get_seasons()),
|
||||
'dc:title' => $tvshow->f_name,
|
||||
'upnp:class' => 'object.container',
|
||||
);
|
||||
}
|
||||
|
||||
private static function _itemTVShowSeason($season, $parent)
|
||||
{
|
||||
return array(
|
||||
'id' => 'amp://video/tvshows/' . $season->tvshow . '/' . $season->id,
|
||||
'parentID' => $parent,
|
||||
'restricted' => '1',
|
||||
'childCount' => count($season->get_episodes()),
|
||||
'dc:title' => $season->f_name,
|
||||
'upnp:class' => 'object.container',
|
||||
);
|
||||
}
|
||||
|
||||
private static function _itemVideo($video, $parent)
|
||||
{
|
||||
$api_session = (AmpConfig::get('require_session')) ? Stream::$session : false;
|
||||
$art_url = Art::url($video->id, 'video', $api_session);
|
||||
|
||||
$fileTypesByExt = self::_getFileTypes();
|
||||
$arrFileType = $fileTypesByExt[$video->type];
|
||||
|
||||
return array(
|
||||
'id' => $parent . '/' . $video->id,
|
||||
'parentID' => $parent,
|
||||
'restricted' => '1',
|
||||
'dc:title' => $video->f_title,
|
||||
'upnp:class' => (isset($arrFileType['class'])) ? $arrFileType['class'] : 'object.item.unknownItem',
|
||||
'upnp:albumArtURI' => $art_url,
|
||||
'upnp:genre' => Tag::get_display($video->tags, false, 'video'),
|
||||
|
||||
'res' => Video::play_url($video->id),
|
||||
'protocolInfo' => $arrFileType['mime'],
|
||||
'size' => $video->size,
|
||||
'duration' => $video->f_time_h . '.0',
|
||||
);
|
||||
}
|
||||
|
||||
private static function _getFileTypes()
|
||||
{
|
||||
return array(
|
||||
|
|
|
@ -1155,7 +1155,7 @@ class User extends database_object
|
|||
$avatar['title'] = T_('User avatar');
|
||||
$upavatar = new Art($this->id, 'user');
|
||||
if ($upavatar->get_db()) {
|
||||
$avatar['url'] = AmpConfig::get('web_path') . '/image.php?object_type=user&id=' . $this->id;
|
||||
$avatar['url'] = AmpConfig::get('web_path') . '/image.php?object_type=user&object_id=' . $this->id;
|
||||
$avatar['url_mini'] = $avatar['url'];
|
||||
$avatar['url_medium'] = $avatar['url'];
|
||||
$avatar['url'] .= '&thumb=4';
|
||||
|
|
|
@ -298,19 +298,9 @@ class vainfo
|
|||
$info['album'] = $info['album'] ?: trim($tags['album']);
|
||||
|
||||
$info['band'] = $info['band'] ?: trim($tags['band']);
|
||||
$info['composer'] = $info['composer'] ?: trim($tags['composer']);
|
||||
|
||||
// multiple genre support
|
||||
if ((!$info['genre']) && $tags['genre']) {
|
||||
if (!is_array($tags['genre'])) {
|
||||
// not all tag formats will return an array, but we need one
|
||||
$info['genre'][] = trim($tags['genre']);
|
||||
} else {
|
||||
// if we trim the array we lose everything after 1st entry
|
||||
foreach ($tags['genre'] as $genre) {
|
||||
$info['genre'][] = trim($genre);
|
||||
}
|
||||
}
|
||||
}
|
||||
$info['genre'] = self::clean_array_tag('genre', $info, $tags);
|
||||
|
||||
$info['mb_trackid'] = $info['mb_trackid'] ?: trim($tags['mb_trackid']);
|
||||
$info['mb_albumid'] = $info['mb_albumid'] ?: trim($tags['mb_albumid']);
|
||||
|
@ -330,12 +320,17 @@ class vainfo
|
|||
$info['resolution_y'] = $info['resolution_y'] ?: intval($tags['resolution_y']);
|
||||
$info['audio_codec'] = $info['audio_codec'] ?: trim($tags['audio_codec']);
|
||||
$info['video_codec'] = $info['video_codec'] ?: trim($tags['video_codec']);
|
||||
$info['description'] = $info['description'] ?: trim($tags['description']);
|
||||
|
||||
$info['tvshow'] = $info['tvshow'] ?: trim($tags['tvshow']);
|
||||
$info['tvshow_year'] = $info['tvshow_year'] ?: trim($tags['tvshow_year']);
|
||||
$info['tvshow_season'] = $info['tvshow_season'] ?: trim($tags['tvshow_season']);
|
||||
$info['tvshow_episode'] = $info['tvshow_episode'] ?: trim($tags['tvshow_episode']);
|
||||
$info['release_date'] = $info['release_date'] ?: trim($tags['release_date']);
|
||||
|
||||
$info['tvshow_art'] = $info['tvshow_art'] ?: trim($tags['tvshow_art']);
|
||||
$info['tvshow_season_art'] = $info['tvshow_season_art'] ?: trim($tags['tvshow_season_art']);
|
||||
$info['art'] = $info['art'] ?: trim($tags['art']);
|
||||
}
|
||||
|
||||
// Some things set the disk number even though there aren't multiple
|
||||
|
@ -347,6 +342,25 @@ class vainfo
|
|||
return $info;
|
||||
}
|
||||
|
||||
private static function clean_array_tag($field, $info, $tags)
|
||||
{
|
||||
$arr = array();
|
||||
if ((!$info[$field] || count($info[$field]) == 0) && $tags[$field]) {
|
||||
if (!is_array($tags[$field])) {
|
||||
// not all tag formats will return an array, but we need one
|
||||
$arr[] = trim($tags[$field]);
|
||||
} else {
|
||||
foreach ($tags[$field] as $genre) {
|
||||
$arr[] = trim($genre);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$arr = $info[$field];
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* _get_type
|
||||
*
|
||||
|
|
|
@ -36,8 +36,12 @@ class Video extends database_object implements media
|
|||
public $release_date;
|
||||
public $catalog;
|
||||
|
||||
public $type;
|
||||
public $tags;
|
||||
public $f_title;
|
||||
public $f_full_title;
|
||||
public $f_time;
|
||||
public $f_time_h;
|
||||
public $link;
|
||||
public $f_link;
|
||||
public $f_codec;
|
||||
|
@ -60,10 +64,28 @@ class Video extends database_object implements media
|
|||
$this->$key = $value;
|
||||
}
|
||||
|
||||
$data = pathinfo($this->file);
|
||||
$this->type = strtolower($data['extension']);
|
||||
|
||||
return true;
|
||||
|
||||
} // Constructor
|
||||
|
||||
public static function create_from_id($video_id)
|
||||
{
|
||||
$dtypes = self::get_derived_types();
|
||||
foreach ($dtypes as $dtype) {
|
||||
$sql = "SELECT `id` FROM `" . strtolower($dtype) . "` WHERE `id` = ?";
|
||||
$db_results = Dba::read($sql, array($video_id));
|
||||
if ($results = Dba::fetch_assoc($db_results)) {
|
||||
if ($results['id']) {
|
||||
return new $dtype($video_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Video($video_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* build_cache
|
||||
* Build a cache based on the array of ids passed, saves lots of little queries
|
||||
|
@ -90,6 +112,7 @@ class Video extends database_object implements media
|
|||
public function format()
|
||||
{
|
||||
$this->f_title = scrub_out($this->title);
|
||||
$this->f_full_title = $this->f_title;
|
||||
$this->link = AmpConfig::get('web_path') . "/video.php?action=show_video&video_id=" . $this->id;
|
||||
if (strtolower(get_class($this)) != 'video') {
|
||||
$this->link .= '&type=' . get_class($this);
|
||||
|
@ -97,7 +120,19 @@ class Video extends database_object implements media
|
|||
$this->f_link = "<a href=\"" . $this->link . "\" title=\"" . scrub_out($this->f_title) . "\"> " . scrub_out($this->f_title) . "</a>";
|
||||
$this->f_codec = $this->video_codec . ' / ' . $this->audio_codec;
|
||||
$this->f_resolution = $this->resolution_x . 'x' . $this->resolution_y;
|
||||
$this->f_tags = '';
|
||||
|
||||
// Format the Time
|
||||
$min = floor($this->time/60);
|
||||
$sec = sprintf("%02d", ($this->time%60));
|
||||
$this->f_time = $min . ":" . $sec;
|
||||
$hour = sprintf("%02d", floor($min/60));
|
||||
$min_h = sprintf("%02d", ($min%60));
|
||||
$this->f_time_h = $hour . ":" . $min_h . ":" . $sec;
|
||||
|
||||
// Get the top tags
|
||||
$this->tags = Tag::get_top_tags('video', $this->id);
|
||||
$this->f_tags = Tag::get_display($this->tags, true, 'video');
|
||||
|
||||
$this->f_length = floor($this->time/60) . ' ' . T_('minutes');
|
||||
$this->f_file = $this->f_title . '.' . $this->type;
|
||||
if ($this->release_date) {
|
||||
|
@ -138,7 +173,7 @@ class Video extends database_object implements media
|
|||
|
||||
if (!$video->id) { return false; }
|
||||
|
||||
$uid = intval($GLOBALS['user']->id);
|
||||
$uid = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1';
|
||||
$oid = intval($video->id);
|
||||
|
||||
$url = Stream::get_base_url() . "type=video&uid=" . $uid . "&oid=" . $oid;
|
||||
|
@ -157,17 +192,100 @@ class Video extends database_object implements media
|
|||
return false;
|
||||
}
|
||||
|
||||
private static function get_derived_types()
|
||||
{
|
||||
return array('TVShow_Episode', 'Movie', 'Clip', 'Personal_Video');
|
||||
}
|
||||
|
||||
public static function validate_type($type)
|
||||
{
|
||||
switch (strtolower($type)) {
|
||||
case 'tvshow_episode':
|
||||
case 'movie':
|
||||
case 'clip':
|
||||
case 'personal_video':
|
||||
$dtypes = self::get_derived_types();
|
||||
foreach ($dtypes as $dtype) {
|
||||
if (strtolower($type) == strtolower($dtype))
|
||||
return $type;
|
||||
default:
|
||||
}
|
||||
|
||||
return 'Video';
|
||||
}
|
||||
|
||||
/**
|
||||
* type_to_mime
|
||||
*
|
||||
* Returns the mime type for the specified file extension/type
|
||||
*/
|
||||
public static function type_to_mime($type)
|
||||
{
|
||||
// FIXME: This should really be done the other way around.
|
||||
// Store the mime type in the database, and provide a function
|
||||
// to make it a human-friendly type.
|
||||
switch ($type) {
|
||||
case 'avi':
|
||||
return 'video/avi';
|
||||
case 'ogg':
|
||||
return 'application/ogg';
|
||||
case 'wmv':
|
||||
return 'audio/x-ms-wmv';
|
||||
case 'mp4':
|
||||
case 'm4v':
|
||||
return 'video/mp4';
|
||||
case 'mkv':
|
||||
return 'video/x-matroska';
|
||||
default:
|
||||
return 'video/mpeg';
|
||||
}
|
||||
}
|
||||
|
||||
public static function insert($data, $gtypes = array(), $options = array())
|
||||
{
|
||||
$rezx = intval($data['resolution_x']);
|
||||
$rezy = intval($data['resolution_y']);
|
||||
$release_date = intval($data['release_date']);
|
||||
$tags = $data['genre'];
|
||||
|
||||
$sql = "INSERT INTO `video` (`file`,`catalog`,`title`,`video_codec`,`audio_codec`,`resolution_x`,`resolution_y`,`size`,`time`,`mime`,`release_date`,`addition_time`) " .
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
$params = array($data['file'], $data['catalog'], $data['title'], $data['video_codec'], $data['audio_codec'], $rezx, $rezy, $data['size'], $data['time'], $data['mime'], $release_date, time());
|
||||
Dba::write($sql, $params);
|
||||
$vid = Dba::insert_id();
|
||||
|
||||
if (is_array($tags)) {
|
||||
foreach ($tags as $tag) {
|
||||
$tag = trim($tag);
|
||||
if (!empty($tag)) {
|
||||
Tag::add('video', $vid, $tag, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['art'] && $options['gather_art']) {
|
||||
$art = new Art($vid, 'video');
|
||||
$art->insert_url($data['art']);
|
||||
}
|
||||
|
||||
$data['id'] = $vid;
|
||||
self::insert_video_type($data, $gtypes, $options);
|
||||
}
|
||||
|
||||
private static function insert_video_type($data, $gtypes, $options = array())
|
||||
{
|
||||
if (count($gtypes) > 0) {
|
||||
$gtype = $gtypes[0];
|
||||
switch ($gtype) {
|
||||
case 'tvshow':
|
||||
return TVShow_Episode::insert($data, $options);
|
||||
case 'movie':
|
||||
return Movie::insert($data, $options);
|
||||
case 'clip':
|
||||
return Clip::insert($data, $options);
|
||||
case 'personal_video':
|
||||
return Personal_Video::insert($data, $options);
|
||||
default:
|
||||
// Do nothing, video entry already created and no additional data for now
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $data['id'];
|
||||
}
|
||||
|
||||
} // end Video class
|
||||
|
|
|
@ -342,7 +342,7 @@ class XML_Data
|
|||
$rating = new Rating($album_id,'album');
|
||||
|
||||
// Build the Art URL, include session
|
||||
$art_url = AmpConfig::get('web_path') . '/image.php?id=' . $album->id . '&auth=' . scrub_out($_REQUEST['auth']);
|
||||
$art_url = AmpConfig::get('web_path') . '/image.php?object_id=' . $album->id . '&object_type=album&auth=' . scrub_out($_REQUEST['auth']);
|
||||
|
||||
$string .= "<album id=\"" . $album->id . "\">\n" .
|
||||
"\t<name><![CDATA[" . $album->name . "]]></name>\n";
|
||||
|
|
|
@ -104,7 +104,6 @@ require_once $prefix . '/modules/getid3/getid3.php';
|
|||
require_once $prefix . '/modules/phpmailer/class.phpmailer.php';
|
||||
require_once $prefix . '/modules/phpmailer/class.smtp.php';
|
||||
require_once $prefix . '/modules/infotools/AmazonSearchEngine.class.php';
|
||||
require_once $prefix . '/modules/infotools/lastfm.class.php';
|
||||
require_once $prefix . '/modules/musicbrainz/MusicBrainz.php';
|
||||
require_once $prefix . '/modules/musicbrainz/Exception.php';
|
||||
require_once $prefix . '/modules/musicbrainz/Clients/MbClient.php';
|
||||
|
|
|
@ -19,8 +19,7 @@ use Tmdb\Client;
|
|||
* Class AbstractApi
|
||||
* @package Tmdb\Api
|
||||
*/
|
||||
abstract class AbstractApi
|
||||
implements ApiInterface
|
||||
abstract class AbstractApi implements ApiInterface
|
||||
{
|
||||
/**
|
||||
* The client
|
||||
|
@ -53,6 +52,7 @@ abstract class AbstractApi
|
|||
* @var Response $response
|
||||
*/
|
||||
$response = $this->client->getHttpClient()->get($path, $parameters, $headers);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ abstract class AbstractApi
|
|||
* @var Response $response
|
||||
*/
|
||||
$response = $this->client->getHttpClient()->head($path, $parameters, $headers);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
|
@ -88,6 +89,7 @@ abstract class AbstractApi
|
|||
* @var Response $response
|
||||
*/
|
||||
$response = $this->client->getHttpClient()->post($path, $postBody, $parameters, $headers);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
|
@ -110,6 +112,7 @@ abstract class AbstractApi
|
|||
}
|
||||
|
||||
$response = $this->client->getHttpClient()->postJson($path, $postBody, $parameters, $headers);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
|
@ -128,6 +131,7 @@ abstract class AbstractApi
|
|||
* @var Response $response
|
||||
*/
|
||||
$response = $this->client->getHttpClient()->put($path, $body, $parameters, $headers);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
|
@ -146,6 +150,7 @@ abstract class AbstractApi
|
|||
* @var Response $response
|
||||
*/
|
||||
$response = $this->client->getHttpClient()->delete($path, $body, $parameters, $headers);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
|
@ -164,6 +169,7 @@ abstract class AbstractApi
|
|||
* @var Response $response
|
||||
*/
|
||||
$response = $this->client->getHttpClient()->patch($path, $body, $parameters, $headers);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#account
|
||||
*/
|
||||
class Account
|
||||
extends AbstractApi
|
||||
class Account extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the basic information for an account. You will need to have a valid session id.
|
||||
|
|
|
@ -16,5 +16,6 @@ namespace Tmdb\Api;
|
|||
* Interface ApiInterface
|
||||
* @package Tmdb\Api
|
||||
*/
|
||||
interface ApiInterface {
|
||||
interface ApiInterface
|
||||
{
|
||||
}
|
||||
|
|
|
@ -12,16 +12,15 @@
|
|||
*/
|
||||
namespace Tmdb\Api;
|
||||
|
||||
use Symfony\Component\Yaml\Exception\RuntimeException;
|
||||
use Tmdb\Exception\UnauthorizedRequestTokenException;
|
||||
use Tmdb\RequestToken;
|
||||
|
||||
/**
|
||||
* Class Authentication
|
||||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#authentication
|
||||
*/
|
||||
class Authentication
|
||||
extends AbstractApi
|
||||
class Authentication extends AbstractApi
|
||||
{
|
||||
const REQUEST_TOKEN_URI = 'https://www.themoviedb.org/authenticate';
|
||||
|
||||
|
@ -46,11 +45,13 @@ class Authentication
|
|||
*/
|
||||
public function authenticateRequestToken($token)
|
||||
{
|
||||
//@codeCoverageIgnoreStart
|
||||
header(sprintf(
|
||||
'Location: %s/%s',
|
||||
self::REQUEST_TOKEN_URI,
|
||||
$token
|
||||
));
|
||||
//@codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,13 +64,74 @@ class Authentication
|
|||
*/
|
||||
public function getNewSession($requestToken)
|
||||
{
|
||||
if ($requestToken instanceof RequestToken) {
|
||||
$requestToken = $requestToken->getToken();
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->get('authentication/session/new', array('request_token' => $requestToken));
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
|
||||
//@codeCoverageIgnoreStart
|
||||
} catch (\Exception $e) {
|
||||
if ($e->getCode() == 401) {
|
||||
throw new UnauthorizedRequestTokenException("The request token has not been validated yet.");
|
||||
}
|
||||
//@codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to validate the request_token and obtain a session_token
|
||||
*
|
||||
* @param $requestToken
|
||||
* @param $username
|
||||
* @param $password
|
||||
* @return mixed
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getSessionTokenWithLogin($requestToken, $username, $password)
|
||||
{
|
||||
if ($requestToken instanceof RequestToken) {
|
||||
$requestToken = $requestToken->getToken();
|
||||
}
|
||||
|
||||
$validatedRequestToken = $this->validateRequestTokenWithLogin($requestToken, $username, $password);
|
||||
|
||||
if (!$validatedRequestToken['success']) {
|
||||
throw new \InvalidArgumentException('Unable to validate the request_token, please check your credentials.');
|
||||
}
|
||||
|
||||
return $this->getNewSession($validatedRequestToken['request_token']);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to generate a session id for user based authentication.
|
||||
* A session id is required in order to use any of the write methods.
|
||||
*
|
||||
* @param string $requestToken
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @throws UnauthorizedRequestTokenException
|
||||
* @return mixed
|
||||
*/
|
||||
public function validateRequestTokenWithLogin($requestToken, $username, $password)
|
||||
{
|
||||
if ($requestToken instanceof RequestToken) {
|
||||
$requestToken = $requestToken->getToken();
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->get('authentication/token/validate_with_login', array(
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'request_token' => $requestToken
|
||||
));
|
||||
//@codeCoverageIgnoreStart
|
||||
} catch (\Exception $e) {
|
||||
if ($e->getCode() == 401) {
|
||||
throw new UnauthorizedRequestTokenException("The request token has not been validated yet.");
|
||||
}
|
||||
//@codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +142,8 @@ class Authentication
|
|||
* You should only generate a single guest session per user (or device)
|
||||
* as you will be able to attach the ratings to a TMDb user account in the future.
|
||||
*
|
||||
* There is also IP limits in place so you should always make sure it's the end user doing the guest session actions.
|
||||
* There is also IP limits in place so you should always make sure it's the end user
|
||||
* doing the guest session actions.
|
||||
*
|
||||
* If a guest session is not used for the first time within 24 hours, it will be automatically discarded.
|
||||
*
|
||||
|
|
|
@ -17,13 +17,13 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#certifications
|
||||
*/
|
||||
class Certifications
|
||||
extends AbstractApi
|
||||
class Certifications extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the list of supported certifications for movies.
|
||||
*
|
||||
* These can be used in conjunction with the certification_country and certification.lte parameters when using discover.
|
||||
* These can be used in conjunction with the certification_country and
|
||||
* certification.lte parameters when using discover.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* http://docs.themoviedb.apiary.io/#changes
|
||||
*/
|
||||
class Changes
|
||||
extends AbstractApi
|
||||
class Changes extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get a list of movie ids that have been edited.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#collections
|
||||
*/
|
||||
class Collections
|
||||
extends AbstractApi
|
||||
class Collections extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the basic collection information for a specific collection id.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#companies
|
||||
*/
|
||||
class Companies
|
||||
extends AbstractApi
|
||||
class Companies extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* This method is used to retrieve all of the basic information about a company.
|
||||
|
|
|
@ -18,8 +18,7 @@ namespace Tmdb\Api;
|
|||
*
|
||||
* @see http://docs.themoviedb.apiary.io/#configuration
|
||||
*/
|
||||
class Configuration
|
||||
extends AbstractApi
|
||||
class Configuration extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the system wide configuration information.
|
||||
|
|
|
@ -17,12 +17,14 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#credits
|
||||
*/
|
||||
class Credits
|
||||
extends AbstractApi
|
||||
class Credits extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the detailed information about a particular credit record. This is currently only supported with the new credit model found in TV.
|
||||
* These ids can be found from any TV credit response as well as the tv_credits and combined_credits methods for people.
|
||||
* Get the detailed information about a particular credit record.
|
||||
*
|
||||
* This is currently only supported with the new credit model found in TV.
|
||||
* These ids can be found from any TV credit response as well as
|
||||
* the tv_credits and combined_credits methods for people.
|
||||
*
|
||||
* The episodes object returns a list of episodes and are generally going to be guest stars.
|
||||
* The season array will return a list of season numbers.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#discover
|
||||
*/
|
||||
class Discover
|
||||
extends AbstractApi
|
||||
class Discover extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Discover movies by different types of data like average rating, number of votes, genres and certifications.
|
||||
|
@ -33,7 +32,8 @@ class Discover
|
|||
}
|
||||
|
||||
/**
|
||||
* Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates.
|
||||
* Discover TV shows by different types of data like average rating, number of votes, genres,
|
||||
* the network they aired on and air dates.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
|
|
|
@ -17,12 +17,15 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#find
|
||||
*/
|
||||
class Find
|
||||
extends AbstractApi
|
||||
class Find extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* The find method makes it easy to search for objects in our database by an external id. For instance, an IMDB ID. This will search all objects (movies, TV shows and people) and return the results in a single response. TV season and TV episode searches will be supported shortly.
|
||||
* The find method makes it easy to search for objects in our database by an external id.
|
||||
*
|
||||
* For instance, an IMDB ID. This will search all objects (movies, TV shows and people)
|
||||
* and return the results in a single response.
|
||||
*
|
||||
* TV season and TV episode searches will be supported shortly.
|
||||
* The supported external sources for each object are as follows:
|
||||
*
|
||||
* Movies: imdb_id
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#genres
|
||||
*/
|
||||
class Genres
|
||||
extends AbstractApi
|
||||
class Genres extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the list of genres, and return one by id
|
||||
|
@ -71,10 +70,11 @@ class Genres
|
|||
*/
|
||||
private function extractGenreByIdFromResponse($id, array $data = array())
|
||||
{
|
||||
foreach($data as $genre) {
|
||||
if ($id == $genre['id'])
|
||||
foreach ($data as $genre) {
|
||||
if ($id == $genre['id']) {
|
||||
return $genre;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
42
modules/Tmdb/Api/GuestSession.php
Normal file
42
modules/Tmdb/Api/GuestSession.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Api;
|
||||
use Tmdb\Exception\MissingSessionTokenException;
|
||||
use Tmdb\SessionToken;
|
||||
|
||||
/**
|
||||
* Class GuestSession
|
||||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#guestsessions
|
||||
*/
|
||||
class GuestSession extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get a list of rated movies for a specific guest session id.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @throws MissingSessionTokenException when the guest session token was not set on the client.
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRatedMovies(array $parameters = array(), array $headers = array())
|
||||
{
|
||||
$sessionToken = $this->client->getSessionToken();
|
||||
|
||||
if (!$sessionToken instanceof SessionToken) {
|
||||
throw new MissingSessionTokenException('The guest session token was not set on the client.');
|
||||
}
|
||||
|
||||
return $this->get('guest_session/' . $sessionToken->getToken() . '/rated_movies', $parameters, $headers);
|
||||
}
|
||||
}
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#jobs
|
||||
*/
|
||||
class Jobs
|
||||
extends AbstractApi
|
||||
class Jobs extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get a list of valid jobs.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#keywords
|
||||
*/
|
||||
class Keywords
|
||||
extends AbstractApi
|
||||
class Keywords extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the basic information for a specific keyword id.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#lists
|
||||
*/
|
||||
class Lists
|
||||
extends AbstractApi
|
||||
class Lists extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get a list by id.
|
||||
|
@ -99,4 +98,23 @@ class Lists
|
|||
{
|
||||
return $this->delete('list/' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all of the items within a list.
|
||||
*
|
||||
* This is a irreversible action and should be treated with caution.
|
||||
* A valid session id is required.
|
||||
*
|
||||
* @param string $id
|
||||
* @param boolean $confirm
|
||||
* @return mixed
|
||||
*/
|
||||
public function clearList($id, $confirm)
|
||||
{
|
||||
return $this->post(sprintf(
|
||||
'list/%s/clear?confirm=%s',
|
||||
$id,
|
||||
(bool) $confirm === true ? 'true':'false'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#movies
|
||||
*/
|
||||
class Movies
|
||||
extends AbstractApi
|
||||
class Movies extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the basic movie information for a specific movie id.
|
||||
|
@ -101,6 +100,7 @@ class Movies
|
|||
/**
|
||||
* Get the trailers for a specific movie id.
|
||||
*
|
||||
* @deprecated TMDB changed the way of requesting trailers, see getVideos instead!
|
||||
* @param $movie_id
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
|
@ -189,7 +189,8 @@ class Movies
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the list of upcoming movies. This list refreshes every day. The maximum number of items this list will include is 100.
|
||||
* Get the list of upcoming movies. This list refreshes every day.
|
||||
* The maximum number of items this list will include is 100.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
|
@ -201,7 +202,8 @@ class Movies
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the list of movies playing in theatres. This list refreshes every day. The maximum number of items this list will include is 100.
|
||||
* Get the list of movies playing in theatres. This list refreshes every day.
|
||||
* The maximum number of items this list will include is 100.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
|
@ -213,7 +215,8 @@ class Movies
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the list of popular movies on The Movie Database. This list refreshes every day.
|
||||
* Get the list of popular movies on The Movie Database.
|
||||
* This list refreshes every day.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
|
@ -225,7 +228,8 @@ class Movies
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day.
|
||||
* Get the list of top rated movies. By default, this list will only include
|
||||
* movies that have 10 or more votes. This list refreshes every day.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
|
@ -237,7 +241,8 @@ class Movies
|
|||
}
|
||||
|
||||
/**
|
||||
* This method lets users get the status of whether or not the movie has been rated or added to their favourite or watch lists.
|
||||
* This method lets users get the status of whether or not the movie has been rated
|
||||
* or added to their favourite or watch lists.
|
||||
*
|
||||
* A valid session id is required.
|
||||
*
|
||||
|
@ -259,4 +264,17 @@ class Movies
|
|||
{
|
||||
return $this->postJson('movie/' . $id . '/rating', array('value' => (float) $rating));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the videos (trailers, teasers, clips, etc...) for a specific movie id.
|
||||
*
|
||||
* @param $movie_id
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVideos($movie_id, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get('movie/' . $movie_id . '/videos', $parameters, $headers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#networks
|
||||
*/
|
||||
class Networks
|
||||
extends AbstractApi
|
||||
class Networks extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* This method is used to retrieve the basic information about a TV network.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#people
|
||||
*/
|
||||
class People
|
||||
extends AbstractApi
|
||||
class People extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the general person information for a specific id.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#reviews
|
||||
*/
|
||||
class Reviews
|
||||
extends AbstractApi
|
||||
class Reviews extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the full details of a review by ID.
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#search
|
||||
*/
|
||||
class Search
|
||||
extends AbstractApi
|
||||
class Search extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Search for movies by title.
|
||||
|
|
31
modules/Tmdb/Api/Timezones.php
Normal file
31
modules/Tmdb/Api/Timezones.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Api;
|
||||
|
||||
/**
|
||||
* Class Timezones
|
||||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#timezones
|
||||
*/
|
||||
class Timezones extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the list of supported timezones for the API methods that support them.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTimezones()
|
||||
{
|
||||
return $this->get('timezones/list');
|
||||
}
|
||||
}
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#tv
|
||||
*/
|
||||
class Tv
|
||||
extends AbstractApi
|
||||
class Tv extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the primary information about a TV series by id.
|
||||
|
@ -112,7 +111,47 @@ class Tv
|
|||
*/
|
||||
public function getTranslations($tvshow_id, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
$this->get('tv/' . $tvshow_id . '/translations', $parameters, $headers);
|
||||
return $this->get('tv/' . $tvshow_id . '/translations', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of TV shows that are currently on the air.
|
||||
*
|
||||
* This query looks for any TV show that has an episode with an air date in the next 7 days.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOnTheAir(array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get('tv/on_the_air', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of TV shows that air today.
|
||||
*
|
||||
* Without a specified timezone, this query defaults to EST (Eastern Time UTC-05:00).
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAiringToday(array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get('tv/airing_today', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the videos that have been added to a TV series (trailers, opening credits, etc...)
|
||||
*
|
||||
* @param int $tvshow_id
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVideos($tvshow_id, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get('tv/' . $tvshow_id . '/videos', $parameters, $headers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#tvepisodes
|
||||
*/
|
||||
class TvEpisode
|
||||
extends AbstractApi
|
||||
class TvEpisode extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the primary information about a TV episode by combination of a season and episode number.
|
||||
|
@ -30,9 +29,23 @@ class TvEpisode
|
|||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEpisode($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get(sprintf('tv/%s/season/%s/episode/%s', $tvshow_id, $season_number,$episode_number), $parameters, $headers);
|
||||
public function getEpisode(
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number,
|
||||
array $parameters = array(),
|
||||
array $headers = array()
|
||||
) {
|
||||
return $this->get(
|
||||
sprintf(
|
||||
'tv/%s/season/%s/episode/%s',
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number
|
||||
),
|
||||
$parameters,
|
||||
$headers
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,9 +58,23 @@ class TvEpisode
|
|||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCredits($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get(sprintf('tv/%s/season/%s/episode/%s/credits', $tvshow_id, $season_number,$episode_number), $parameters, $headers);
|
||||
public function getCredits(
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number,
|
||||
array $parameters = array(),
|
||||
array $headers = array()
|
||||
) {
|
||||
return $this->get(
|
||||
sprintf(
|
||||
'tv/%s/season/%s/episode/%s/credits',
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number
|
||||
),
|
||||
$parameters,
|
||||
$headers
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,9 +87,23 @@ class TvEpisode
|
|||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExternalIds($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get(sprintf('tv/%s/season/%s/episode/%s/external_ids', $tvshow_id, $season_number,$episode_number), $parameters, $headers);
|
||||
public function getExternalIds(
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number,
|
||||
array $parameters = array(),
|
||||
array $headers = array()
|
||||
) {
|
||||
return $this->get(
|
||||
sprintf(
|
||||
'tv/%s/season/%s/episode/%s/external_ids',
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number
|
||||
),
|
||||
$parameters,
|
||||
$headers
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,8 +116,51 @@ class TvEpisode
|
|||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getImages($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get(sprintf('tv/%s/season/%s/episode/%s/images', $tvshow_id, $season_number,$episode_number), $parameters, $headers);
|
||||
public function getImages(
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number,
|
||||
array $parameters = array(),
|
||||
array $headers = array()
|
||||
) {
|
||||
return $this->get(
|
||||
sprintf(
|
||||
'tv/%s/season/%s/episode/%s/images',
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number
|
||||
),
|
||||
$parameters,
|
||||
$headers
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the videos that have been added to a TV episode (teasers, clips, etc...)
|
||||
*
|
||||
* @param $tvshow_id
|
||||
* @param $season_number
|
||||
* @param $episode_number
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVideos(
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number,
|
||||
array $parameters = array(),
|
||||
array $headers = array()
|
||||
) {
|
||||
return $this->get(
|
||||
sprintf(
|
||||
'tv/%s/season/%s/episode/%s/videos',
|
||||
$tvshow_id,
|
||||
$season_number,
|
||||
$episode_number
|
||||
),
|
||||
$parameters,
|
||||
$headers
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace Tmdb\Api;
|
|||
* @package Tmdb\Api
|
||||
* @see http://docs.themoviedb.apiary.io/#tvseasons
|
||||
*/
|
||||
class TvSeason
|
||||
extends AbstractApi
|
||||
class TvSeason extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get the primary information about a TV season by its season number.
|
||||
|
@ -75,4 +74,18 @@ class TvSeason
|
|||
{
|
||||
return $this->get(sprintf('tv/%s/season/%s/images', $tvshow_id, $season_number), $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the videos that have been added to a TV season (trailers, teasers, etc...)
|
||||
*
|
||||
* @param $tvshow_id
|
||||
* @param $season_number
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVideos($tvshow_id, $season_number, array $parameters = array(), array $headers = array())
|
||||
{
|
||||
return $this->get(sprintf('tv/%s/season/%s/videos', $tvshow_id, $season_number), $parameters, $headers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@
|
|||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb;
|
||||
use Tmdb\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* Class ApiToken
|
||||
* @package Tmdb
|
||||
*/
|
||||
class ApiToken {
|
||||
class ApiToken
|
||||
{
|
||||
private $apiToken = null;
|
||||
|
||||
/**
|
||||
|
@ -30,12 +32,18 @@ class ApiToken {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param null $apiToken
|
||||
* @param string $apiToken
|
||||
* @throws RuntimeException
|
||||
* @return $this
|
||||
*/
|
||||
public function setToken($apiToken)
|
||||
{
|
||||
if (!is_string($apiToken)) {
|
||||
throw new RuntimeException('The Apitoken must be set.');
|
||||
}
|
||||
|
||||
$this->apiToken = $apiToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,20 +12,17 @@
|
|||
*/
|
||||
namespace Tmdb;
|
||||
|
||||
use Guzzle\Http\Client as GuzzleClient;
|
||||
use Guzzle\Http\ClientInterface;
|
||||
use Tmdb\HttpClient\HttpClient;
|
||||
use Tmdb\HttpClient\HttpClientInterface;
|
||||
use Tmdb\ApiToken as Token;
|
||||
use Tmdb\HttpClient\Plugin\AcceptJsonHeaderPlugin;
|
||||
use Tmdb\HttpClient\Plugin\ApiTokenPlugin;
|
||||
use Tmdb\HttpClient\Plugin\SessionTokenPlugin;
|
||||
|
||||
/**
|
||||
* Client wrapper for TMDB
|
||||
* @package Tmdb
|
||||
*/
|
||||
class Client {
|
||||
class Client
|
||||
{
|
||||
/**
|
||||
* Base API URI
|
||||
*/
|
||||
|
@ -69,29 +66,93 @@ class Client {
|
|||
*/
|
||||
private $httpClient;
|
||||
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* Holds the log path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $logPath;
|
||||
|
||||
/**
|
||||
* Enable logging?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $logEnabled = false;
|
||||
|
||||
/**
|
||||
* Stores the cache path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cachePath;
|
||||
|
||||
/**
|
||||
* Stores wether the cache is enabled or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $cacheEnabled = false;
|
||||
|
||||
/**
|
||||
* Construct our client
|
||||
*
|
||||
* @param ClientInterface|null $httpClient
|
||||
* @param ApiToken $token
|
||||
* @param boolean $secure
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Token $token, ClientInterface $httpClient = null, $secure = false)
|
||||
public function __construct(
|
||||
ApiToken $token,
|
||||
ClientInterface $httpClient = null,
|
||||
$secure = false,
|
||||
$options = array()
|
||||
)
|
||||
{
|
||||
$this->setToken($token);
|
||||
$this->setSecure($secure);
|
||||
|
||||
$httpClient = $httpClient ?: new GuzzleClient($this->getBaseUrl());
|
||||
|
||||
if ($httpClient instanceof \Guzzle\Common\HasDispatcherInterface) {
|
||||
$apiTokenPlugin = new ApiTokenPlugin($token);
|
||||
$httpClient->addSubscriber($apiTokenPlugin);
|
||||
|
||||
$acceptJsonHeaderPlugin = new AcceptJsonHeaderPlugin();
|
||||
$httpClient->addSubscriber($acceptJsonHeaderPlugin);
|
||||
$this->constructHttpClient(
|
||||
$httpClient,
|
||||
array_merge(
|
||||
array(
|
||||
'token' => $this->getToken(),
|
||||
'secure' => $this->getSecure()
|
||||
),
|
||||
$options
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->httpClient = new HttpClient($this->getBaseUrl(), array(), $httpClient);
|
||||
/**
|
||||
* Construct the http client
|
||||
*
|
||||
* @param ClientInterface $httpClient
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
private function constructHttpClient(ClientInterface $httpClient = null, array $options)
|
||||
{
|
||||
$httpClient = $httpClient ?: new \Guzzle\Http\Client($this->getBaseUrl());
|
||||
$this->httpClient = new HttpClient(
|
||||
$this->getBaseUrl(),
|
||||
$options,
|
||||
$httpClient
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the token subscriber
|
||||
*
|
||||
* @return Token
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token !== null ? $this->token : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,6 +164,7 @@ class Client {
|
|||
public function setToken(Token $token)
|
||||
{
|
||||
$this->token = $token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -283,7 +345,23 @@ class Client {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return HttpClientInterface
|
||||
* @return Api\Timezones
|
||||
*/
|
||||
public function getTimezonesApi()
|
||||
{
|
||||
return new Api\Timezones($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Api\GuestSession
|
||||
*/
|
||||
public function getGuestSessionApi()
|
||||
{
|
||||
return new Api\GuestSession($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpClient|HttpClientInterface
|
||||
*/
|
||||
public function getHttpClient()
|
||||
{
|
||||
|
@ -319,6 +397,11 @@ class Client {
|
|||
public function setSecure($secure)
|
||||
{
|
||||
$this->secure = $secure;
|
||||
|
||||
if ($this->httpClient instanceof HttpClientInterface) {
|
||||
$this->getHttpClient()->setBaseUrl($this->getBaseUrl());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -336,12 +419,12 @@ class Client {
|
|||
*/
|
||||
public function setSessionToken($sessionToken)
|
||||
{
|
||||
if ($this->httpClient->getClient() instanceof \Guzzle\Common\HasDispatcherInterface) {
|
||||
$sessionTokenPlugin = new SessionTokenPlugin($sessionToken);
|
||||
$this->httpClient->getClient()->addSubscriber($sessionTokenPlugin);
|
||||
$this->sessionToken = $sessionToken;
|
||||
|
||||
if ($this->httpClient instanceof HttpClientInterface) {
|
||||
$this->getHttpClient()->setSessionToken($sessionToken);
|
||||
}
|
||||
|
||||
$this->sessionToken = $sessionToken;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -352,4 +435,105 @@ class Client {
|
|||
{
|
||||
return $this->sessionToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCacheEnabled()
|
||||
{
|
||||
return $this->cacheEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache path
|
||||
*
|
||||
* Leaving the second argument out will use sys_get_temp_dir()
|
||||
*
|
||||
* @param boolean $enabled
|
||||
* @param string $path
|
||||
* @return $this
|
||||
*/
|
||||
public function setCaching($enabled = true, $path = null)
|
||||
{
|
||||
$this->cacheEnabled = $enabled;
|
||||
$this->cachePath = (null === $path) ?
|
||||
sys_get_temp_dir() . '/php-tmdb-api' :
|
||||
$path
|
||||
;
|
||||
|
||||
$this->getHttpClient()->setCaching(array(
|
||||
'enabled' => $enabled,
|
||||
'cache_path' => $path
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCachePath()
|
||||
{
|
||||
return $this->cachePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @return $this
|
||||
*/
|
||||
public function setLogger($logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Psr\Log\LoggerInterface
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getLogEnabled()
|
||||
{
|
||||
return $this->logEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set log path
|
||||
*
|
||||
* Leaving the second argument out will use sys_get_temp_dir()
|
||||
*
|
||||
* @param boolean $enabled
|
||||
* @param string $path
|
||||
* @return $this
|
||||
*/
|
||||
public function setLogging($enabled = true, $path = null)
|
||||
{
|
||||
$this->logEnabled = $enabled;
|
||||
$this->logPath = (null === $path) ?
|
||||
sys_get_temp_dir() . '/php-tmdb-api.log' :
|
||||
$path
|
||||
;
|
||||
|
||||
$this->getHttpClient()->setLogging(array(
|
||||
'enabled' => $enabled,
|
||||
'log_path' => $path
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLogPath()
|
||||
{
|
||||
return $this->logPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@ use Tmdb\Model\AbstractModel;
|
|||
* Class ObjectHydrator
|
||||
* @package Tmdb\Common
|
||||
*/
|
||||
class ObjectHydrator {
|
||||
class ObjectHydrator
|
||||
{
|
||||
/**
|
||||
* Hydrate the object with data
|
||||
*
|
||||
|
@ -35,7 +36,7 @@ class ObjectHydrator {
|
|||
if (!empty($data)) {
|
||||
foreach ($data as $k => $v) {
|
||||
|
||||
if (in_array($k, $object::$_properties)) {
|
||||
if (in_array($k, $object::$properties)) {
|
||||
|
||||
$method = $this->camelize(
|
||||
sprintf('set_%s', $k)
|
||||
|
@ -47,7 +48,7 @@ class ObjectHydrator {
|
|||
$method,
|
||||
get_class($object)
|
||||
));
|
||||
}else{
|
||||
} else {
|
||||
$object->$method($v);
|
||||
}
|
||||
}
|
||||
|
@ -68,10 +69,15 @@ class ObjectHydrator {
|
|||
public function camelize($candidate)
|
||||
{
|
||||
return lcfirst(
|
||||
implode('',
|
||||
array_map('ucfirst',
|
||||
array_map('strtolower',
|
||||
explode('_', $candidate
|
||||
implode(
|
||||
'',
|
||||
array_map(
|
||||
'ucfirst',
|
||||
array_map(
|
||||
'strtolower',
|
||||
explode(
|
||||
'_',
|
||||
$candidate
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -16,6 +16,6 @@ namespace Tmdb\Exception;
|
|||
* Class InvalidArgumentException
|
||||
* @package Tmdb\Exception
|
||||
*/
|
||||
class InvalidArgumentException extends \InvalidArgumentException {
|
||||
|
||||
class InvalidArgumentException extends \InvalidArgumentException
|
||||
{
|
||||
}
|
||||
|
|
|
@ -16,6 +16,6 @@ namespace Tmdb\Exception;
|
|||
* Class MissingArgumentException
|
||||
* @package Tmdb\Exception
|
||||
*/
|
||||
class MissingArgumentException extends \InvalidArgumentException {
|
||||
|
||||
class MissingArgumentException extends \InvalidArgumentException
|
||||
{
|
||||
}
|
||||
|
|
21
modules/Tmdb/Exception/MissingSessionTokenException.php
Normal file
21
modules/Tmdb/Exception/MissingSessionTokenException.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Exception;
|
||||
|
||||
/**
|
||||
* Class MissingSessionTokenException
|
||||
* @package Tmdb\Exception
|
||||
*/
|
||||
class MissingSessionTokenException extends \RuntimeException
|
||||
{
|
||||
}
|
|
@ -16,6 +16,6 @@ namespace Tmdb\Exception;
|
|||
* Class NotImplementedException
|
||||
* @package Tmdb\Exception
|
||||
*/
|
||||
class NotImplementedException extends \Exception {
|
||||
|
||||
class NotImplementedException extends \Exception
|
||||
{
|
||||
}
|
||||
|
|
|
@ -16,6 +16,6 @@ namespace Tmdb\Exception;
|
|||
* Class RuntimeException
|
||||
* @package Tmdb\Exception
|
||||
*/
|
||||
class RuntimeException extends \RuntimeException {
|
||||
|
||||
class RuntimeException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
|
|
26
modules/Tmdb/Exception/TmdbApiException.php
Normal file
26
modules/Tmdb/Exception/TmdbApiException.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Exception;
|
||||
|
||||
/**
|
||||
* Class TmdbApiException
|
||||
* @package Tmdb\Exception
|
||||
*/
|
||||
class TmdbApiException extends \Exception
|
||||
{
|
||||
public function __construct($message, $code)
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,6 @@ namespace Tmdb\Exception;
|
|||
* Class UnauthorizedRequestTokenException
|
||||
* @package Tmdb\Exception
|
||||
*/
|
||||
class UnauthorizedRequestTokenException extends \RuntimeException {
|
||||
|
||||
class UnauthorizedRequestTokenException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@ use Tmdb\Model\Common\GenericCollection;
|
|||
* Class AbstractFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
abstract class AbstractFactory {
|
||||
abstract class AbstractFactory
|
||||
{
|
||||
/**
|
||||
* Convert an array to an hydrated object
|
||||
*
|
||||
|
@ -39,13 +40,13 @@ abstract class AbstractFactory {
|
|||
abstract public function createCollection(array $data = array());
|
||||
|
||||
/**
|
||||
* Create a generic collection of data and map it on the class by it's static parameter $_properties
|
||||
* Create a generic collection of data and map it on the class by it's static parameter $properties
|
||||
*
|
||||
* @param array $data
|
||||
* @param $class
|
||||
* @return GenericCollection
|
||||
*/
|
||||
protected function createGenericCollection(array $data = array(), $class)
|
||||
protected function createGenericCollection($data = array(), $class)
|
||||
{
|
||||
if (is_object($class)) {
|
||||
$class = get_class($class);
|
||||
|
@ -53,7 +54,11 @@ abstract class AbstractFactory {
|
|||
|
||||
$collection = new GenericCollection();
|
||||
|
||||
foreach($data as $item) {
|
||||
if (null === $data) {
|
||||
return $collection;
|
||||
}
|
||||
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->hydrate(new $class(), $item));
|
||||
}
|
||||
|
||||
|
@ -67,10 +72,14 @@ abstract class AbstractFactory {
|
|||
* @param string $method
|
||||
* @return ResultCollection
|
||||
*/
|
||||
public function createResultCollection(array $data = array(), $method = 'create')
|
||||
public function createResultCollection($data = array(), $method = 'create')
|
||||
{
|
||||
$collection = new ResultCollection();
|
||||
|
||||
if (null === $data) {
|
||||
return $collection;
|
||||
}
|
||||
|
||||
if (array_key_exists('page', $data)) {
|
||||
$collection->setPage($data['page']);
|
||||
}
|
||||
|
@ -87,7 +96,7 @@ abstract class AbstractFactory {
|
|||
$data = $data['results'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->$method($item));
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ class AccountFactory extends AbstractFactory
|
|||
* @param array $data
|
||||
* @return \Tmdb\Model\Movie
|
||||
*/
|
||||
public function createMovie(array $data = array()) {
|
||||
public function createMovie(array $data = array())
|
||||
{
|
||||
return $this->getMovieFactory()->create($data);
|
||||
}
|
||||
|
||||
|
@ -100,6 +101,7 @@ class AccountFactory extends AbstractFactory
|
|||
public function setMovieFactory($movieFactory)
|
||||
{
|
||||
$this->movieFactory = $movieFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -118,6 +120,7 @@ class AccountFactory extends AbstractFactory
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Tmdb\Factory;
|
||||
|
||||
use Tmdb\Exception\NotImplementedException;
|
||||
use Tmdb\GuestSessionToken;
|
||||
use Tmdb\RequestToken;
|
||||
use Tmdb\SessionToken;
|
||||
|
||||
|
@ -98,7 +99,7 @@ class AuthenticationFactory extends AbstractFactory
|
|||
*/
|
||||
public function createGuestSessionToken(array $data = array())
|
||||
{
|
||||
$token = new SessionToken();
|
||||
$token = new GuestSessionToken();
|
||||
|
||||
if (array_key_exists('expires_at', $data)) {
|
||||
$token->setExpiresAt(new \DateTime($data['expires_at']));
|
||||
|
|
|
@ -42,11 +42,11 @@ class CertificationFactory extends AbstractFactory
|
|||
|
||||
$collection = new GenericCollection();
|
||||
|
||||
foreach($data as $country => $certifications) {
|
||||
foreach ($data as $country => $certifications) {
|
||||
$certification = new Certification();
|
||||
$certification->setCountry($country);
|
||||
|
||||
foreach($certifications as $countryCertification) {
|
||||
foreach ($certifications as $countryCertification) {
|
||||
$object = $this->create($countryCertification);
|
||||
|
||||
$certification->getCertifications()->add(null, $object);
|
||||
|
|
|
@ -53,7 +53,7 @@ class ChangesFactory extends AbstractFactory
|
|||
$data = $data['results'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
|
|
@ -55,15 +55,21 @@ class CollectionFactory extends AbstractFactory
|
|||
}
|
||||
|
||||
if (array_key_exists('backdrop_path', $data)) {
|
||||
$collection->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path'));
|
||||
$collection->setBackdropImage(
|
||||
$this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('images', $data)) {
|
||||
$collection->setImages($this->getImageFactory()->createCollectionFromMovie($data['images']));
|
||||
$collection->setImages(
|
||||
$this->getImageFactory()->createCollectionFromMovie($data['images'])
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('poster_path', $data)) {
|
||||
$collection->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
|
||||
$collection->setPosterImage(
|
||||
$this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->hydrate($collection, $data);
|
||||
|
@ -76,7 +82,7 @@ class CollectionFactory extends AbstractFactory
|
|||
{
|
||||
$collection = new GenericCollection();
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -90,6 +96,7 @@ class CollectionFactory extends AbstractFactory
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -108,6 +115,7 @@ class CollectionFactory extends AbstractFactory
|
|||
public function setMovieFactory($movieFactory)
|
||||
{
|
||||
$this->movieFactory = $movieFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class ChangeFactory extends AbstractFactory
|
|||
if (array_key_exists('items', $data)) {
|
||||
$items = new GenericCollection();
|
||||
|
||||
foreach($data['items'] as $item) {
|
||||
foreach ($data['items'] as $item) {
|
||||
$item = $this->createChangeItem($item);
|
||||
|
||||
$items->add(null, $item);
|
||||
|
@ -66,7 +66,7 @@ class ChangeFactory extends AbstractFactory
|
|||
$data = $data['changes'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
|
|
@ -21,13 +21,14 @@ use Tmdb\Model\Common\GenericCollection;
|
|||
* Class GenericCollectionFactory
|
||||
* @package Tmdb\Factory\Common
|
||||
*/
|
||||
class GenericCollectionFactory {
|
||||
class GenericCollectionFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
* @param $class
|
||||
* @return GenericCollection
|
||||
*/
|
||||
public function create(array $data = array(), $class)
|
||||
public function create(array $data, $class)
|
||||
{
|
||||
return $this->createCollection($data, $class);
|
||||
}
|
||||
|
@ -37,7 +38,7 @@ class GenericCollectionFactory {
|
|||
* @param $class
|
||||
* @return GenericCollection
|
||||
*/
|
||||
public function createCollection(array $data = array(), $class)
|
||||
public function createCollection(array $data, $class)
|
||||
{
|
||||
if (is_object($class)) {
|
||||
$class = get_class($class);
|
||||
|
@ -46,7 +47,7 @@ class GenericCollectionFactory {
|
|||
$collection = new GenericCollection();
|
||||
$objectHydrator = new ObjectHydrator();
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $objectHydrator->hydrate(new $class(), $item));
|
||||
}
|
||||
|
||||
|
|
72
modules/Tmdb/Factory/Common/VideoFactory.php
Normal file
72
modules/Tmdb/Factory/Common/VideoFactory.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Factory\Common;
|
||||
|
||||
use Tmdb\Factory\AbstractFactory;
|
||||
use Tmdb\Model\Collection\Videos;
|
||||
use Tmdb\Model\Common\Video;
|
||||
|
||||
/**
|
||||
* Class VideoFactory
|
||||
* @package Tmdb\Factory\Common
|
||||
*/
|
||||
class VideoFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create(array $data = array())
|
||||
{
|
||||
$videoType = $this->resolveVideoType($data);
|
||||
|
||||
return $this->hydrate($videoType, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createCollection(array $data = array())
|
||||
{
|
||||
$collection = new Videos();
|
||||
|
||||
if (array_key_exists('videos', $data)) {
|
||||
$data = $data['videos'];
|
||||
}
|
||||
|
||||
if (array_key_exists('results', $data)) {
|
||||
$data = $data['results'];
|
||||
}
|
||||
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
private function resolveVideoType($data)
|
||||
{
|
||||
if (array_key_exists('site', $data) && !empty($data['site'])) {
|
||||
$site = strtolower($data['site']);
|
||||
|
||||
switch ($site) {
|
||||
case 'youtube':
|
||||
return new Video\Youtube();
|
||||
break;
|
||||
default:
|
||||
return new Video();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,6 +62,7 @@ class CompanyFactory extends AbstractFactory
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ namespace Tmdb\Factory;
|
|||
|
||||
use Tmdb\Exception\NotImplementedException;
|
||||
use Tmdb\Model\Genre;
|
||||
use Tmdb\Model\Movie;
|
||||
use Tmdb\Model\Credits as Credits;
|
||||
|
||||
/**
|
||||
|
@ -85,7 +84,10 @@ class CreditsFactory extends AbstractFactory
|
|||
*/
|
||||
public function createCollection(array $data = array())
|
||||
{
|
||||
throw new NotImplementedException('Credits are usually obtained through the PeopleFactory, however we might add a shortcut for that here.');
|
||||
throw new NotImplementedException(
|
||||
'Credits are usually obtained through the PeopleFactory,
|
||||
however we might add a shortcut for that here.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,6 +97,7 @@ class CreditsFactory extends AbstractFactory
|
|||
public function setTvEpisodeFactory($tvEpisodeFactory)
|
||||
{
|
||||
$this->tvEpisodeFactory = $tvEpisodeFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -113,6 +116,7 @@ class CreditsFactory extends AbstractFactory
|
|||
public function setTvSeasonFactory($tvSeasonFactory)
|
||||
{
|
||||
$this->tvSeasonFactory = $tvSeasonFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -131,6 +135,7 @@ class CreditsFactory extends AbstractFactory
|
|||
public function setPeopleFactory($peopleFactory)
|
||||
{
|
||||
$this->peopleFactory = $peopleFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ class FindFactory extends AbstractFactory
|
|||
public function setMovieFactory($movieFactory)
|
||||
{
|
||||
$this->movieFactory = $movieFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -101,6 +102,7 @@ class FindFactory extends AbstractFactory
|
|||
public function setPeopleFactory($peopleFactory)
|
||||
{
|
||||
$this->peopleFactory = $peopleFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -119,6 +121,7 @@ class FindFactory extends AbstractFactory
|
|||
public function setTvFactory($tvFactory)
|
||||
{
|
||||
$this->tvFactory = $tvFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -129,6 +132,4 @@ class FindFactory extends AbstractFactory
|
|||
{
|
||||
return $this->tvFactory;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ namespace Tmdb\Factory;
|
|||
|
||||
use Tmdb\Model\Collection\Genres;
|
||||
use Tmdb\Model\Genre;
|
||||
use Tmdb\Model\Movie;
|
||||
|
||||
/**
|
||||
* Class GenreFactory
|
||||
|
@ -43,7 +42,7 @@ class GenreFactory extends AbstractFactory
|
|||
$data = $data['genres'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->addGenre($this->create($item));
|
||||
}
|
||||
|
||||
|
|
36
modules/Tmdb/Factory/GuestSessionFactory.php
Normal file
36
modules/Tmdb/Factory/GuestSessionFactory.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Factory;
|
||||
|
||||
/**
|
||||
* Currently a place-holder for future expansions
|
||||
*
|
||||
* Class GuestSessionFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
class GuestSessionFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create(array $data = array())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createCollection(array $data = array())
|
||||
{
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ class ImageFactory extends AbstractFactory
|
|||
*/
|
||||
public function resolveImageType($key = null)
|
||||
{
|
||||
switch($key) {
|
||||
switch ($key) {
|
||||
case 'poster':
|
||||
case 'posters':
|
||||
case 'poster_path':
|
||||
|
@ -110,7 +110,7 @@ class ImageFactory extends AbstractFactory
|
|||
{
|
||||
$collection = new Images();
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -127,14 +127,14 @@ class ImageFactory extends AbstractFactory
|
|||
{
|
||||
$collection = new Images();
|
||||
|
||||
foreach($data as $format => $formatCollection) {
|
||||
foreach ($data as $format => $formatCollection) {
|
||||
|
||||
if (!is_array($formatCollection)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($formatCollection as $item) {
|
||||
if (array_key_exists($format, Image::$_formats)) {
|
||||
foreach ($formatCollection as $item) {
|
||||
if (array_key_exists($format, Image::$formats)) {
|
||||
$item = $this->create($item, $format);
|
||||
|
||||
$collection->addImage($item);
|
||||
|
|
|
@ -40,7 +40,7 @@ class JobsFactory extends AbstractFactory
|
|||
$data = $data['jobs'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ namespace Tmdb\Factory;
|
|||
|
||||
use Tmdb\Model\Collection\Keywords;
|
||||
use Tmdb\Model\Keyword;
|
||||
use Tmdb\Model\Movie;
|
||||
|
||||
/**
|
||||
* Class KeywordFactory
|
||||
|
@ -43,7 +42,7 @@ class KeywordFactory extends AbstractFactory
|
|||
$data = $data['keywords'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->addKeyword($this->create($item));
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ use Tmdb\Factory\Lists\ListItemFactory;
|
|||
use Tmdb\Model\Common\GenericCollection;
|
||||
use Tmdb\Model\Genre;
|
||||
use Tmdb\Model\Lists;
|
||||
use Tmdb\Model\Movie;
|
||||
|
||||
/**
|
||||
* Class ListFactory
|
||||
|
@ -100,7 +99,7 @@ class ListFactory extends AbstractFactory
|
|||
{
|
||||
$collection = new GenericCollection();
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -114,6 +113,7 @@ class ListFactory extends AbstractFactory
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,7 @@ class ListFactory extends AbstractFactory
|
|||
public function setListItemFactory($listItemFactory)
|
||||
{
|
||||
$this->listItemFactory = $listItemFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,11 +44,15 @@ class ListItemFactory extends AbstractFactory
|
|||
|
||||
/** Images */
|
||||
if (array_key_exists('backdrop_path', $data)) {
|
||||
$listItem->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path'));
|
||||
$listItem->setBackdropImage(
|
||||
$this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('poster_path', $data)) {
|
||||
$listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
|
||||
$listItem->setPosterImage(
|
||||
$this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->hydrate($listItem, $data);
|
||||
|
@ -65,7 +69,7 @@ class ListItemFactory extends AbstractFactory
|
|||
$data = $data['items'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -79,6 +83,7 @@ class ListItemFactory extends AbstractFactory
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class AlternativeTitleFactory extends AbstractFactory
|
|||
{
|
||||
$collection = new GenericCollection();
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ class ListItemFactory extends AbstractFactory
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,15 @@
|
|||
namespace Tmdb\Factory;
|
||||
|
||||
use Tmdb\Factory\Common\ChangeFactory;
|
||||
use Tmdb\Factory\Common\VideoFactory;
|
||||
use Tmdb\Factory\Movie\ListItemFactory;
|
||||
use Tmdb\Factory\People\CastFactory;
|
||||
use Tmdb\Factory\People\CrewFactory;
|
||||
use Tmdb\Model\Common\Country;
|
||||
use Tmdb\Model\Common\GenericCollection;
|
||||
use Tmdb\Model\Common\Trailer\Youtube;
|
||||
use Tmdb\Model\Common\Translation;
|
||||
use Tmdb\Model\Company;
|
||||
use Tmdb\Model\Lists\Result;
|
||||
use Tmdb\Model\Movie;
|
||||
|
||||
|
@ -26,7 +29,8 @@ use Tmdb\Model\Movie;
|
|||
* Class MovieFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
class MovieFactory extends AbstractFactory {
|
||||
class MovieFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var People\CastFactory
|
||||
*/
|
||||
|
@ -67,6 +71,11 @@ class MovieFactory extends AbstractFactory {
|
|||
*/
|
||||
private $keywordFactory;
|
||||
|
||||
/**
|
||||
* @var Common\VideoFactory
|
||||
*/
|
||||
private $videoFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -80,6 +89,7 @@ class MovieFactory extends AbstractFactory {
|
|||
$this->reviewFactory = new ReviewFactory();
|
||||
$this->listItemFactory = new ListItemFactory();
|
||||
$this->keywordFactory = new KeywordFactory();
|
||||
$this->videoFactory = new VideoFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,14 +148,24 @@ class MovieFactory extends AbstractFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* @TODO actually implement more providers? ( Can't seem to find any quicktime related trailers anyways? ). For now KISS
|
||||
* @TODO actually implement more providers?
|
||||
* ( Can't seem to find any quicktime related trailers anyways? ). For now KISS
|
||||
*/
|
||||
if (array_key_exists('trailers', $data) && array_key_exists('youtube', $data['trailers'])) {
|
||||
$movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube()));
|
||||
}
|
||||
|
||||
if (array_key_exists('videos', $data)) {
|
||||
$movie->setVideos($this->getVideoFactory()->createCollection($data['videos']));
|
||||
}
|
||||
|
||||
if (array_key_exists('translations', $data) && array_key_exists('translations', $data['translations'])) {
|
||||
$movie->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation()));
|
||||
$movie->setTranslations(
|
||||
$this->createGenericCollection(
|
||||
$data['translations']['translations'],
|
||||
new Translation()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('similar_movies', $data)) {
|
||||
|
@ -164,6 +184,18 @@ class MovieFactory extends AbstractFactory {
|
|||
$movie->setChanges($this->getChangeFactory()->createCollection($data['changes']));
|
||||
}
|
||||
|
||||
if (array_key_exists('production_companies', $data)) {
|
||||
$movie->setProductionCompanies(
|
||||
$this->createGenericCollection($data['production_companies'], new Company())
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('production_countries', $data)) {
|
||||
$movie->setProductionCountries(
|
||||
$this->createGenericCollection($data['production_countries'], new Country())
|
||||
);
|
||||
}
|
||||
|
||||
return $this->hydrate($movie, $data);
|
||||
}
|
||||
|
||||
|
@ -178,7 +210,7 @@ class MovieFactory extends AbstractFactory {
|
|||
$data = $data['results'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -191,7 +223,8 @@ class MovieFactory extends AbstractFactory {
|
|||
* @param array $data
|
||||
* @return \Tmdb\Model\AbstractModel
|
||||
*/
|
||||
public function createResult(array $data = array()) {
|
||||
public function createResult(array $data = array())
|
||||
{
|
||||
return $this->hydrate(new Result(), $data);
|
||||
}
|
||||
|
||||
|
@ -201,7 +234,8 @@ class MovieFactory extends AbstractFactory {
|
|||
* @param array $data
|
||||
* @return \Tmdb\Model\AbstractModel
|
||||
*/
|
||||
public function createRating(array $data = array()) {
|
||||
public function createRating(array $data = array())
|
||||
{
|
||||
return $this->hydrate(new Movie\Rating(), $data);
|
||||
}
|
||||
|
||||
|
@ -231,6 +265,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setCastFactory($castFactory)
|
||||
{
|
||||
$this->castFactory = $castFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -249,6 +284,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setCrewFactory($crewFactory)
|
||||
{
|
||||
$this->crewFactory = $crewFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -267,6 +303,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setGenreFactory($genreFactory)
|
||||
{
|
||||
$this->genreFactory = $genreFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -285,6 +322,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -303,6 +341,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setChangeFactory($changeFactory)
|
||||
{
|
||||
$this->changeFactory = $changeFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -321,6 +360,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setReviewFactory($reviewFactory)
|
||||
{
|
||||
$this->reviewFactory = $reviewFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -339,6 +379,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setListItemFactory($listItemFactory)
|
||||
{
|
||||
$this->listItemFactory = $listItemFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -357,6 +398,7 @@ class MovieFactory extends AbstractFactory {
|
|||
public function setKeywordFactory($keywordFactory)
|
||||
{
|
||||
$this->keywordFactory = $keywordFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -367,4 +409,23 @@ class MovieFactory extends AbstractFactory {
|
|||
{
|
||||
return $this->keywordFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Tmdb\Factory\Common\VideoFactory $videoFactory
|
||||
* @return $this
|
||||
*/
|
||||
public function setVideoFactory($videoFactory)
|
||||
{
|
||||
$this->videoFactory = $videoFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tmdb\Factory\Common\VideoFactory
|
||||
*/
|
||||
public function getVideoFactory()
|
||||
{
|
||||
return $this->videoFactory;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ namespace Tmdb\Factory;
|
|||
|
||||
use Tmdb\Model\Common\GenericCollection;
|
||||
use Tmdb\Model\Network;
|
||||
use Tmdb\Model\Movie;
|
||||
|
||||
/**
|
||||
* Class NetworkFactory
|
||||
|
@ -43,7 +42,7 @@ class NetworkFactory extends AbstractFactory
|
|||
$data = $data['networks'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,11 @@ class CastFactory extends PeopleFactory
|
|||
|
||||
if (is_object($person)) {
|
||||
$class = get_class($person);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$class = '\Tmdb\Model\Person\CastMember';
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item, new $class()));
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,11 @@ class CrewFactory extends PeopleFactory
|
|||
|
||||
if (is_object($person)) {
|
||||
$class = get_class($person);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$class = '\Tmdb\Model\Person\CrewMember';
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item, new $class()));
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,8 @@ use Tmdb\Model\Person\CastMember;
|
|||
use Tmdb\Model\Person\CrewMember;
|
||||
use Tmdb\Model\Person;
|
||||
|
||||
/**
|
||||
* Class PeopleFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
class PeopleFactory extends AbstractFactory {
|
||||
class PeopleFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var ImageFactory
|
||||
*/
|
||||
|
@ -100,11 +97,12 @@ class PeopleFactory extends AbstractFactory {
|
|||
* @param array $data
|
||||
* @param Person $person
|
||||
*/
|
||||
protected function applyCredits(array $data = array(), Person $person) {
|
||||
protected function applyCredits(array $data, Person $person)
|
||||
{
|
||||
$hydrator = new ObjectHydrator();
|
||||
$types = array('movie_credits', 'tv_credits', 'combined_credits');
|
||||
|
||||
foreach($types as $type) {
|
||||
foreach ($types as $type) {
|
||||
if (array_key_exists($type, $data)) {
|
||||
$method = $hydrator->camelize(sprintf('get_%s', $type));
|
||||
|
||||
|
@ -114,8 +112,8 @@ class PeopleFactory extends AbstractFactory {
|
|||
new Person\MovieCredit()
|
||||
);
|
||||
|
||||
foreach($cast as $member) {
|
||||
$member->setPosterImage($member->getPosterPath());
|
||||
foreach ($cast as $member) {
|
||||
$member->setPosterImage($this->getPosterImageForCredit($member->getPosterPath()));
|
||||
}
|
||||
|
||||
$person->$method()->setCast($cast);
|
||||
|
@ -127,8 +125,8 @@ class PeopleFactory extends AbstractFactory {
|
|||
new Person\MovieCredit()
|
||||
);
|
||||
|
||||
foreach($crew as $member) {
|
||||
$member->setPosterImage($member->getPosterPath());
|
||||
foreach ($crew as $member) {
|
||||
$member->setPosterImage($this->getPosterImageForCredit($member->getPosterPath()));
|
||||
}
|
||||
|
||||
$person->$method()->setCrew($crew);
|
||||
|
@ -157,14 +155,14 @@ class PeopleFactory extends AbstractFactory {
|
|||
|
||||
if (is_object($person)) {
|
||||
$class = get_class($person);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$class = '\Tmdb\Model\Person';
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item, new $class()));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
@ -175,6 +173,7 @@ class PeopleFactory extends AbstractFactory {
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -193,6 +192,7 @@ class PeopleFactory extends AbstractFactory {
|
|||
public function setChangeFactory($changeFactory)
|
||||
{
|
||||
$this->changeFactory = $changeFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
56
modules/Tmdb/Factory/TimezoneFactory.php
Normal file
56
modules/Tmdb/Factory/TimezoneFactory.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Factory;
|
||||
|
||||
use Tmdb\Model\Collection\Timezones;
|
||||
use Tmdb\Model\Timezone;
|
||||
|
||||
/**
|
||||
* Class TimezoneFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
class TimezoneFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Timezone\CountryTimezone
|
||||
*/
|
||||
public function create(array $data = array())
|
||||
{
|
||||
return $this->hydrate(new Timezone\CountryTimezone(), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createCollection(array $data = array())
|
||||
{
|
||||
$collection = new Timezones();
|
||||
|
||||
foreach ($data as $foobar_data) {
|
||||
foreach ($foobar_data as $iso_3166_1 => $timezones) {
|
||||
$country = new Timezone\CountryTimezone();
|
||||
$country->setIso31661($iso_3166_1);
|
||||
|
||||
foreach ($timezones as $timezone) {
|
||||
$country->getTimezones()->add(null, $timezone);
|
||||
}
|
||||
|
||||
$collection->add(null, $country);
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
namespace Tmdb\Factory;
|
||||
|
||||
use Tmdb\Factory\Common\VideoFactory;
|
||||
use Tmdb\Factory\People\CastFactory;
|
||||
use Tmdb\Factory\People\CrewFactory;
|
||||
use Tmdb\Model\Common\GenericCollection;
|
||||
|
@ -24,7 +25,8 @@ use Tmdb\Model\Tv\Episode;
|
|||
* Class TvEpisodeFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
class TvEpisodeFactory extends AbstractFactory {
|
||||
class TvEpisodeFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var People\CastFactory
|
||||
*/
|
||||
|
@ -40,6 +42,11 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
*/
|
||||
private $imageFactory;
|
||||
|
||||
/**
|
||||
* @var Common\VideoFactory
|
||||
*/
|
||||
private $videoFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -48,6 +55,7 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
$this->castFactory = new CastFactory();
|
||||
$this->crewFactory = new CrewFactory();
|
||||
$this->imageFactory = new ImageFactory();
|
||||
$this->videoFactory = new VideoFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,16 +71,23 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
|
||||
if (array_key_exists('credits', $data)) {
|
||||
if (array_key_exists('cast', $data['credits'])) {
|
||||
$tvEpisode->getCredits()->setCast(
|
||||
$this->getCastFactory()->createCollection($data['credits']['cast'],
|
||||
new CastMember())
|
||||
$tvEpisode
|
||||
->getCredits()
|
||||
->setCast(
|
||||
$this->getCastFactory()
|
||||
->createCollection(
|
||||
$data['credits']['cast'],
|
||||
new CastMember()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('crew', $data['credits'])) {
|
||||
$tvEpisode->getCredits()->setCrew(
|
||||
$this->getCrewFactory()->createCollection($data['credits']['crew'],
|
||||
new CrewMember())
|
||||
$this->getCrewFactory()->createCollection(
|
||||
$data['credits']['crew'],
|
||||
new CrewMember()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +108,10 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
$tvEpisode->setStillImage($this->getImageFactory()->createFromPath($data['still_path'], 'still_path'));
|
||||
}
|
||||
|
||||
if (array_key_exists('videos', $data)) {
|
||||
$tvEpisode->setVideos($this->getVideoFactory()->createCollection($data['videos']));
|
||||
}
|
||||
|
||||
return $this->hydrate($tvEpisode, $data);
|
||||
}
|
||||
|
||||
|
@ -103,7 +122,7 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
{
|
||||
$collection = new GenericCollection();
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -117,6 +136,7 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
public function setCastFactory($castFactory)
|
||||
{
|
||||
$this->castFactory = $castFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -135,6 +155,7 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
public function setCrewFactory($crewFactory)
|
||||
{
|
||||
$this->crewFactory = $crewFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -153,6 +174,7 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -163,4 +185,23 @@ class TvEpisodeFactory extends AbstractFactory {
|
|||
{
|
||||
return $this->imageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Tmdb\Factory\Common\VideoFactory $videoFactory
|
||||
* @return $this
|
||||
*/
|
||||
public function setVideoFactory($videoFactory)
|
||||
{
|
||||
$this->videoFactory = $videoFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tmdb\Factory\Common\VideoFactory
|
||||
*/
|
||||
public function getVideoFactory()
|
||||
{
|
||||
return $this->videoFactory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
namespace Tmdb\Factory;
|
||||
|
||||
use Tmdb\Factory\Common\VideoFactory;
|
||||
use Tmdb\Factory\People\CastFactory;
|
||||
use Tmdb\Factory\People\CrewFactory;
|
||||
use Tmdb\Model\Common\GenericCollection;
|
||||
|
@ -25,7 +26,8 @@ use Tmdb\Model\Tv;
|
|||
* Class TvFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
class TvFactory extends AbstractFactory {
|
||||
class TvFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var People\CastFactory
|
||||
*/
|
||||
|
@ -56,6 +58,11 @@ class TvFactory extends AbstractFactory {
|
|||
*/
|
||||
private $networkFactory;
|
||||
|
||||
/**
|
||||
* @var Common\VideoFactory
|
||||
*/
|
||||
private $videoFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -67,6 +74,7 @@ class TvFactory extends AbstractFactory {
|
|||
$this->imageFactory = new ImageFactory();
|
||||
$this->tvSeasonFactory = new TvSeasonFactory();
|
||||
$this->networkFactory = new NetworkFactory();
|
||||
$this->videoFactory = new VideoFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,11 +92,21 @@ class TvFactory extends AbstractFactory {
|
|||
|
||||
if (array_key_exists('credits', $data)) {
|
||||
if (array_key_exists('cast', $data['credits'])) {
|
||||
$tvShow->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'], new CastMember()));
|
||||
$tvShow->getCredits()->setCast(
|
||||
$this->getCastFactory()->createCollection(
|
||||
$data['credits']['cast'],
|
||||
new CastMember()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('crew', $data['credits'])) {
|
||||
$tvShow->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'], new CrewMember()));
|
||||
$tvShow->getCredits()->setCrew(
|
||||
$this->getCrewFactory()->createCollection(
|
||||
$data['credits']['crew'],
|
||||
new CrewMember()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,20 +124,35 @@ class TvFactory extends AbstractFactory {
|
|||
|
||||
/** Images */
|
||||
if (array_key_exists('images', $data)) {
|
||||
$tvShow->setImages($this->getImageFactory()->createCollectionFromTv($data['images']));
|
||||
$tvShow->setImages(
|
||||
$this->getImageFactory()->createCollectionFromTv($data['images'])
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('backdrop_path', $data)) {
|
||||
$tvShow->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path'));
|
||||
$tvShow->setBackdropImage(
|
||||
$this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('poster_path', $data)) {
|
||||
$tvShow->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
|
||||
$tvShow->setPosterImage(
|
||||
$this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')
|
||||
);
|
||||
}
|
||||
|
||||
/** Translations */
|
||||
if (array_key_exists('translations', $data) && null !== $data['translations']) {
|
||||
$tvShow->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation()));
|
||||
|
||||
if (array_key_exists('translations', $data['translations'])) {
|
||||
$translations = $data['translations']['translations'];
|
||||
} else {
|
||||
$translations = $data['translations'];
|
||||
}
|
||||
|
||||
$tvShow->setTranslations(
|
||||
$this->createGenericCollection($translations, new Translation())
|
||||
);
|
||||
}
|
||||
|
||||
/** Seasons */
|
||||
|
@ -132,6 +165,10 @@ class TvFactory extends AbstractFactory {
|
|||
$tvShow->setNetworks($this->getNetworkFactory()->createCollection($data['networks']));
|
||||
}
|
||||
|
||||
if (array_key_exists('videos', $data)) {
|
||||
$tvShow->setVideos($this->getVideoFactory()->createCollection($data['videos']));
|
||||
}
|
||||
|
||||
return $this->hydrate($tvShow, $data);
|
||||
}
|
||||
|
||||
|
@ -146,7 +183,7 @@ class TvFactory extends AbstractFactory {
|
|||
$data = $data['results'];
|
||||
}
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -160,6 +197,7 @@ class TvFactory extends AbstractFactory {
|
|||
public function setCastFactory($castFactory)
|
||||
{
|
||||
$this->castFactory = $castFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -178,6 +216,7 @@ class TvFactory extends AbstractFactory {
|
|||
public function setCrewFactory($crewFactory)
|
||||
{
|
||||
$this->crewFactory = $crewFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -196,6 +235,7 @@ class TvFactory extends AbstractFactory {
|
|||
public function setGenreFactory($genreFactory)
|
||||
{
|
||||
$this->genreFactory = $genreFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -214,6 +254,7 @@ class TvFactory extends AbstractFactory {
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -232,6 +273,7 @@ class TvFactory extends AbstractFactory {
|
|||
public function setTvSeasonFactory($tvSeasonFactory)
|
||||
{
|
||||
$this->tvSeasonFactory = $tvSeasonFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -250,6 +292,7 @@ class TvFactory extends AbstractFactory {
|
|||
public function setNetworkFactory($networkFactory)
|
||||
{
|
||||
$this->networkFactory = $networkFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -260,4 +303,23 @@ class TvFactory extends AbstractFactory {
|
|||
{
|
||||
return $this->networkFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Tmdb\Factory\Common\VideoFactory $videoFactory
|
||||
* @return $this
|
||||
*/
|
||||
public function setVideoFactory($videoFactory)
|
||||
{
|
||||
$this->videoFactory = $videoFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tmdb\Factory\Common\VideoFactory
|
||||
*/
|
||||
public function getVideoFactory()
|
||||
{
|
||||
return $this->videoFactory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
namespace Tmdb\Factory;
|
||||
|
||||
use Tmdb\Factory\Common\VideoFactory;
|
||||
use Tmdb\Factory\People\CastFactory;
|
||||
use Tmdb\Factory\People\CrewFactory;
|
||||
use Tmdb\Model\Common\GenericCollection;
|
||||
|
@ -24,7 +25,8 @@ use Tmdb\Model\Tv\Season;
|
|||
* Class TvSeasonFactory
|
||||
* @package Tmdb\Factory
|
||||
*/
|
||||
class TvSeasonFactory extends AbstractFactory {
|
||||
class TvSeasonFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var People\CastFactory
|
||||
*/
|
||||
|
@ -45,6 +47,11 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
*/
|
||||
private $tvEpisodeFactory;
|
||||
|
||||
/**
|
||||
* @var Common\VideoFactory
|
||||
*/
|
||||
private $videoFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -54,6 +61,7 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
$this->crewFactory = new CrewFactory();
|
||||
$this->imageFactory = new ImageFactory();
|
||||
$this->tvEpisodeFactory = new TvEpisodeFactory();
|
||||
$this->videoFactory = new VideoFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,11 +77,21 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
|
||||
if (array_key_exists('credits', $data)) {
|
||||
if (array_key_exists('cast', $data['credits'])) {
|
||||
$tvSeason->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'], new CastMember()));
|
||||
$tvSeason->getCredits()->setCast(
|
||||
$this->getCastFactory()->createCollection(
|
||||
$data['credits']['cast'],
|
||||
new CastMember()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('crew', $data['credits'])) {
|
||||
$tvSeason->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'], new CrewMember()));
|
||||
$tvSeason->getCredits()->setCrew(
|
||||
$this->getCrewFactory()->createCollection(
|
||||
$data['credits']['crew'],
|
||||
new CrewMember()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +116,10 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
$tvSeason->setEpisodes($this->getTvEpisodeFactory()->createCollection($data['episodes']));
|
||||
}
|
||||
|
||||
if (array_key_exists('videos', $data)) {
|
||||
$tvSeason->setVideos($this->getVideoFactory()->createCollection($data['videos']));
|
||||
}
|
||||
|
||||
return $this->hydrate($tvSeason, $data);
|
||||
}
|
||||
|
||||
|
@ -108,7 +130,7 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
{
|
||||
$collection = new GenericCollection();
|
||||
|
||||
foreach($data as $item) {
|
||||
foreach ($data as $item) {
|
||||
$collection->add(null, $this->create($item));
|
||||
}
|
||||
|
||||
|
@ -122,6 +144,7 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
public function setCastFactory($castFactory)
|
||||
{
|
||||
$this->castFactory = $castFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -140,6 +163,7 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
public function setCrewFactory($crewFactory)
|
||||
{
|
||||
$this->crewFactory = $crewFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -158,6 +182,7 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
public function setImageFactory($imageFactory)
|
||||
{
|
||||
$this->imageFactory = $imageFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -176,6 +201,7 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
public function setTvEpisodeFactory($tvEpisodeFactory)
|
||||
{
|
||||
$this->tvEpisodeFactory = $tvEpisodeFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -186,4 +212,23 @@ class TvSeasonFactory extends AbstractFactory {
|
|||
{
|
||||
return $this->tvEpisodeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Tmdb\Factory\Common\VideoFactory $videoFactory
|
||||
* @return $this
|
||||
*/
|
||||
public function setVideoFactory($videoFactory)
|
||||
{
|
||||
$this->videoFactory = $videoFactory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tmdb\Factory\Common\VideoFactory
|
||||
*/
|
||||
public function getVideoFactory()
|
||||
{
|
||||
return $this->videoFactory;
|
||||
}
|
||||
}
|
||||
|
|
21
modules/Tmdb/GuestSessionToken.php
Normal file
21
modules/Tmdb/GuestSessionToken.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb;
|
||||
|
||||
/**
|
||||
* Class GuestSessionToken
|
||||
* @package Tmdb
|
||||
*/
|
||||
class GuestSessionToken extends SessionToken
|
||||
{
|
||||
}
|
|
@ -19,8 +19,8 @@ use Tmdb\Model\Image;
|
|||
* Class ImageHelper
|
||||
* @package Tmdb\Helper
|
||||
*/
|
||||
class ImageHelper {
|
||||
|
||||
class ImageHelper
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct(Configuration $config)
|
||||
|
@ -41,26 +41,29 @@ class ImageHelper {
|
|||
/**
|
||||
* Get the url for the image resource
|
||||
*
|
||||
* @param Image $image
|
||||
* @param Image|string $image Either an instance of Image or the file_path
|
||||
* @param string $size
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(Image $image, $size = 'original') {
|
||||
public function getUrl($image, $size = 'original')
|
||||
{
|
||||
$config = $this->getImageConfiguration();
|
||||
|
||||
return $config['base_url'] . $size . $image->getFilePath();
|
||||
return $config['base_url'] . $size . $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an img html tag for the image in the specified size
|
||||
*
|
||||
* @param Image $image
|
||||
* @param Image|string $image Either an instance of Image or the file_path
|
||||
* @param string $size
|
||||
* @param int|null $width
|
||||
* @param int|null $height
|
||||
* @return string
|
||||
*/
|
||||
public function getHtml(Image $image, $size = 'original', $width = null, $height = null) {
|
||||
public function getHtml($image, $size = 'original', $width = null, $height = null)
|
||||
{
|
||||
if ($image instanceof Image) {
|
||||
if (null == $image->getFilePath()) {
|
||||
return '';
|
||||
}
|
||||
|
@ -82,6 +85,7 @@ class ImageHelper {
|
|||
if (null == $height) {
|
||||
$height = $image->getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<img src="%s" width="%s" height="%s" />',
|
||||
|
|
|
@ -17,13 +17,26 @@ use Guzzle\Http\Message\Request;
|
|||
use Guzzle\Http\Message\RequestInterface;
|
||||
use Guzzle\Http\Message\Response;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Guzzle\Cache\DoctrineCacheAdapter;
|
||||
use Guzzle\Common\Exception\RuntimeException;
|
||||
use Guzzle\Log\MessageFormatter;
|
||||
use Guzzle\Log\PsrLogAdapter;
|
||||
use Guzzle\Plugin\Backoff\BackoffPlugin;
|
||||
use Guzzle\Plugin\Cache\CachePlugin;
|
||||
use Guzzle\Plugin\Cache\DefaultCacheStorage;
|
||||
use Guzzle\Plugin\Log\LogPlugin;
|
||||
use Tmdb\ApiToken;
|
||||
use Tmdb\Exception\TmdbApiException;
|
||||
use Tmdb\HttpClient\Plugin\AcceptJsonHeaderPlugin;
|
||||
use Tmdb\HttpClient\Plugin\ApiTokenPlugin;
|
||||
use Tmdb\HttpClient\Plugin\SessionTokenPlugin;
|
||||
use Tmdb\SessionToken;
|
||||
|
||||
/**
|
||||
* Class HttpClient
|
||||
* @package Tmdb\HttpClient
|
||||
*/
|
||||
class HttpClient
|
||||
implements HttpClientInterface
|
||||
class HttpClient implements HttpClientInterface
|
||||
{
|
||||
/**
|
||||
* @var \Guzzle\Http\ClientInterface
|
||||
|
@ -55,6 +68,8 @@ class HttpClient
|
|||
$this->base_url = $baseUrl;
|
||||
$this->options = $options;
|
||||
$this->client = $client;
|
||||
|
||||
$this->registerGuzzleSubscribers($options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,11 +186,9 @@ class HttpClient
|
|||
|
||||
try {
|
||||
$response = $request->send();
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
// @TODO catch any API errors / timeouts / other specific information from Guzzle?
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getResponse()->json();
|
||||
throw new TmdbApiException($error['status_message'], $error['status_code']);
|
||||
}
|
||||
|
||||
$this->lastRequest = $request;
|
||||
|
@ -191,6 +204,7 @@ class HttpClient
|
|||
public function setClient($client)
|
||||
{
|
||||
$this->client = $client;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -201,4 +215,166 @@ class HttpClient
|
|||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Guzzle\Http\Message\Request $lastRequest
|
||||
* @return $this
|
||||
*/
|
||||
public function setLastRequest($lastRequest)
|
||||
{
|
||||
$this->lastRequest = $lastRequest;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Guzzle\Http\Message\Request
|
||||
*/
|
||||
public function getLastRequest()
|
||||
{
|
||||
return $this->lastRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Guzzle\Http\Message\Response $lastResponse
|
||||
* @return $this
|
||||
*/
|
||||
public function setLastResponse($lastResponse)
|
||||
{
|
||||
$this->lastResponse = $lastResponse;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Guzzle\Http\Message\Response
|
||||
*/
|
||||
public function getLastResponse()
|
||||
{
|
||||
return $this->lastResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current base url
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return $this->getClient()->getBaseUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base url secure / insecure
|
||||
*
|
||||
* @param $url
|
||||
* @return ClientInterface
|
||||
*/
|
||||
public function setBaseUrl($url)
|
||||
{
|
||||
return $this->getClient()->setBaseUrl($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default subscribers for Guzzle
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function registerGuzzleSubscribers(array $options)
|
||||
{
|
||||
$acceptJsonHeaderPlugin = new AcceptJsonHeaderPlugin();
|
||||
$this->addSubscriber($acceptJsonHeaderPlugin);
|
||||
|
||||
$backoffPlugin = BackoffPlugin::getExponentialBackoff(5);
|
||||
$this->addSubscriber($backoffPlugin);
|
||||
|
||||
if (array_key_exists('token', $options) && $options['token'] instanceof ApiToken) {
|
||||
$apiTokenPlugin = new ApiTokenPlugin($options['token']);
|
||||
$this->addSubscriber($apiTokenPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an subscriber to enable caching.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @throws \Guzzle\Common\Exception\RuntimeException
|
||||
*/
|
||||
public function setCaching(array $parameters = array())
|
||||
{
|
||||
if (!class_exists('Doctrine\Common\Cache\FilesystemCache')) {
|
||||
//@codeCoverageIgnoreStart
|
||||
throw new RuntimeException(
|
||||
'Could not find the doctrine cache library,
|
||||
have you added doctrine-cache to your composer.json?'
|
||||
);
|
||||
//@codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$cachePlugin = new CachePlugin(array(
|
||||
'storage' => new DefaultCacheStorage(
|
||||
new DoctrineCacheAdapter(
|
||||
new \Doctrine\Common\Cache\FilesystemCache($parameters['cache_path'])
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addSubscriber($cachePlugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an subscriber to enable logging.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @throws \Guzzle\Common\Exception\RuntimeException
|
||||
*/
|
||||
public function setLogging(array $parameters = array())
|
||||
{
|
||||
if (!array_key_exists('logger', $parameters) && !class_exists('\Monolog\Logger')) {
|
||||
//@codeCoverageIgnoreStart
|
||||
throw new RuntimeException(
|
||||
'Could not find any logger set and the monolog logger library was not found
|
||||
to provide a default, you have to set a custom logger on the client or
|
||||
have you forgot adding monolog to your composer.json?'
|
||||
);
|
||||
//@codeCoverageIgnoreEnd
|
||||
} else {
|
||||
$logger = new \Monolog\Logger('php-tmdb-api');
|
||||
$logger->pushHandler(
|
||||
new \Monolog\Handler\StreamHandler(
|
||||
$parameters['log_path'],
|
||||
\Monolog\Logger::DEBUG
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('logger', $parameters)) {
|
||||
$logger = $parameters['logger'];
|
||||
}
|
||||
|
||||
$logPlugin = null;
|
||||
|
||||
if ($logger instanceof \Psr\Log\LoggerInterface) {
|
||||
$logPlugin = new LogPlugin(
|
||||
new PsrLogAdapter($logger),
|
||||
MessageFormatter::SHORT_FORMAT
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== $logPlugin) {
|
||||
$this->addSubscriber($logPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an subscriber to append the session_token to the query parameters.
|
||||
*
|
||||
* @param SessionToken $sessionToken
|
||||
*/
|
||||
public function setSessionToken(SessionToken $sessionToken)
|
||||
{
|
||||
$sessionTokenPlugin = new SessionTokenPlugin($sessionToken);
|
||||
$this->addSubscriber($sessionTokenPlugin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Tmdb\HttpClient;
|
|||
|
||||
use Guzzle\Http\Message\RequestInterface;
|
||||
use Guzzle\Http\Message\Response;
|
||||
use Tmdb\SessionToken;
|
||||
|
||||
/**
|
||||
* Interface HttpClientInterface
|
||||
|
@ -100,4 +101,8 @@ interface HttpClientInterface
|
|||
*/
|
||||
public function request(RequestInterface $request);
|
||||
|
||||
public function getBaseUrl();
|
||||
public function setBaseUrl($url);
|
||||
|
||||
public function setSessionToken(SessionToken $sessionToken);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Tmdb\HttpClient\Plugin;
|
|||
|
||||
use Guzzle\Common\Event;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Tmdb\GuestSessionToken;
|
||||
use Tmdb\SessionToken;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +42,11 @@ class SessionTokenPlugin implements EventSubscriberInterface
|
|||
{
|
||||
$url = $event['request']->getUrl(true);
|
||||
|
||||
if ($this->token instanceof GuestSessionToken) {
|
||||
$url->getQuery()->set('guest_session_id', $this->token->getToken());
|
||||
} else {
|
||||
$url->getQuery()->set('session_id', $this->token->getToken());
|
||||
}
|
||||
|
||||
$event['request']->setUrl($url);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@ namespace Tmdb\Model;
|
|||
* Class AbstractModel
|
||||
* @package Tmdb\Model
|
||||
*/
|
||||
class AbstractModel {
|
||||
class AbstractModel
|
||||
{
|
||||
/**
|
||||
* List of properties to populate by the ObjectHydrator
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $_properties = array();
|
||||
|
||||
public static $properties = array();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ namespace Tmdb\Model;
|
|||
* Class Account
|
||||
* @package Tmdb\Model
|
||||
*/
|
||||
class Account extends AbstractModel {
|
||||
class Account extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
|
@ -50,7 +51,7 @@ class Account extends AbstractModel {
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $_properties = array(
|
||||
public static $properties = array(
|
||||
'id',
|
||||
'include_adult',
|
||||
'iso_3166_1',
|
||||
|
@ -66,6 +67,7 @@ class Account extends AbstractModel {
|
|||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -84,6 +86,7 @@ class Account extends AbstractModel {
|
|||
public function setIncludeAdult($includeAdult)
|
||||
{
|
||||
$this->includeAdult = $includeAdult;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -102,6 +105,7 @@ class Account extends AbstractModel {
|
|||
public function setIso31661($iso31661)
|
||||
{
|
||||
$this->iso31661 = $iso31661;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -120,6 +124,7 @@ class Account extends AbstractModel {
|
|||
public function setIso6391($iso6391)
|
||||
{
|
||||
$this->iso6391 = $iso6391;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -138,6 +143,7 @@ class Account extends AbstractModel {
|
|||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -156,6 +162,7 @@ class Account extends AbstractModel {
|
|||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -166,6 +173,4 @@ class Account extends AbstractModel {
|
|||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ use Tmdb\Model\Image\PosterImage;
|
|||
* Class ListItem
|
||||
* @package Tmdb\Model\Account
|
||||
*/
|
||||
class ListItem extends AbstractModel {
|
||||
class ListItem extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -68,7 +69,7 @@ class ListItem extends AbstractModel {
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $_properties = array(
|
||||
public static $properties = array(
|
||||
'description',
|
||||
'favorite_count',
|
||||
'id',
|
||||
|
@ -86,6 +87,7 @@ class ListItem extends AbstractModel {
|
|||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -104,6 +106,7 @@ class ListItem extends AbstractModel {
|
|||
public function setFavoriteCount($favoriteCount)
|
||||
{
|
||||
$this->favoriteCount = $favoriteCount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -122,6 +125,7 @@ class ListItem extends AbstractModel {
|
|||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -140,6 +144,7 @@ class ListItem extends AbstractModel {
|
|||
public function setIso6391($iso6391)
|
||||
{
|
||||
$this->iso6391 = $iso6391;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -158,6 +163,7 @@ class ListItem extends AbstractModel {
|
|||
public function setItemCount($itemCount)
|
||||
{
|
||||
$this->itemCount = $itemCount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -176,6 +182,7 @@ class ListItem extends AbstractModel {
|
|||
public function setListType($listType)
|
||||
{
|
||||
$this->listType = $listType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -194,6 +201,7 @@ class ListItem extends AbstractModel {
|
|||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -212,6 +220,7 @@ class ListItem extends AbstractModel {
|
|||
public function setPosterImage($posterImage)
|
||||
{
|
||||
$this->posterImage = $posterImage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -230,6 +239,7 @@ class ListItem extends AbstractModel {
|
|||
public function setPosterPath($posterPath)
|
||||
{
|
||||
$this->posterPath = $posterPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ use Tmdb\Model\Common\GenericCollection;
|
|||
* Class Certification
|
||||
* @package Tmdb\Model
|
||||
*/
|
||||
class Certification extends AbstractModel {
|
||||
|
||||
class Certification extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -30,7 +30,7 @@ class Certification extends AbstractModel {
|
|||
*/
|
||||
private $certifications;
|
||||
|
||||
public static $_properties = array(
|
||||
public static $properties = array(
|
||||
'country',
|
||||
);
|
||||
|
||||
|
@ -46,6 +46,7 @@ class Certification extends AbstractModel {
|
|||
public function setCertifications($certifications)
|
||||
{
|
||||
$this->certifications = $certifications;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -64,6 +65,7 @@ class Certification extends AbstractModel {
|
|||
public function setCountry($country)
|
||||
{
|
||||
$this->country = $country;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ use Tmdb\Model\AbstractModel;
|
|||
* Class CountryCertification
|
||||
* @package Tmdb\Model\Certification
|
||||
*/
|
||||
class CountryCertification extends AbstractModel {
|
||||
|
||||
class CountryCertification extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -35,7 +35,7 @@ class CountryCertification extends AbstractModel {
|
|||
*/
|
||||
private $order;
|
||||
|
||||
public static $_properties = array(
|
||||
public static $properties = array(
|
||||
'certification',
|
||||
'meaning',
|
||||
'order',
|
||||
|
@ -48,6 +48,7 @@ class CountryCertification extends AbstractModel {
|
|||
public function setCertification($certification)
|
||||
{
|
||||
$this->certification = $certification;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -66,6 +67,7 @@ class CountryCertification extends AbstractModel {
|
|||
public function setMeaning($meaning)
|
||||
{
|
||||
$this->meaning = $meaning;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -84,6 +86,7 @@ class CountryCertification extends AbstractModel {
|
|||
public function setOrder($order)
|
||||
{
|
||||
$this->order = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -94,6 +97,4 @@ class CountryCertification extends AbstractModel {
|
|||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ namespace Tmdb\Model;
|
|||
* Class Change
|
||||
* @package Tmdb\Model
|
||||
*/
|
||||
class Change extends AbstractModel {
|
||||
class Change extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
|
@ -30,7 +31,7 @@ class Change extends AbstractModel {
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $_properties = array(
|
||||
public static $properties = array(
|
||||
'id',
|
||||
'adult'
|
||||
);
|
||||
|
@ -42,6 +43,7 @@ class Change extends AbstractModel {
|
|||
public function setAdult($adult)
|
||||
{
|
||||
$this->adult = (bool) $adult;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -60,6 +62,7 @@ class Change extends AbstractModel {
|
|||
public function setId($id)
|
||||
{
|
||||
$this->id = (int) $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ use Tmdb\Model\Image\PosterImage;
|
|||
* Class Collection
|
||||
* @package Tmdb\Model
|
||||
*/
|
||||
class Collection extends AbstractModel {
|
||||
|
||||
class Collection extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -68,7 +68,7 @@ class Collection extends AbstractModel {
|
|||
*/
|
||||
private $poster;
|
||||
|
||||
public static $_properties = array(
|
||||
public static $properties = array(
|
||||
'backdrop_path',
|
||||
'id',
|
||||
'name',
|
||||
|
@ -89,6 +89,7 @@ class Collection extends AbstractModel {
|
|||
public function setBackdropImage(BackdropImage $backdrop)
|
||||
{
|
||||
$this->backdrop = $backdrop;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -107,6 +108,7 @@ class Collection extends AbstractModel {
|
|||
public function setBackdropPath($backdropPath)
|
||||
{
|
||||
$this->backdropPath = $backdropPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -125,6 +127,7 @@ class Collection extends AbstractModel {
|
|||
public function setId($id)
|
||||
{
|
||||
$this->id = (int) $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -143,6 +146,7 @@ class Collection extends AbstractModel {
|
|||
public function setImages(Images $images)
|
||||
{
|
||||
$this->images = $images;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -161,6 +165,7 @@ class Collection extends AbstractModel {
|
|||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -179,6 +184,7 @@ class Collection extends AbstractModel {
|
|||
public function setOverview($overview)
|
||||
{
|
||||
$this->overview = $overview;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -197,6 +203,7 @@ class Collection extends AbstractModel {
|
|||
public function setParts($parts)
|
||||
{
|
||||
$this->parts = $parts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -215,6 +222,7 @@ class Collection extends AbstractModel {
|
|||
public function setPosterImage(PosterImage $poster)
|
||||
{
|
||||
$this->poster = $poster;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -233,6 +241,7 @@ class Collection extends AbstractModel {
|
|||
public function setPosterPath($posterPath)
|
||||
{
|
||||
$this->posterPath = $posterPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue