Esempio n. 1
0
 public function testapiTest()
 {
     $obj = new AmazonProductAPI();
     try {
         $result = $obj->searchProducts("spice girls", AmazonProductAPI::DVD, "TITLE");
         $data = $result->Items->Item->ItemAttributes->Title;
         echo $data . "\n";
         $this->assertNotNull($data);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     try {
         $result = $obj->searchProducts("024543602859", AmazonProductAPI::DVD, "UPC");
         $data = $result->Items->Item->ItemAttributes->Title;
         echo $data . "\n";
         $this->assertNotNull($data);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     try {
         $result = $obj->getItemByUpc("014633190168", AmazonProductAPI::GAMES);
         $data = $result->Items->Item->ItemAttributes->Title;
         echo $data . "\n";
         $this->assertNotNull($data);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     try {
         $result = $obj->getItemByAsin("B001AVCFK6", AmazonProductAPI::DVD);
         $data = $result->Items->Item->ItemAttributes->Title;
         echo $data . "\n";
         $this->assertNotNull($data);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     try {
         $result = $obj->getItemByKeyword("tom petty", AmazonProductAPI::MUSIC);
         $data = $result->Items->Item->ItemAttributes->Title;
         echo $data . "\n";
         $this->assertNotNull($data);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
<?php

define('FS_ROOT', realpath(dirname(__FILE__)));
require_once FS_ROOT . "/../../www/config.php";
require_once FS_ROOT . "/../../www/lib/amazon.php";
require_once FS_ROOT . "/../../www/lib/site.php";
require_once FS_ROOT . "/../../www/lib/book.php";
$b = new Book();
$s = new Sites();
$site = $s->get();
$title = "Long Arm, The - Franz Habl ";
$obj = new AmazonProductAPI($site->amazonpubkey, $site->amazonprivkey, $site->amazonassociatetag);
try {
    $amaz = $obj->searchProducts($title, AmazonProductAPI::BOOKS, "TITLE");
    $item = array();
    $item["asin"] = (string) $amaz->Items->Item->ASIN;
    $item["url"] = (string) $amaz->Items->Item->DetailPageURL;
    $item["cover"] = (string) $amaz->Items->Item->LargeImage->URL;
    $item["author"] = (string) $amaz->Items->Item->ItemAttributes->Author;
    $item["dewey"] = (string) $amaz->Items->Item->ItemAttributes->DeweyDecimalNumber;
    $item["ean"] = (string) $amaz->Items->Item->ItemAttributes->EAN;
    $item["isbn"] = (string) $amaz->Items->Item->ItemAttributes->ISBN;
    $item["publisher"] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
    $item["publishdate"] = (string) $amaz->Items->Item->ItemAttributes->PublicationDate;
    $item["pages"] = (string) $amaz->Items->Item->ItemAttributes->NumberOfPages;
    $item["title"] = (string) $amaz->Items->Item->ItemAttributes->Title;
    $item["review"] = "";
    if (isset($amaz->Items->Item->EditorialReviews)) {
        $item["review"] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
    }
    print_r($item);
 /**
  * Retrieve info from Amazon for a title.
  */
 public function fetchAmazonProperties($title)
 {
     $obj = new AmazonProductAPI($this->pubkey, $this->privkey, $this->asstag);
     try {
         $result = $obj->searchProducts($title, AmazonProductAPI::MP3, "TITLE");
     } catch (Exception $e) {
         //if first search failed try the mp3downloads section
         try {
             // sleep for 1 second
             sleep(1);
             $result = $obj->searchProducts($title, AmazonProductAPI::MUSIC, "TITLE");
         } catch (Exception $e2) {
             $result = false;
         }
     }
     return $result;
 }
Esempio n. 4
0
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
require_once nZEDb_LIBS . 'AmazonProductAPI.php';
use nzedb\db\Settings;
// Test if your amazon keys are working.
$pdo = new Settings();
$pubkey = $pdo->getSetting('amazonpubkey');
$privkey = $pdo->getSetting('amazonprivkey');
$asstag = $pdo->getSetting('amazonassociatetag');
$obj = new AmazonProductAPI($pubkey, $privkey, $asstag);
$e = null;
try {
    $result = $obj->searchProducts("Adriana Koulias The Seal", AmazonProductAPI::BOOKS, "TITLE");
} catch (Exception $e) {
    $result = false;
}
if ($result !== false) {
    print_r($result);
    exit($pdo->log->header("\nLooks like it is working alright."));
} else {
    print_r($e);
    exit($pdo->log->error("\nThere was a problem attemtping to query amazon. Maybe your keys or wrong, or you are being throttled.\n"));
}
Esempio n. 5
0
<?php

/* Example usage of the Amazon Product Advertising API */
include "amazon_api_class.php";
$obj = new AmazonProductAPI();
try {
    $result = $obj->searchProducts("Harry Potter", AmazonProductAPI::DVD, "TITLE");
} catch (Exception $e) {
    echo $e->getMessage();
}
print_r($result);
echo "Sales Rank : {$result->Items->Item->SalesRank}<br>";
echo "ASIN : {$result->Items->Item->ASIN}<br>";
echo "<br><img src=\"" . $result->Items->Item->MediumImage->URL . "\" /><br>";
Esempio n. 6
0
 public function fetchAmazonProperties($title)
 {
     $obj = new \AmazonProductAPI($this->pubkey, $this->privkey, $this->asstag);
     try {
         $result = $obj->searchProducts($title, \AmazonProductAPI::BOOKS, 'TITLE');
     } catch (\Exception $e) {
         $result = false;
     }
     return $result;
 }
Esempio n. 7
0
 /**
  * Retrieve properties for an item from Amazon.
  */
 public function fetchAmazonProperties($title, $node)
 {
     $obj = new AmazonProductAPI($this->pubkey, $this->privkey, $this->asstag);
     try {
         $result = $obj->searchProducts($title, AmazonProductAPI::GAMES, "NODE", $node);
     } catch (Exception $e) {
         $result = false;
     }
     return $result;
 }
Esempio n. 8
0
 /**
  * @param $title
  *
  * @return bool|mixed
  */
 public function fetchAmazonProperties($title)
 {
     $result = false;
     $obj = new \AmazonProductAPI($this->pubkey, $this->privkey, $this->asstag);
     // Try Music category.
     try {
         $result = $obj->searchProducts($title, \AmazonProductAPI::MUSIC, "TITLE");
     } catch (\Exception $e) {
         // Empty because we try another method.
     }
     // Try MP3 category.
     if ($result === false) {
         usleep(700000);
         try {
             $result = $obj->searchProducts($title, \AmazonProductAPI::MP3, "TITLE");
         } catch (\Exception $e) {
             // Empty because we try another method.
         }
     }
     // Try Digital Music category.
     if ($result === false) {
         usleep(700000);
         try {
             $result = $obj->searchProducts($title, \AmazonProductAPI::DIGITALMUS, "TITLE");
         } catch (\Exception $e) {
             // Empty because we try another method.
         }
     }
     // Try Music Tracks category.
     if ($result === false) {
         usleep(700000);
         try {
             $result = $obj->searchProducts($title, \AmazonProductAPI::MUSICTRACKS, "TITLE");
         } catch (\Exception $e) {
             // Empty because we exhausted all possibilities.
         }
     }
     return $result;
 }
Esempio n. 9
0
<?php

/* Example usage of the Amazon Product Advertising API */
include "amazon_api_class.php";
$obj = new AmazonProductAPI();
$result = '';
try {
    $result = $obj->searchProducts("X-Men Origins", AmazonProductAPI::DVD, "TITLE");
} catch (Exception $e) {
    echo $e->getMessage();
}
print_r($result);
exit;
echo "Sales Rank : {$result->Items->Item->SalesRank}<br>";
echo "ASIN : {$result->Items->Item->ASIN}<br>";
echo "<br><img src=\"" . $result->Items->Item->MediumImage->URL . "\" /><br>";
Esempio n. 10
0
<?php

/* Example usage of the Amazon Product Advertising API */
include "AmazonProductAPI.class.php";
$amazon = new AmazonProductAPI();
error_reporting(0);
$DEBUG = true;
$query = !empty($_REQUEST['q']) ? $_REQUEST['q'] : 'X-Men Origins';
$category = !empty($_REQUEST['category']) ? $_REQUEST['category'] : AmazonProductAPI::DVD;
try {
    $result = $amazon->searchProducts($query, $category, "TITLE");
} catch (Exception $e) {
    echo $e->getMessage();
}
$resultList = '<ul>';
foreach ($result->Items->Item as $item) {
    $resultList .= '<li><a href="http://www.amazon.com/gp/product/' . $item->ASIN . '/?ref=' . $amazon->getAssociateTag() . '&tag=' . $amazon->getAssociateTag() . '" title="' . $item->ItemAttributes->Title . '" target="_blank">';
    if ($item->MediumImage->URL) {
        $resultList .= '<img src="' . $item->MediumImage->URL . '" /></a>';
    } else {
        $resultList .= '<img src="http://farm2.static.flickr.com/1192/534117370_7eec8198e8.jpg" alt="Image Coming Soon..." width="120" /></a>';
    }
    if ($item->SalesRank) {
        $resultList .= '<br/>Rank: ' . $item->SalesRank;
    }
    $resultList .= '</li>';
}
$resultList .= '</ul>';
?>
<html>
<head>
Esempio n. 11
0
 private function doAmazon($q, $name = '', $id = 0, $nfo = '', $region = 'com', $case = false, $row = '')
 {
     $amazon = new \AmazonProductAPI($this->pdo->getSetting('amazonpubkey'), $this->pdo->getSetting('amazonprivkey'), $this->pdo->getSetting('amazonassociatetag'));
     $ok = false;
     try {
         switch ($case) {
             case 'upc':
                 $amaz = $amazon->getItemByUpc(trim($q), $region);
                 break;
             case 'asin':
                 $amaz = $amazon->getItemByAsin(trim($q), $region);
                 break;
             case 'isbn':
                 $amaz = $amazon->searchProducts(trim($q), '', "ISBN");
                 break;
             default:
                 $amaz = false;
         }
     } catch (\Exception $e) {
         echo 'Caught exception: ', $e->getMessage() . PHP_EOL;
         unset($s, $amaz, $amazon);
     }
     if (isset($amaz) && isset($amaz->Items->Item)) {
         sleep(2);
         $type = $amaz->Items->Item->ItemAttributes->ProductGroup;
         switch ($type) {
             case 'Audible':
             case 'Book':
             case 'eBooks':
                 $ok = $this->_doAmazonBooks($amaz, $id);
                 break;
             case 'Digital Music Track':
             case 'Digital Music Album':
             case 'Music':
                 $ok = $this->_doAmazonMusic($amaz, $id);
                 break;
             case 'Bluray':
             case 'Movies':
             case 'DVD':
             case 'DVD & Bluray':
                 $ok = $this->_doAmazonMovies($nfo, $amaz, $id);
                 break;
             case 'Video Games':
                 $ok = $this->_doAmazonVG($amaz, $id);
                 break;
             default:
                 echo PHP_EOL . $this->pdo->log->error("Amazon category {$type} could not be parsed for " . $name) . PHP_EOL;
         }
     }
     return $ok;
 }
Esempio n. 12
0
function get_amazon_link($title, $runtime, $cast)
{
    require "amazon/amazon_api_class.php";
    $title = preg_replace('/[^a-z0-9]+/i', ' ', $title);
    $obj = new AmazonProductAPI();
    try {
        $result = $obj->searchProducts($title, AmazonProductAPI::VIDEO, "TITLE");
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    $link = ["link" => "", "rent" => "", "buy" => "", "asin" => ""];
    $test = true;
    foreach ($result->Items->Item as $k) {
        if ($test) {
            echo $k;
            $test = false;
        }
        if ($k->ItemAttributes->Binding == 'Amazon Instant Video') {
            if (abs($k->ItemAttributes->RunningTime - $runtime) < 5 && strpos($cast, (string) $k->ItemAttributes->Actor) !== false || abs($k->ItemAttributes->RunningTime - $runtime) < 5 && levenshtein($title, (string) $k->ItemAttributes->Title) <= 3) {
                $link['link'] = $k->DetailPageURL;
                $link['asin'] = $k->ASIN;
                break;
            }
        }
    }
    if (strlen($link['link']) > 0) {
        $html = file_get_contents($link['link']);
        if (!strpos($html, 'movie is currently unavailable') && strlen($html) > 20) {
            //$pos = strpos($html, '<strong>Release year:</strong> ');
            //$release = substr($html, $pos+31, 4);
            //echo $release;
            $html = substr($html, strpos($html, '<ul class="button-list">'), 2000);
            $matches = array();
            $rent = "";
            $buy = "";
            preg_match_all("/Rent SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
            if (sizeof($matches[0]) > 0) {
                $rent .= substr($matches[0][0], 8);
            }
            preg_match_all("/Rent HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
            if (sizeof($matches[0]) > 0) {
                $rent .= "|" . substr($matches[0][0], 8);
            }
            preg_match_all("/Buy SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
            if (sizeof($matches[0]) > 0) {
                $buy .= substr($matches[0][0], 7);
            }
            preg_match_all("/Buy HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
            if (sizeof($matches[0]) > 0) {
                $buy .= "|" . substr($matches[0][0], 7);
            }
            $link['rent'] = $rent;
            $link['buy'] = $buy;
        } else {
            $link['link'] = '';
        }
    }
    return $link;
}
Esempio n. 13
0
 public static function get_link($movieId)
 {
     $link = self::find_by_id($movieId);
     $exists = $link ? true : false;
     if ($link && days_from_now($link->timestamp) < LINK_UPDATE_DAYS) {
         // good
     } else {
         $exists = $link ? true : false;
         $movie = Movie::find_by_id($movieId);
         $link = new Amazon();
         $link->id = $movieId;
         $link->timestamp = gen_timestamp();
         require_once LIB_PATH . DS . "amazon_api_class.php";
         $runtime = $movie->runtime;
         $title = preg_replace('/[^a-z0-9]+/i', ' ', $movie->title);
         $obj = new AmazonProductAPI();
         try {
             $result = $obj->searchProducts($title, AmazonProductAPI::VIDEO, "TITLE");
         } catch (Exception $e) {
             echo $e->getMessage();
         }
         $cast = Actor::list_of_names($movie->id);
         foreach ($result->Items->Item as $k) {
             if ($k->ItemAttributes->Binding == 'Amazon Instant Video') {
                 if (abs($k->ItemAttributes->RunningTime - $runtime) < 5 && strpos($cast, (string) $k->ItemAttributes->Actor) !== false || abs($k->ItemAttributes->RunningTime - $runtime) < 5 && levenshtein($title, (string) $k->ItemAttributes->Title) <= 3) {
                     $link->link = $k->DetailPageURL;
                     $link->asin = $k->ASIN;
                     break;
                 }
             }
         }
         if (strlen($link->link) > 0) {
             $html = file_get_contents($link->link);
             if (!strpos($html, 'movie is currently unavailable') && strlen($html) > 20) {
                 $html = substr($html, strpos($html, '<ul class="button-list">'), 2000);
                 $matches = array();
                 $rent = "";
                 $buy = "";
                 preg_match_all("/Rent SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $rent .= substr($matches[0][0], 8);
                 }
                 preg_match_all("/Rent HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $rent .= "|" . substr($matches[0][0], 8);
                 }
                 preg_match_all("/Buy SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $buy .= substr($matches[0][0], 7);
                 }
                 preg_match_all("/Buy HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $buy .= "|" . substr($matches[0][0], 7);
                 }
                 $link->rent = $rent;
                 $link->buy = $buy;
             }
         }
         if ($exists) {
             $link->update();
         } else {
             $link->create();
         }
     }
     return $link;
 }