krthush / link-preview

An API for getting near perfect link preview data - works for Node.js enviroments.
https://favorited-link-preview.herokuapp.com/
MIT License
42 stars 19 forks source link

have additional fallback using amazon product advertising api for amazon links #2

Open krthush opened 3 years ago

krthush commented 3 years ago

see https://webservices.amazon.com/paapi5/documentation/

amazon id "can" be obtain from link, but can be tricky since doesn't seem like there is a consistent structure?

for example here the id is B0140RDK8W but both of the following links work

https://www.amazon.com/gp/product/B0140RDK8W

https://www.amazon.com/dp/B0140RDK8W

krthush commented 3 years ago

see list of supported urls https://stackoverflow.com/questions/902001/how-to-get-product-information-from-amazon-just-based-on-the-url

http://amazon./gp/product/*

http://amazon.//dp/*

http://amazon./dp/*

http://amazon./o/ASIN/*

http://amazon./gp/offer-listing/*

http://amazon.//ASIN/*

http://amazon./gp/product/images/*

http://amazon./gp/aw/d/*

http://www.amzn.com/*

http://amzn.com/*

krthush commented 3 years ago

https://stackoverflow.com/questions/21700573/get-asin-from-pasted-amazon-url seems to have some "easier" solutions

krthush commented 3 years ago

following regex works for the supported urls list

(?:dp|o|gp|-|gp\/product|\/ASIN|gp\/offer-listing|gp\/product\/images|gp\/aw\/d)\/(B[0-9]{2}[0-9A-Z]{7}|[0-9]{9}(?:X|[0-9]))

excluding the following 2 urls

http://www.amzn.com/*

http://amzn.com/*

krthush commented 3 years ago

implemented setup with 6df1800 and 8151be1, now waiting for registration from amazon associates, until further work can be done