Skip to content

Commit

Permalink
feat: 🎨 improve handling of authors as contributors
Browse files Browse the repository at this point in the history
such as `John Smith - translator`
  • Loading branch information
djdembeck committed Oct 5, 2021
1 parent a522522 commit beb20f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
13 changes: 2 additions & 11 deletions Contents/Code/__init__.py
Expand Up @@ -739,21 +739,12 @@ def add_authors_to_moods(self, helper):
"""
Adds authors to moods, except for cases in contibutors list.
"""
author_contributers_list = [
'contributor',
'translator',
'foreword',
'translated',
]
contributor_regex = '.+?(?= -)'
if not helper.metadata.moods or helper.force:
helper.metadata.moods.clear()
# Loop through authors to check if it has contributor wording
for author in helper.author:
if not [
contrib for contrib in author_contributers_list if (
contrib in author['name'].lower()
)
]:
if not re.match(contributor_regex, author['name']):
helper.metadata.moods.add(author['name'].strip())

def add_series_to_moods(self, helper):
Expand Down
40 changes: 31 additions & 9 deletions Contents/Code/search_tools.py
Expand Up @@ -192,6 +192,12 @@ def build_url(self):

return final_url

def clear_contributor_text(self, string):
contributor_regex = '.+?(?= -)'
if re.match(contributor_regex, string):
return re.match(contributor_regex, string).group(0)
return string

def parse_api_response(self, api_response):
"""
Collects keys used for each item from API response, for Plex search results.
Expand All @@ -217,15 +223,31 @@ def validate_author_name(self):
If matched, author name is set to None to prevent
it being used in search query.
"""
if ',' in self.media.artist:
split_authors = self.media.artist.split(',')
log.info(
'Merging multi-author "' +
self.media.artist +
'" into top-level author "' +
split_authors[0] + '"'
)
self.media.artist = split_authors[0]

author_array = self.media.artist.split(', ')
# Handle multi-artist
if len(author_array) > 1:
# Go through list of artists until we find a non contributor
for i, r in enumerate(author_array):
if self.clear_contributor_text(r):
log.debug('Author #' + str(i+1) + ' is a contributor')
continue
log.info(
'Merging multi-author "' +
self.media.artist +
'" into top-level author "' +
r + '"'
)
self.media.artist = r
return
else:
if self.clear_contributor_text(self.media.artist):
log.debug('Stripped contributor tag from author')
self.media.artist = self.clear_contributor_text(
self.media.artist
)
log.debug(self.media.artist)

strings_to_check = [
"[Unknown Artist]"
]
Expand Down

0 comments on commit beb20f6

Please sign in to comment.