Skip to content

Commit 4a00ac6

Browse files
committed
Remove B&H Photo Video, fix Amazon issues, and add block messages when not using proxies
1 parent 42f008a commit 4a00ac6

File tree

7 files changed

+56
-61
lines changed

7 files changed

+56
-61
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Currently, the following stores are supported:
4040
* Amazon, with ability to track stock by a particular merchant
4141
* Argos (UK. Does not currently work with proxies)\
4242
For PS5, use the following links. Disc: `https://www.argos.co.uk/product/8349000`, Digital: `https://www.argos.co.uk/product/8349024`
43-
* B&H Photo Video
4443
* Best Buy, including open-box and packages (Does not currently work with proxies)
4544
* Costco (Does not currently work with proxies)
4645
* Currys (UK)
@@ -200,7 +199,8 @@ To provide monetary support, [donate](https://www.paypal.com/donate?business=3Y9
200199
## Things to work on
201200
* Add more stores
202201
* Newegg search pages
203-
* ~~B&H Photo Video~~
202+
* Best Buy preorder alerts
203+
* ~~B&H Photo Video~~ (no longer supported)
204204
* ~~Ebuyer~~
205205
* ~~Walmart~~
206206
* ~~Gamestop~~

config/config.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"amazon",
2323
"antonline",
2424
"argos",
25-
"bhphotovideo",
2625
"bestbuy",
2726
"costco",
2827
"currys",
@@ -37,7 +36,6 @@
3736
"SUPPORTED_PROXY_DOMAINS": [
3837
"amazon",
3938
"antonline",
40-
"bhphotovideo",
4139
"currys",
4240
"ebuyer",
4341
"microcenter",

package-lock.json

Lines changed: 31 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import amazonFunction from "./stores/amazon.js";
1818
import antonlineFunction from "./stores/antonline.js";
1919
import argosFunction from "./stores/argos.js";
2020
import bestbuyFunction from "./stores/bestbuy.js";
21-
import bhphotovideoFunction from "./stores/bhphotovideo.js";
2221
import costcoFunction from "./stores/costco.js";
2322
import currysFunction from "./stores/currys.js";
2423
import ebuyerFunction from "./stores/ebuyer.js";
@@ -34,7 +33,6 @@ const storeFunctionMap = {
3433
antonline: antonlineFunction,
3534
argos: argosFunction,
3635
bestbuy: bestbuyFunction,
37-
bhphotovideo: bhphotovideoFunction,
3836
costco: costcoFunction,
3937
currys: currysFunction,
4038
ebuyer: ebuyerFunction,

src/stores/amazon.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ export default function amazon(html) {
44
try {
55
const TITLE_SELECTOR = "#productTitle";
66
const IMAGE_SELECTOR = "#landingImage";
7+
const IMAGE_BOOK_SELECTOR = "#img-canvas > img";
78
const INVENTORY_SELECTOR = "#add-to-cart-button";
89

910
const $ = cheerio.load(html);
1011
const title = $(TITLE_SELECTOR).text()?.trim();
11-
const image = $(IMAGE_SELECTOR).attr("data-old-hires");
12+
let image = $(IMAGE_SELECTOR).attr("data-old-hires");
1213
let inventory = $(INVENTORY_SELECTOR).attr("value");
1314

15+
if (!image) {
16+
image = $(IMAGE_SELECTOR).attr("src");
17+
if (!image) {
18+
image = $(IMAGE_BOOK_SELECTOR).attr("src");
19+
}
20+
}
21+
1422
if (inventory != undefined) {
1523
inventory = true;
1624
} else if (inventory == undefined) {

src/stores/bhphotovideo.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/utils/fetch.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const PROXY_BLOCKING_MESSAGES = [
1111
"Are you a human?",
1212
"Help us keep your account safe by clicking on the checkbox below",
1313
"we just need to make sure you're not a robot",
14+
"discuss automated access to Amazon",
1415
];
1516

1617
/*
@@ -106,15 +107,19 @@ export function fetchPage(url, store, use_proxies, badProxies, retry = false, ge
106107
}
107108
})
108109
.then((html) => {
109-
// If proxy was blocked, add to bad list and retry
110-
if (
111-
use_proxies &&
112-
PROXIES &&
113-
PROXY_BLOCKING_MESSAGES.some((message) => html.includes(message))
114-
) {
115-
toConsole("info", `Proxy, ${proxy}, was blocked! Retrying...`);
116-
badProxies.add(proxy);
117-
return fetchPage(url, store, use_proxies, badProxies, true);
110+
// If request was blocked..
111+
if (PROXY_BLOCKING_MESSAGES.some((message) => html.includes(message))) {
112+
// ..via proxy, add it to bad list and retry
113+
if (use_proxies && PROXIES) {
114+
toConsole("info", `Proxy, ${proxy}, was blocked! Retrying...`);
115+
badProxies.add(proxy);
116+
return fetchPage(url, store, use_proxies, badProxies, true);
117+
}
118+
// Otherwise, Raise error
119+
else {
120+
sourceHTML = html;
121+
throw new Error(`Request to ${store} was blocked!`);
122+
}
118123
}
119124

120125
return retry

0 commit comments

Comments
 (0)