diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cfe738..d4a17a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 833eb32..738fa07 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -70,7 +70,7 @@ 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') @@ -78,7 +78,7 @@ def getAnchorUrlFromXPath(self, source, query): def getImageUrlFromXPath(self, source, query): img = source.xpath(query) - if len(img) == 0: + if not img: return None return img[0].get('src') @@ -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 @@ -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 @@ -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 @@ -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) @@ -848,7 +851,7 @@ 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') @@ -856,7 +859,7 @@ def getAnchorUrlFromXPath(self, source, query): def getImageUrlFromXPath(self, source, query): img = source.xpath(query) - if len(img) == 0: + if not img: return None return img[0].get('src') diff --git a/Contents/Code/search_tools.py b/Contents/Code/search_tools.py index adb2cbf..74360db 100644 --- a/Contents/Code/search_tools.py +++ b/Contents/Code/search_tools.py @@ -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 diff --git a/Contents/Code/update_tools.py b/Contents/Code/update_tools.py index 2d2461d..2b551b0 100644 --- a/Contents/Code/update_tools.py +++ b/Contents/Code/update_tools.py @@ -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")