Пример #1
0
 public function testGetById()
 {
     $_ = $this;
     $AmazonSearch = new AmazonSearch();
     CmdLibs::bannerBig('ItemLookup Books', false);
     $conditions = ['SearchIndex' => 'Books', 'IdType' => 'ISBN', 'ResponseGroup' => 'ItemIds,ItemAttributes,SalesRank,Images', 'ItemId' => '9784774174099'];
     $result = $AmazonSearch->getById($conditions);
     foreach ($result as $item) {
         echo $item['Title'] . "\n";
     }
     $this->assertTrue(is_array($result));
     $this->assertNotEquals(0, count($result));
 }
Пример #2
0
 /**
  * gather_arts
  * Returns arts for what we're passed in.
  */
 public function gather_arts($type, $options = array(), $limit = 5)
 {
     $images = array();
     $final_results = array();
     $possible_keys = array('LargeImage', 'MediumImage', 'SmallImage');
     $mediaType = $type == 'album' || $type == 'artist' ? 'Music' : 'Video';
     // Prevent the script from timing out
     set_time_limit(0);
     // Create the Search Object
     $amazon = new AmazonSearch($this->amazon_developer_public_key, $this->amazon_developer_private_api_key, $this->amazon_developer_associate_tag, $this->amazon_base_url);
     if (AmpConfig::get('proxy_host') && 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($this->amazon_max_results_pages, $amazon->_default_results_pages);
     // while we have pages to search
     do {
         $raw_results = $amazon->search(array('artist' => '', 'album' => '', 'keywords' => $options['keyword']), $mediaType);
         $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 " . $options['keyword'] . ", results: " . count($final_results), 5);
     /* 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
         if (!empty($key)) {
             // 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;
             $data['title'] = $this->name;
             $images[] = $data;
             if (!empty($limit)) {
                 if (count($images) >= $limit) {
                     return $images;
                 }
             }
         }
     }
     // if we've got something
     return $images;
 }
Пример #3
0
 public static function getDefaultObject()
 {
     $o = parent::getDefaultObject();
     $o->artist = '';
     $o->label = '';
     $o->release_date = '';
     $o->image_medium = array('url' => Amazon::$default_image_url, 'width' => Amazon::$default_image_width, 'height' => Amazon::$default_image_height);
     $o->image_large = array('url' => Amazon::$default_image_url, 'width' => Amazon::$default_image_width, 'height' => Amazon::$default_image_height);
     return $o;
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
                $this->objMyAssets->Publisher = $arrParameter[8];
                $this->objMyAssets->Isbn = $arrParameter[10];
                break;
            case 'DVD':
                //Fill MyAssets
                $this->objMyAssets->Actor = $arrParameter[5];
                $this->objMyAssets->Director = $arrParameter[6];
                $this->objMyAssets->RunningTime = $arrParameter[7];
                break;
            case 'Music':
                //Fill MyAssets
                $this->objMyAssets->Artist = $arrParameter[5];
                $this->objMyAssets->Label = $arrParameter[6];
                $this->objMyAssets->NumberOfDiscs = $arrParameter[7];
                break;
        }
        $this->objMyAssets->Owner = $_SESSION['User'];
        $this->objMyAssets->Save();
        QApplication::DisplayAlert('"' . $this->objMyAssets->Title . '"' . ' has been added to your library');
    }
    protected function MyLibrary_Click()
    {
        QApplication::Redirect('MyLibrary.php');
    }
    protected function Home_Click()
    {
        QApplication::Redirect('index.php');
    }
}
AmazonSearch::Run('AmazonSearch');
Пример #6
0
        $this->total_pages = (int) $xml->Items->TotalPages;
        $this->total_results = (int) $xml->Items->TotalResults;
        return true;
    }
}
include "config.inc.php";
$query = @$_GET['keywords'];
$page = @$_GET['page'];
if (!$page) {
    $page = 1;
}
$output = @$_GET['output'];
if ($output != 'rdf') {
    $output = 'html';
}
$service = new AmazonSearch($query, $page);
$service->execute();
if ($output == 'rdf') {
    include RDFAPI_INCLUDE_DIR . "RdfAPI.php";
    $model = ModelFactory::getDefaultModel();
    define("SEARCH_NS", "urn:x-search:");
    $rdf_type = new Resource(RDF_NAMESPACE_URI . "type");
    $rdfs_label = new Resource(RDF_SCHEMA_URI . "label");
    $dc_creator = new Resource(DC_NS . "creator");
    $dc_subject = new Resource(DC_NS . "subject");
    $foaf_name = new Resource(FOAF_NS . "name");
    $foaf_depiction = new Resource(FOAF_NS . "depiction");
    $SearchResultPage = new Resource(SEARCH_NS . "SearchResultPage");
    $searchTerm = new Resource(SEARCH_NS . "searchTerm");
    $page = new Resource(SEARCH_NS . "page");
    $totalPages = new Resource(SEARCH_NS . "totalPages");