Skip to content

Commit

Permalink
Merge pull request #26 from seanap/develop
Browse files Browse the repository at this point in the history
Improvements to error handling
  • Loading branch information
djdembeck committed Sep 2, 2021
2 parents 1d8ac72 + d48e4c5 commit ad48e73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.python-version
20 changes: 8 additions & 12 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from update_tools import UpdateTool
from urls import SiteUrl

VERSION_NO = '2021.08.30.2'

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

# Starting value for score before deductions are taken.
INITIAL_SCORE = 100
Expand All @@ -23,8 +19,6 @@
# Any score lower than this will be ignored.
IGNORE_SCORE = 45

#THREAD_MAX = 20

# Setup logger
log = Logging()

Expand Down Expand Up @@ -90,7 +84,7 @@ def findDateInTitle(self, title):
return None

def doSearch(self, ctx, url):
html = HTML.ElementFromURL(url, sleep=REQUEST_DELAY)
html = HTML.ElementFromURL(url)
found = []

for r in html.xpath('//div[a/img[@class="yborder"]]'):
Expand Down Expand Up @@ -120,7 +114,7 @@ def search(self, results, media, lang, manual=False):
log.debug(
'* Artist: %s', media.artist
)
log.error(
log.warn(
'****************************************'
'Not Ready For Artist Search Yet'
'****************************************'
Expand Down Expand Up @@ -248,7 +242,10 @@ def update(self, metadata, media, lang, force=False):
url = ctx['AUD_BOOK_INFO'] % metadata.id

try:
html = HTML.ElementFromURL(url, sleep=REQUEST_DELAY)
html = HTML.ElementFromURL(url)
except UnboundLocalError as e:
log.error("Title no longer avaible on Audible: " + metadata.id)
return
except Exception as e:
log.error(e)

Expand Down Expand Up @@ -349,7 +346,7 @@ def create_search_url(self, ctx, helper):
return searchUrl

def doSearch(self, ctx, url):
html = HTML.ElementFromURL(url, sleep=REQUEST_DELAY)
html = HTML.ElementFromURL(url)
found = []

# Set append to the returned array from this function
Expand Down Expand Up @@ -607,7 +604,6 @@ def scrape_book_metadata(self, ctx, helper, html):
helper.date = date
helper.genre_child = genre_child
helper.genre_parent = genre_parent
# helper.url = murl
helper.narrator = narrator
helper.series = series
helper.studio = studio
Expand Down
2 changes: 1 addition & 1 deletion Contents/Code/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def info(self, message, *args):
):
return Log(message, *args)

def warning(self, message, *args):
def warn(self, message, *args):
"""
Prints passed message with INFO TYPE,
when DEBUG, INFO or WARN pref enabled.
Expand Down
10 changes: 7 additions & 3 deletions Contents/Code/update_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ def re_parse_with_date_published(self, json_data):
for c in data['author']:
author_array.append(c['name'])
self.author = ",".join(author_array)

narrator_array = []
for c in data['readBy']:
narrator_array.append(c['name'])
if 'readBy' in data:
for c in data['readBy']:
narrator_array.append(c['name'])
else:
log.warn("No narrator listed for: " + self.metadata.id)
narrator_array.append("[Unknown Artist]")
self.narrator = ",".join(narrator_array)
self.studio = data['publisher']
self.synopsis = data['description']
Expand Down
7 changes: 3 additions & 4 deletions Contents/Code/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from logging import Logging

# Setup logger
log = Logging()


class SiteUrl:
intl_sites = {
Expand Down Expand Up @@ -190,7 +193,3 @@ def SetupUrls(self):
self.set_context_urls()

return self.context


# Setup logger
log = Logging()

0 comments on commit ad48e73

Please sign in to comment.