Exemple #1
0
function amazon_search_cover($artist, $album)
{
    global $amazon_cover_url, $metadata_dir;
    $xml = amazon_album_query($amazon_cover_url, $artist, $album);
    if ($xml) {
        if (isset($xml->Items[0]) && isset($xml->Items[0]->Item[0])) {
            $item = $xml->Items[0]->Item[0];
            $small = false;
            $small_name = false;
            $large = false;
            $large_name = false;
            if (isset($item->SmallImage[0])) {
                $small = @file_get_contents($item->SmallImage[0]->URL[0]);
                if ($small) {
                    $small_name = escape_name($artist) . "-" . escape_name($album) . basename($item->SmallImage[0]->URL[0]);
                    if (!@file_put_contents($metadata_dir . $small_name, $small)) {
                        $small = false;
                    }
                }
            }
            if (isset($item->LargeImage[0])) {
                $large = @file_get_contents($item->LargeImage[0]->URL[0]);
                if ($large) {
                    $large_name = escape_name($artist) . "-" . escape_name($album) . basename($item->LargeImage[0]->URL[0]);
                    if (!@file_put_contents($metadata_dir . $large_name, $large)) {
                        $large = false;
                    }
                }
            } else {
                if (isset($item->MediumImage[0])) {
                    $large = @file_get_contents($item->MediumImage[0]->URL[0]);
                    if ($large) {
                        $large_name = escape_name($artist) . "-" . escape_name($album) . basename($item->MediumImage[0]->URL[0]);
                        if (!@file_put_contents($metadata_dir . $large_name, $large)) {
                            $large = false;
                        }
                    }
                }
            }
            if ($small && $large) {
                $data = array();
                $data['asin'] = $item->ASIN[0];
                $data['thumbnail'] = $small_name;
                $data['image'] = $large_name;
                return $data;
            }
        }
    }
    return false;
}
Exemple #2
0
function get_review()
{
    global $amazon_review_url, $COVER_SEARCH_AGAIN;
    list($fp, $artist, $album) = init_album_artist_or_die();
    $xml = fp_get_contents($fp);
    $asin = "";
    $desc = false;
    $review = false;
    $review_src = false;
    $no_search = false;
    $failed = false;
    $changed = false;
    if ($xml) {
        $xml = @simplexml_load_string($xml);
        if ($xml) {
            if (isset($xml->rnotfound) && is_numeric((string) $xml->rnotfound[0])) {
                $time = @intval((string) $xml->rnotfound[0]);
                if ($time + $COVER_SEARCH_AGAIN > time()) {
                    $no_search = true;
                }
            }
        }
    }
    if (!$xml || !(isset($xml->review[0]) || isset($xml->desc[0])) && !$no_search) {
        $res = false;
        if (!amazon_wait()) {
            echo array_to_xml(array("result" => "failed"))->asXML();
            exit;
        }
        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);
            }
            $asin = false;
        } else {
            $res = @amazon_album_query($amazon_review_url . "ItemSearch&SearchIndex=Music&Artist=", $artist, $album);
        }
        if ($res) {
            if ($res && isset($res->Items[0]) && isset($res->Items[0]->Item[0])) {
                $p = $res->Items[0]->Item[0];
                $asin = (string) $p->ASIN;
                if (isset($p->EditorialReviews[0])) {
                    $p = $p->EditorialReviews[0];
                    foreach ($p->EditorialReview as $er) {
                        if (!$desc && "Album Description" == (string) $er->Source) {
                            $desc = (string) $er->Content;
                        } else {
                            if (!$review) {
                                $review_src = (string) $er->Source;
                                $review = (string) $er->Content;
                            }
                        }
                    }
                }
                /* set info in xml-file... */
                if ($xml) {
                    if ($review) {
                        $xml->review_src = htmlspecialchars($review_src);
                        $xml->review = htmlspecialchars($review);
                    }
                    if ($desc) {
                        $xml->desc = htmlspecialchars($desc);
                    }
                    if (!isset($xml->asin[0])) {
                        $xml->addChild("asin", $asin);
                        $changed = true;
                    }
                    if (!$review && !$desc) {
                        $failed = true;
                    } else {
                        $changed = true;
                    }
                } else {
                    $xml = array();
                    $xml['asin'] = $asin;
                    if ($desc) {
                        $xml['desc'] = $desc;
                    }
                    if ($review) {
                        $xml['review_src'] = $review_src;
                        $xml['review'] = $review;
                    }
                    if (!$review && !$desc) {
                        $failed = true;
                    }
                    $xml = array_to_xml($xml);
                    $changed = true;
                }
            } else {
                $failed = true;
            }
        } else {
            $failed = true;
        }
    } else {
        $xml->addChild("cached", "true");
    }
    if ($xml) {
        if ($failed) {
            if (isset($xml->rnotfound)) {
                $xml->rnotfound = time();
            } else {
                $xml->addChild("rnotfound", time());
            }
            @fwrite($fp, $xml->asXML());
        } else {
            if ($changed) {
                @fwrite($fp, $xml->asXML());
            }
        }
    } else {
        $xml = array_to_xml(array("rnotfound" => time()));
        @fwrite($fp, $xml->asXML());
    }
    @fclose($fp);
    echo $xml->asXML();
    exit;
}