Skip to content

Commit

Permalink
fix(author-search): 🚑 ASIN in filename was being used as search for a…
Browse files Browse the repository at this point in the history
…uthor as well as book

this caused an infinite loading loop for artist update. Also make sure logging of filename uses unquoted name
  • Loading branch information
djdembeck committed Feb 24, 2023
1 parent 3724a97 commit 4e622b3
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Contents/Code/search_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# Setup logger
log = Logging()

asin_regex = '(?=.\\d)[A-Z\\d]{10}'
region_regex = '(?<=\[)[A-Za-z]{2}(?=\])'
asin_regex = re.compile(r'(?=.\d)[A-Z\d]{10}')
region_regex = re.compile(r'(?<=\[)[A-Za-z]{2}(?=\])')


class SearchTool:
Expand Down Expand Up @@ -41,18 +41,26 @@ def build_url(self, query):

def check_for_asin(self):
"""
Checks filename and search query for ASIN to quick match.
Checks filename (for books) and/or search query for ASIN to quick match.
"""
filename_search_asin = self.search_asin(self.media.filename)
# Check filename for ASIN if content type is books
if self.content_type == 'books':
# Provide a plain filename for ASIN search
filename_unquoted = urllib.unquote(
self.media.filename).decode('utf8')
filename_search_asin = self.search_asin(filename_unquoted)

if filename_search_asin:
log.info('ASIN found in filename')
self.check_for_region(filename_unquoted)
return filename_search_asin.group(0) + '_' + self.region_override

# Check search query for ASIN
# Default to album and use artist if no album
manual_asin = self.media.album if self.media.album else self.media.artist
manual_search_asin = self.search_asin(manual_asin)

if filename_search_asin:
log.info('ASIN found in filename')
self.check_for_region(self.media.filename)
return filename_search_asin.group(0) + '_' + self.region_override
elif manual_search_asin:
if manual_search_asin:
log.info('ASIN found in manual search')
self.check_for_region(manual_asin)
return manual_search_asin.group(0) + '_' + self.region_override
Expand Down Expand Up @@ -137,14 +145,14 @@ def search_asin(self, input):
Searches for ASIN in a string.
"""
if input:
return re.search(asin_regex, urllib.unquote(input).decode('utf8'))
return re.search(asin_regex, input)

def search_region(self, input):
"""
Searches for region in a string.
"""
if input:
return re.search(region_regex, urllib.unquote(input).decode('utf8'))
return re.search(region_regex, input)

def validate_author_name(self):
"""
Expand Down

0 comments on commit 4e622b3

Please sign in to comment.