Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed xpath for series, and tried to add to collection #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def json_decode(output):


# URLs
VERSION_NO = '1.2020.04.15.1'
VERSION_NO = '1.2019.07.29.1'

REQUEST_DELAY = 10 # Delay used when requesting HTML, may be good to have to prevent being banned from the site

Expand All @@ -35,16 +35,16 @@ def json_decode(output):
'fr' : { 'url': 'www.audible.fr' , 'urltitle' : u'title=' , 'rel_date' : u'Date de publication' , 'nar_by' : u'Narrateur(s)' , 'nar_by2': u'Lu par'},
'de' : { 'url': 'www.audible.de' , 'urltitle' : u'title=' , 'rel_date' : u'Erscheinungsdatum' , 'nar_by' : u'Gesprochen von', 'rel_date2': u'Veröffentlicht'},
'it' : { 'url': 'www.audible.it' , 'urltitle' : u'title=' , 'rel_date' : u'Data di Pubblicazione', 'nar_by' : u'Narratore' },
#'jp' : { 'url': 'www.audible.co.jp', 'rel_date' : u'N/A', 'nar_by' : u'ナレーター' }, # untested
}

sites_langs={
'www.audible.com' : { 'lang' : 'en' , 'url': 'www.audible.com' },
'www.audible.ca' : { 'lang' : 'en' , 'url': 'www.audible.ca' },
'www.audible.co.uk' : { 'lang' : 'en' , 'url': 'www.audible.co.uk'},
'www.audible.com.au' : { 'lang' : 'en' , 'url': 'www.audible.com.au'},
'www.audible.fr' : { 'lang' : 'fr' , 'url': 'www.audible.fr' },
'www.audible.de' : { 'lang' : 'de' , 'url': 'www.audible.de' },
'www.audible.it' : { 'lang' : 'it' , 'url': 'www.audible.it' },
'www.audible.com' : { 'lang' : 'en' },
'www.audible.co.uk' : { 'lang' : 'en' },
'www.audible.com.au' : { 'lang' : 'en' },
'www.audible.fr' : { 'lang' : 'fr' },
'www.audible.de' : { 'lang' : 'de' },
'www.audible.it' : { 'lang' : 'it' },
}

def SetupUrls(sitetype, base, lang='en'):
Expand All @@ -57,7 +57,7 @@ def SetupUrls(sitetype, base, lang='en'):
Log('Pulling language from sites array')
lang=sites_langs[base]['lang']
if lang in intl_sites :
base=sites_langs[base]['url']
base=intl_sites[lang]['url']
urlsearchtitle=intl_sites[lang]['urltitle']
ctx['REL_DATE']=intl_sites[lang]['rel_date']
ctx['NAR_BY' ]=intl_sites[lang]['nar_by']
Expand Down Expand Up @@ -459,7 +459,7 @@ def search(self, results, media, lang, manual):
i += 1

def update(self, metadata, media, lang, force=False):
self.Log('***** UPDATING "%s" ID: %s - AUDIBLE v.%s *****', media.title, metadata.id, VERSION_NO)
self.Log('***** UPDATING***** UPDATING "%s" ID: %s - AUDIBLE v.%s *****', media.title, metadata.id, VERSION_NO)
ctx=SetupUrls(Prefs['sitetype'], Prefs['site'], lang)

# Make url
Expand Down Expand Up @@ -535,8 +535,16 @@ def update(self, metadata, media, lang, force=False):
except:
continue

for r in html.xpath('//li[contains (@class, "seriesLabel")]'):
series = self.getStringContentFromXPath(r, '//li[contains (@class, "seriesLabel")]//a[1]')
# not sure why this errors - syntax seem OK in Xpath tester
#series = html.xpath('string-join(//span[contains (@class, "seriesLabel")]//a, ","')
series = ''
counter=1
for r in html.xpath('//span[contains (@class, "seriesLabel")]/a'):
if counter > 1:
series+=','

series+=self.getStringContentFromXPath(r, '//span[contains (@class, "seriesLabel")]/a['+str(counter)+']')
counter+=1
#Log(series.strip())


Expand Down Expand Up @@ -579,7 +587,8 @@ def update(self, metadata, media, lang, force=False):

# Add the genres
metadata.genres.clear()
metadata.genres.add(series)
# series goes into collection instead
#metadata.genres.add(series)
narrators_list = narrator.split(",")
for narrators in narrators_list:
metadata.genres.add(narrators)
Expand All @@ -594,6 +603,12 @@ def update(self, metadata, media, lang, force=False):
metadata.posters.validate_keys(thumb)
metadata.rating = float(rating) * 2

# Add the collection tag
metadata.collections.clear()
series_list = series.split(",")
for sl in series_list:
metadata.collections.add(sl)

metadata.title = title
media.artist = author

Expand Down