/** * @param $title * * @return bool|mixed * @throws Exception */ public function fetchAmazonProperties($title) { $response = false; $conf = new GenericConfiguration(); try { $conf->setCountry('com')->setAccessKey($this->pubkey)->setSecretKey($this->privkey)->setAssociateTag($this->asstag)->setResponseTransformer('\\newznab\\libraries\\ApaiIO\\ResponseTransformer\\XmlToSimpleXmlObject'); } catch (\Exception $e) { echo $e->getMessage(); } $apaiIo = new ApaiIO($conf); // Try Music category. try { $search = new Search(); $search->setCategory('Music'); $search->setKeywords($title); $search->setResponseGroup(['Large']); $response = $apaiIo->runOperation($search); } catch (\Exception $e) { // Empty because we try another method. } // Try MP3 category. if ($response === false) { usleep(700000); try { $search = new Search(); $search->setCategory('MP3Downloads'); $search->setKeywords($title); $search->setResponseGroup(['Large']); $response = $apaiIo->runOperation($search); } catch (\Exception $e) { // Empty because we try another method. } } // Try Digital Music category. if ($response === false) { usleep(700000); try { $search = new Search(); $search->setCategory('DigitalMusic'); $search->setKeywords($title); $search->setResponseGroup(['Large']); $response = $apaiIo->runOperation($search); } catch (\Exception $e) { // Empty because we try another method. } } // Try Music Tracks category. if ($response === false) { usleep(700000); try { $search = new Search(); $search->setCategory('MusicTracks'); $search->setKeywords($title); $search->setResponseGroup(['Large']); $response = $apaiIo->runOperation($search); } catch (\Exception $e) { // Empty because we exhausted all possibilities. } } if ($response === false) { throw new \Exception("Could not connect to Amazon"); } else { if (isset($response->Items->Item->ItemAttributes->Title)) { return $response; } else { return false; } } }
public function fetchAmazonProperties($title, $node) { $conf = new GenericConfiguration(); try { $conf->setCountry('com')->setAccessKey($this->pubkey)->setSecretKey($this->privkey)->setAssociateTag($this->asstag)->setResponseTransformer('\\newznab\\libraries\\ApaiIO\\ResponseTransformer\\XmlToSimpleXmlObject'); } catch (\Exception $e) { echo $e->getMessage(); } $search = new Search(); $search->setCategory('VideoGames'); $search->setKeywords($title); $search->setBrowseNode($node); $search->setResponseGroup(['Large']); $apaiIo = new ApaiIO($conf); $response = $apaiIo->runOperation($search); if ($response === false) { throw new \Exception("Could not connect to Amazon"); } else { if (isset($response->Items->Item->ItemAttributes->Title)) { return $response; } else { return false; } } }
<?php require_once dirname(__FILE__) . '/../../../www/config.php'; use newznab\libraries\ApaiIO\Configuration\GenericConfiguration; use newznab\libraries\ApaiIO\Operations\Search; use newznab\libraries\ApaiIO\ApaiIO; use newznab\db\Settings; $pdo = new Settings(); $pubkey = $pdo->getSetting('amazonpubkey'); $privkey = $pdo->getSetting('amazonprivkey'); $asstag = $pdo->getSetting('amazonassociatetag'); $conf = new GenericConfiguration(); $conf->setCountry('com')->setAccessKey($pubkey)->setSecretKey($privkey)->setAssociateTag($asstag)->setResponseTransformer('\\newznab\\libraries\\ApaiIO\\ResponseTransformer\\XmlToSimpleXmlObject'); $search = new Search(); $search->setCategory('VideoGames'); $search->setKeywords('Guilty Gear 2 Oveture'); $search->setResponseGroup(['Large']); $search->setPage(1); $apaiIo = new ApaiIO($conf); $response = $apaiIo->runOperation($search); var_dump($response);