Skip to content

Commit

Permalink
Workaround URL differences for .com search when outside US
Browse files Browse the repository at this point in the history
- Also add option to use more flexible keyword searching
  • Loading branch information
jmeosbn committed Dec 29, 2017
1 parent e563d68 commit 3b3e459
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def json_decode(output):
}

sites_langs={
'www.audible.com' : { 'lang' : 'en', 'urltitle' : u'title=' , 'rel_date' : u'Release date' , 'nar_by' : u'Narrated By' , 'nar_by2': u'Narrated by'},
'www.audible.com' : { 'lang' : 'en', 'urltitle' : u'title=' , 'rel_date' : u'Release ' , 'nar_by' : u'Narrated By' , 'nar_by2': u'Narrated by'},
'www.audible.co.uk' : { 'lang' : 'en', 'urltitle' : u'searchTitle=' , 'rel_date' : u'Release Date' , 'nar_by' : u'Narrated By' , 'nar_by2': u'Narrated by'},
'www.audible.com.au' : { 'lang' : 'en', 'urltitle' : u'searchTitle=' , 'rel_date' : u'Release Date' , 'nar_by' : u'Narrated By' , 'nar_by2': u'Narrated by'},
'www.audible.fr' : { 'lang' : 'fr', 'urltitle' : u'searchTitle=' , 'rel_date' : u'Date de publication' , 'nar_by' : u'Narrateur(s)' , 'nar_by2': u'Lu par'},
Expand Down Expand Up @@ -99,12 +99,18 @@ def SetupUrls(sitetype, base, lang='en'):
Log('/* NAR_BY_INFO = %s', ctx['NAR_BY_INFO'])
Log('/********************************************************************************/')

# Match titles using more flexible keyword search
if Prefs['keyword_searching']:
urlsearchtitle = "advsearchKeywords="
else:
# fallback for .com title search outside US
urlsearchtitle += "{0}&searchTitle="

AUD_BASE_URL='https://' + str(base) + '/'
AUD_TITLE_URL=urlsearchtitle
ctx['AUD_BOOK_INFO' ]=AUD_BASE_URL + 'pd/%s?ipRedirectOverride=true'
ctx['AUD_ARTIST_SEARCH_URL' ]=AUD_BASE_URL + 'search?searchAuthor=%s&ipRedirectOverride=true'
ctx['AUD_ALBUM_SEARCH_URL' ]=AUD_BASE_URL + 'search?' + AUD_TITLE_URL + '%s&x=41&ipRedirectOverride=true'
ctx['AUD_ALBUM_SEARCH_URL' ]=AUD_BASE_URL + 'search?' + AUD_TITLE_URL + '{0}&x=41&ipRedirectOverride=true'
ctx['AUD_KEYWORD_SEARCH_URL']=AUD_BASE_URL + 'search?filterby=field-keywords&advsearchKeywords=%s&x=41&ipRedirectOverride=true'
ctx['AUD_SEARCH_URL' ]=AUD_BASE_URL + 'search?' + AUD_TITLE_URL + '{0}&searchAuthor={1}&x=41&ipRedirectOverride=true'
return ctx
Expand Down Expand Up @@ -354,7 +360,7 @@ def search(self, results, media, lang, manual):
elif media.artist is not None:
searchUrl = ctx['AUD_SEARCH_URL'].format((String.Quote((normalizedName).encode('utf-8'), usePlus=True)), (String.Quote((media.artist).encode('utf-8'), usePlus=True)))
else:
searchUrl = ctx['AUD_ALBUM_SEARCH_URL'] % (String.Quote((normalizedName).encode('utf-8'), usePlus=True))
searchUrl = ctx['AUD_ALBUM_SEARCH_URL'].format((String.Quote((normalizedName).encode('utf-8'), usePlus=True)))
found = self.doSearch(searchUrl, ctx)

# Write search result status to log
Expand Down
5 changes: 5 additions & 0 deletions Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"type" : "enum",
"values" : ["www.audible.com","www.audible.co.uk","www.audible.com.au","www.audible.de","www.audible.fr","www.audible.it"],
"default" : "www.audible.com"
},{
"id": "keyword_searching",
"label": "Match titles using more flexible keyword search",
"type": "bool",
"default": "false"
},{
"id": "debug",
"label": "Ouput debugging info in logs",
Expand Down

0 comments on commit 3b3e459

Please sign in to comment.