(.*)(.*)', $xml, $regs); $this->code = intval($regs[1]); $this->message = $regs[2]; } } class AnyClip { private $token; private $tokenPath; private $apikey; public function __construct($apikey) { $this->apikey = $apikey; $this->tokenPath = md5($apikey).".token"; $this->token = @file_get_contents($this->tokenPath); if ($this->token == "") $this->token = false; } private function request() { $args = func_get_args(); if ($args[0] == "authenticate") $url = "http://api.anyclip.com/ac_auth/v1/json/authenticate/$args[1]/"; elseif (func_num_args() >= 1) { if ($this->token === false) $this->authenticate(); $url = "http://api.anyclip.com/ac_api/v1/{$this->token}/json/$args[0]/"; for ($i = 1; $i < func_num_args(); $i++) $url .= urlencode(utf8_encode($args[$i]))."/"; //The API says to encode arguments as utf-8... } else return null; $response = @file_get_contents($url); if($response == "" || substr($response, 0, 6) == "code == 1001) { $this->authenticate(); return call_user_func_array(array(&$this, 'request'), $args); } return $error; } return json_decode($response); } private function authenticate() { $this->token = $this->request("authenticate", $this->apikey)->Token; @file_put_contents($this->tokenPath, $this->token); if ($this->token == "") $this->token = false; } public function tagTypes($start = 0, $max = 20) { return $this->request("tagtypes", $start, $max); } public function tags($start = 0, $max = 20) { return $this->request("tags", $start, $max); } public function studios() { return $this->request("studios"); } public function genres() { return $this->request("genres"); } public function castTypes() { return $this->request("castTypes"); } public function titleTypes() { return $this->request("titleTypes"); } public function clipsForCast($castCode, $start = 0, $max = 20) { return $this->request("cast", $castCode, "clips", $start, $max); } public function castForTitle($titleCode, $start = 0, $max = 20) { return $this->request("title", $titleCode, "cast", $start, $max); } public function titlesForCast($castCode, $start = 0, $max = 20) { return $this->request("cast", $castCode, "titles", $start, $max); } public function tagsForClip($clipCode, $start = 0, $max = 20) { return $this->request("clip", $clipCode, "tags", $start, $max); } public function clipsForTagType($tagType, $start = 0, $max = 20) { return $this->request("clips", "tagType", $tagType, $start, $max); } public function clipsForTag($tag, $start = 0, $max = 20) { return $this->request("clips", "tag", $tag, $start, $max); } public function titlesForTitleType($titleTypeID, $start = 0, $max = 20) { return $this->request("titles", "titleType", $titleTypeID, $start, $max); } public function titles($start = 0, $max = 20) { return $this->request("titles", $start, $max); } public function title($titleCode) { return $this->request("title", $titleCode); } public function titlesStartWith($startsWith, $start = 0, $max = 20) { return $this->request("titles", "name", $start, $max); } public function titlesForGenre($genreID, $start = 0, $max = 20) { return $this->request("titles", "genre", $genreID, $start, $max); } public function clip($clipCode) { return $this->request("clip", $clipCode); } public function clipsForTitle($titleCode, $start = 0, $max = 20) { return $this->request("title", $titleCode, "clips", $start, $max); } public function clipsForTitleType($titleTypeID, $start = 0, $max = 20) { return $this->request("titles", $titleTypeID, "clips", $start, $max); } public function searchTitles($titleQuery, $start = 0, $max = 20) { return $this->request("titles", "search", $titleQuery, $start, $max); } public function searchCasts($castQuery, $start = 0, $max = 20) { return $this->request("cast", "search", $castQuery, $start, $max); } public function searchClips($query, $start = 0, $max = 20) { return $this->request("search", $query, $start, $max); } } ?>