]> Joshua Wise's Git repositories - patchfork.git/blobdiff - player/metadata.php
Tweak support for Amazon coverart grabbing to be able to use keyword search, too...
[patchfork.git] / player / metadata.php
index 5da76079383b106a2bf9a59a8fbd100ab45bca7c..9de3be3f3b5b0a0bc5d79f62fdcdd30691d540b3 100644 (file)
        /* how much time must pass before we try searching for cover art again */
        $COVER_SEARCH_AGAIN = 86400;
 
        /* how much time must pass before we try searching for cover art again */
        $COVER_SEARCH_AGAIN = 86400;
 
-       $amazon_base_url = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId="
-                   . "15BH771NY941TX2NKC02";
-       $amazon_review_url = $amazon_base_url . "&ResponseGroup=EditorialReview&Operation=";
+       include("aws_signed_request.php");
        require_once("../inc/base.php");
        require_once("metadata_cover.php");
        
        require_once("../inc/base.php");
        require_once("metadata_cover.php");
        
+       function amazonlink($params)
+       {
+               $params["SubscriptionId"] = "15BH771NY941TX2NKC02";
+               if (strlen(get_config("aws_secret")) == 0)
+                       return False;
+               $res = aws_signed_request("com", $params, get_config("aws_keyid"), get_config("aws_secret"));
+               
+               return $res;
+       }
+       
        /* metadata should not require locking of session */
        session_write_close();
 
        /* metadata should not require locking of session */
        session_write_close();
 
        /* Queries amazon with the specified url, strict serach first and then a more careless one, 
         * will urlencode artist and albumname 
         * returns xml document or false upon failure */
        /* Queries amazon with the specified url, strict serach first and then a more careless one, 
         * will urlencode artist and albumname 
         * returns xml document or false upon failure */
-       function amazon_album_query($base_url, $artist, $album) {
+       function amazon_album_query($params, $album) {
                $stype = array("Title", "Keywords");
                $artist = urlencode($artist);
                $album = urlencode($album);
                foreach($stype as $st) {
                        if(!amazon_wait())
                                return false;
                $stype = array("Title", "Keywords");
                $artist = urlencode($artist);
                $album = urlencode($album);
                foreach($stype as $st) {
                        if(!amazon_wait())
                                return false;
-                       $xml = @simplexml_load_string(@file_get_contents($base_url . "&Artist=$artist&$st=$album"));
+                       $params[$st] = $album;
+                       $xml = amazonlink($params);
                        if($xml&&isset($xml->Items[0])&&isset($xml->Items[0]->Item[0]))
                                return $xml;
                        if($xml&&isset($xml->Items[0])&&isset($xml->Items[0]->Item[0]))
                                return $xml;
+                        unset($params[$st]);
                }
                return false;
        }
                }
                return false;
        }
 
 
        function get_cover() {
 
 
        function get_cover() {
-               global $COVER_SEARCH_AGAIN, $amazon_base_url,$cover_providers;
+               global $COVER_SEARCH_AGAIN, $cover_providers;
 
                list($fp, $artist, $album) = init_album_artist_or_die();
 
 
                list($fp, $artist, $album) = init_album_artist_or_die();
 
        }
 
        function get_review() {
        }
 
        function get_review() {
-               global $amazon_review_url, $COVER_SEARCH_AGAIN;
+               global $COVER_SEARCH_AGAIN;
 
                list($fp, $artist, $album) = init_album_artist_or_die();
 
 
                list($fp, $artist, $album) = init_album_artist_or_die();
 
                        }
 
                        if($xml&&isset($xml->asin[0])) {
                        }
 
                        if($xml&&isset($xml->asin[0])) {
-                               $res = @file_get_contents($amazon_review_url . "ItemLookup&IdType=ASIN&ItemId=" . urlencode($xml->asin[0]));
-                               if($res)
-                                       $res = @simplexml_load_string($res);
+                               $res = amazonlink(array("Operation"=>"ItemLookup", "IdType"=>"ASIN", "ItemId"=>"urlencode($xml->asin[0])"));
                                $asin = false;
                        }
                        else {
                                $asin = false;
                        }
                        else {
-                               $res = @amazon_album_query($amazon_review_url . "ItemSearch&SearchIndex=Music&Artist=" , $artist , $album);
+                               $res = @amazon_album_query(array("Operation"=>"ItemSearch", "SearchIndex"=>"Music", "Artist"=>"$artist"), $album);
                        }
                        if($res) {
                                if($res&&isset($res->Items[0])&&isset($res->Items[0]->Item[0])) {
                        }
                        if($res) {
                                if($res&&isset($res->Items[0])&&isset($res->Items[0]->Item[0])) {
This page took 0.024808 seconds and 4 git commands to generate.