Subversion Repositories cheapmusic

Rev

Rev 101 | Rev 121 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 101 Rev 120
Line 13... Line 13...
13
    }
13
    }
14
 
14
 
15
    $arr = [];
15
    $arr = [];
16
    $products = [];
16
    $products = [];
17
    $cnt = 0;
17
    $cnt = 0;
-
 
18
    $wlAddArr = [];
-
 
19
    $wlSearchArr = [];
18
 
20
 
19
    libxml_use_internal_errors(true);
21
    libxml_use_internal_errors(true);
20
    $html = getSearchCache("amazon_scrape", $query, $searchCondition);
22
    $html = getSearchCache("amazon_scrape", $query, $searchCondition);
21
    if ($html === false) {
23
    if ($html === false) {
22
        $html = getUrl("https://www.amazon.com/s?k=" . rawurlencode($query) . "&sf=qz&unfiltered=1&ref=nb_sb_noss");
24
        $html = getUrl("https://www.amazon.com/s?k=" . rawurlencode($query) . "&sf=qz&unfiltered=1&ref=nb_sb_noss");
Line 121... Line 123...
121
            }
123
            }
122
 
124
 
123
            if (strpos($format, "Audio CD") === 0 ||
125
            if (strpos($format, "Audio CD") === 0 ||
124
                strpos($format, "Vinyl") === 0) {
126
                strpos($format, "Vinyl") === 0) {
125
                if ($needMatches) {
127
                if ($needMatches) {
126
                    addMatch_scrape($xpathPrd, ++$cnt, $title, $artists, $format, $releaseDate, $asin, $url, $pic);
128
                    addMatch_scrape($xpathPrd, ++$cnt, $title, $artists, $format, $releaseDate, $asin, $url, $pic, $wlAddArr, $wlSearchArr);
127
                }
129
                }
128
            }
130
            }
129
 
131
 
130
            $listings = $xpath->query('//div[contains(concat(" ", normalize-space(@class), " "), " olpOffer ")]');
132
            $listings = $xpath->query('//div[contains(concat(" ", normalize-space(@class), " "), " olpOffer ")]');
131
 
133
 
Line 247... Line 249...
247
 
249
 
248
    if ($needMatches) {
250
    if ($needMatches) {
249
        if ($cnt = 0) {
251
        if ($cnt = 0) {
250
            $_SESSION["discogs"] = "";
252
            $_SESSION["discogs"] = "";
251
        } else {
253
        } else {
-
 
254
            $_SESSION["discogs"] .= '<script nonce="xxxNONCExx">';
-
 
255
            $_SESSION["discogs"] .= 'function addDiscogsEventsWait() {';
-
 
256
            $_SESSION["discogs"] .= 'document.addEventListener("DOMContentLoaded", function() {';
-
 
257
            $_SESSION["discogs"] .= '	addDiscogsEvents();';
-
 
258
            $_SESSION["discogs"] .= '});';
-
 
259
            $_SESSION["discogs"] .= '}';
-
 
260
 
-
 
261
            $_SESSION["discogs"] .= 'function addDiscogsEvents() {';
-
 
262
            foreach($wlAddArr as $k=>$v) {
-
 
263
                $_SESSION["discogs"] .= 'el = document.getElementById("' . $k . '");';
-
 
264
                $_SESSION["discogs"] .= 'if (el) document.getElementById("' . $k . '").addEventListener("click", function() {';
-
 
265
                $_SESSION["discogs"] .= $v;
-
 
266
                $_SESSION["discogs"] .= '	});';
-
 
267
            }
-
 
268
 
-
 
269
            foreach($wlSearchArr as $k=>$v) {
-
 
270
                $_SESSION["discogs"] .= 'el = document.getElementById("' . $k . '");';
-
 
271
                $_SESSION["discogs"] .= 'if (el) document.getElementById("' . $k . '").addEventListener("click", function() {';
-
 
272
                $_SESSION["discogs"] .= $v;
-
 
273
                $_SESSION["discogs"] .= '	});';
-
 
274
            }
-
 
275
            $_SESSION["discogs"] .= '}';
-
 
276
            $_SESSION["discogs"] .= 'addDiscogsEventsWait();';
-
 
277
            $_SESSION["discogs"] .= '</script>';
-
 
278
            
252
            $_SESSION["discogs"] .= endMatches();
279
            $_SESSION["discogs"] .= endMatches();
253
        }
280
        }
254
    }
281
    }
255
 
282
 
256
    return ($arr);
283
    return ($arr);
257
}
284
}
258
 
285
 
259
function addMatch_scrape($xpath, $cnt, $title, $artists, $mediaType, $releaseDate, $asin, $url, $pic) {
286
function addMatch_scrape($xpath, $cnt, $title, $artists, $mediaType, $releaseDate, $asin, $url, $pic, &$wlAddArr, &$wlSearchArr) {
260
    $nodes = $xpath->query('//table[@id="productDetailsTable"]//ul/li');
287
    $nodes = $xpath->query('//table[@id="productDetailsTable"]//ul/li');
261
    if ($nodes->length < 1) {
288
    if ($nodes->length < 1) {
262
        return;
289
        return;
263
    }
290
    }
264
 
291
 
Line 380... Line 407...
380
    $item->ItemInfo->addChild('MediaType', $mediaType);
407
    $item->ItemInfo->addChild('MediaType', $mediaType);
381
    $item->ItemInfo->addChild('Edition', $edition);
408
    $item->ItemInfo->addChild('Edition', $edition);
382
    $item->ItemInfo->addChild('Genre', $genre);
409
    $item->ItemInfo->addChild('Genre', $genre);
383
    $item->ItemInfo->addChild('RunningTime', (int)$runTime);
410
    $item->ItemInfo->addChild('RunningTime', (int)$runTime);
384
 
411
 
385
    $_SESSION["discogs"] .= addMatch($item, $cnt, $mediaType);
412
    $_SESSION["discogs"] .= addMatch($item, $cnt, $mediaType, $wlAddArr, $wlSearchArr);
386
}
413
}