Skip to content

Commit

Permalink
Merge pull request #23 from seanap/develop
Browse files Browse the repository at this point in the history
Map series' to moods, code quality improvements
  • Loading branch information
seanap authored Aug 30, 2021
2 parents 13e1374 + 6511fbd commit 7068757
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 39 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [v2021.08.29.2](https://github.com/seanap/Audiobooks.bundle/tree/v2021.08.29.2) (2021-08-30)

[Full Changelog](https://github.com/seanap/Audiobooks.bundle/compare/v2021.08.28.1...v2021.08.29.2)

**Implemented enhancements:**

- Refine score when multiple of same book [\#19](https://github.com/seanap/Audiobooks.bundle/issues/19)
- Speed and scoring improvements [\#21](https://github.com/seanap/Audiobooks.bundle/pull/21) ([djdembeck](https://github.com/djdembeck))

## [v2021.08.28.1](https://github.com/seanap/Audiobooks.bundle/tree/v2021.08.28.1) (2021-08-28)

[Full Changelog](https://github.com/seanap/Audiobooks.bundle/compare/2021.08.27.1...v2021.08.28.1)
Expand Down
73 changes: 38 additions & 35 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def getStringContentFromXPath(self, source, query):
def getAnchorUrlFromXPath(self, source, query):
anchor = source.xpath(query)

if len(anchor) == 0:
if not anchor:
return None

return anchor[0].get('href')

def getImageUrlFromXPath(self, source, query):
img = source.xpath(query)

if len(img) == 0:
if not img:
return None

return img[0].get('src')
Expand Down Expand Up @@ -468,9 +468,9 @@ def score_result(self, f, helper, i, info, valid_itemId, year):
)

# Because builtin sum() isn't available
sum=lambda numberlist:reduce(lambda x,y:x+y,numberlist,0)
sum_scores=lambda numberlist:reduce(lambda x,y:x+y,numberlist,0)
# Subtract difference from initial score
score = INITIAL_SCORE - sum(all_scores)
score = INITIAL_SCORE - sum_scores(all_scores)

log.info("Result #" + str(i + 1))
# Log basic metadata
Expand Down Expand Up @@ -708,16 +708,10 @@ def compile_metadata(self, helper):
if helper.date is not None:
helper.metadata.originally_available_at = helper.date

# Add the genres
if not Prefs['no_overwrite_genre']:
helper.metadata.genres.clear()
helper.metadata.genres.add(helper.genre_parent)
# Not all books have 2 genres
if helper.genre_child:
helper.metadata.genres.add(helper.genre_child)

self.add_narrators_to_moods(helper)
self.add_genres(helper)
self.add_narrators_to_styles(helper)
self.add_authors_to_moods(helper)
self.add_series_to_moods(helper)
self.parse_series(helper)

# Other metadata
Expand Down Expand Up @@ -748,39 +742,39 @@ def compile_metadata(self, helper):
if helper.rating:
helper.metadata.rating = float(helper.rating) * 2

# Collections if/when Plex supports them
# https://github.com/seanap/Audiobooks.bundle/issues/1#issuecomment-713191070
helper.metadata.collections.clear()
helper.metadata.collections.add(helper.series)
if helper.series2:
helper.metadata.collections.add(helper.series2)
helper.writeInfo()

def add_narrators_to_moods(self, helper):
# Add Narrators to Styles
def add_genres(self, helper):
"""
Add genre(s) to Plex genres where available and depending on preference.
"""
if not Prefs['no_overwrite_genre']:
helper.metadata.genres.clear()
helper.metadata.genres.add(helper.genre_parent)
# Not all books have 2 genres
if helper.genre_child:
helper.metadata.genres.add(helper.genre_child)

def add_narrators_to_styles(self, helper):
"""
Adds narrators to styles.
"""
narrators_list = helper.narrator.split(",")
narr_contributors_list = [
'full cast'
]
helper.metadata.styles.clear()
# Loop through narrators to check if it has contributor wording

for narrator in narrators_list:
if not [
contrib for contrib in narr_contributors_list if (
contrib in narrator.lower()
)
]:
helper.metadata.styles.add(narrator.strip())
helper.metadata.styles.add(narrator.strip())

def add_authors_to_moods(self, helper):
# Add Authors to Moods
"""
Adds authors to moods, except for cases in contibutors list.
"""
author_list = helper.author.split(",")
author_contributers_list = [
'contributor',
'translator',
'foreword',
'translated',
'full cast',
]
helper.metadata.moods.clear()
# Loop through authors to check if it has contributor wording
Expand All @@ -792,6 +786,15 @@ def add_authors_to_moods(self, helper):
]:
helper.metadata.moods.add(author.strip())

def add_series_to_moods(self, helper):
"""
Adds book series' to moods, since collections are not supported
"""

helper.metadata.moods.add(helper.series)
if helper.series2:
helper.metadata.moods.add(helper.series2)

def parse_series(self, helper):
# Clean series
x = re.match("(.*)(: A .* Series)", helper.series_def)
Expand Down Expand Up @@ -848,15 +851,15 @@ def getStringContentFromXPath(self, source, query):
def getAnchorUrlFromXPath(self, source, query):
anchor = source.xpath(query)

if len(anchor) == 0:
if not anchor:
return None

return anchor[0].get('href')

def getImageUrlFromXPath(self, source, query):
img = source.xpath(query)

if len(img) == 0:
if not img:
return None

return img[0].get('src')
Expand Down
2 changes: 1 addition & 1 deletion Contents/Code/search_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def pre_search_logging(self):
self.media.album = self.media.name

def strip_title(self, normalizedName):
if len(normalizedName) == 0:
if not normalizedName:
normalizedName = self.media.album
log.debug(
'normalizedName = %s', normalizedName
Expand Down
4 changes: 1 addition & 3 deletions Contents/Code/update_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ def writeInfo(self):

# Log basic metadata stored in arrays
multi_arr = [
# {'Collection': self.metadata.collections},
{'Genre': self.metadata.genres},
{'Genres & Series': self.metadata.genres},
{'Moods(Authors)': self.metadata.moods},
{'Styles(Narrators)': self.metadata.styles},
# {'Fan art URL': self.metadata.art},
]
log.metadata_arrs(multi_arr, log_level="info")

Expand Down

0 comments on commit 7068757

Please sign in to comment.