szarroug3 / X-Ray_Calibre_Plugin

X-Ray Creator plugin for Calibre
http://www.mobileread.com/forums/showthread.php?t=273189
GNU General Public License v3.0
57 stars 12 forks source link

Book config UI opens link to amazon.co.uk, should try to open in local store #76

Closed stoduk closed 8 years ago

stoduk commented 8 years ago

As discussed in #45, the "open" button for amazon links opens in the .co.uk store. We should try to open it in the local store.

Simplest option would be to give a config option to let the user type whatever they want (we can validate it works before saving).

A more automated way could use this information, we'd just need to write a mapping between country and domain (eg. GB -> .co.uk). I couldn't even find a full list of amazon domains, so maybe this isn't worth the effort.

Thoughts? Former option will be most simple and robust, latter is nicer and automated (but needs to mapping to be worked out).

X-Ray_Calibre_Plugin anthony$ curl "http://ipinfo.io"
{
  "ip": "90.212.178.7",
  "hostname": "5ad4b207.bb.sky.com",
  "city": "Hemel Hempstead",
  "region": "England",
  "country": "GB",
  "loc": "51.7500,-0.4667",
  "org": "AS5607 Sky UK Limited",
  "postal": "HP3"
} X-Ray_Calibre_Plugin anthony$ 
szarroug3 commented 8 years ago

Just found the list at the bottom of amazon's website.. It's not that long actually.

Australia - www.amazon.com.au Brazil - www.amazon.com.br Canada - www.amazon.ca China - www.amazon.cn France - www.amazon.fr Germany - www.amazon.de India - www.amazon.in Italy - www.amazon.it Japan - www.amazon.co.jp Mexico - www.amazon.com.mx Netherlands - www.amazon.nl Spain - www.amazon.es United Kingdom - www.amazon.co.uk

We could probably just default any other country to somewhere else.

stoduk commented 8 years ago

Nice, I was googling to find the list, didn't occur to me there would be a list on their frontpage!

Are you keen to do the automated way? Shouldn't be too tricky, though I don't know if we'd want to still give people the option to change it (which means either a config option, or telling them to manually edit the saved settings. Though I can't see where the settings are saved so that might be a non-starter).

szarroug3 commented 8 years ago

I don't mind either way. I just feel like people might not be too interested in going to look at the preferences too much so they might just end up with the default when there's a better option for them.

On Tue, Nov 1, 2016 at 3:51 PM Anthony Toole notifications@github.com wrote:

Nice, I was googling to find the list, didn't occur to me there would be a list on their frontpage!

Are you keen to do the automated way? Shouldn't be too tricky, though I don't know if we'd want to still give people the option to change it (which means either a config option, or telling them to manually edit the saved settings. Though I can't see where the settings are saved so that might be a non-starter).

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/szarroug3/X-Ray_Calibre_Plugin/issues/76#issuecomment-257692483, or mute the thread https://github.com/notifications/unsubscribe-auth/AIEjUf1JrC-QDoXikxsyBrIcFFIXWZtCks5q56ZSgaJpZM4Kmbih .

stoduk commented 8 years ago

OK, we can make it guess and if people have a problem with it they can ask for a config option later :)

This code basically does it, I'll sort it out later (probably tomorrow, busy day today).

from collections import defaultdict
try:
    country = json.loads(urllib2.urlopen("http://ipinfo.io/json").read())["country"]
except:
    country = "unknown"
country_tld=defaultdict(lambda:"com", {"AU":"com.au", "BR":"com.br", "CA":"ca", "CN":"cn", "FR":"fr", "DE":"de", "IN":"in", "IT":"it", "JP":"co.jp", "MX":"com.mx", "NL":"nl", "ES":"es", "GB":"co.uk", "US":"com"})
tld = country_tld[country]