Skip to content

Commit 4e622b3

Browse files
committed
fix(author-search): 🚑 ASIN in filename was being used as search for author as well as book
this caused an infinite loading loop for artist update. Also make sure logging of filename uses unquoted name
1 parent 3724a97 commit 4e622b3

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

Contents/Code/search_tools.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# Setup logger
99
log = Logging()
1010

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

1414

1515
class SearchTool:
@@ -41,18 +41,26 @@ def build_url(self, query):
4141

4242
def check_for_asin(self):
4343
"""
44-
Checks filename and search query for ASIN to quick match.
44+
Checks filename (for books) and/or search query for ASIN to quick match.
4545
"""
46-
filename_search_asin = self.search_asin(self.media.filename)
46+
# Check filename for ASIN if content type is books
47+
if self.content_type == 'books':
48+
# Provide a plain filename for ASIN search
49+
filename_unquoted = urllib.unquote(
50+
self.media.filename).decode('utf8')
51+
filename_search_asin = self.search_asin(filename_unquoted)
52+
53+
if filename_search_asin:
54+
log.info('ASIN found in filename')
55+
self.check_for_region(filename_unquoted)
56+
return filename_search_asin.group(0) + '_' + self.region_override
57+
58+
# Check search query for ASIN
4759
# Default to album and use artist if no album
4860
manual_asin = self.media.album if self.media.album else self.media.artist
4961
manual_search_asin = self.search_asin(manual_asin)
5062

51-
if filename_search_asin:
52-
log.info('ASIN found in filename')
53-
self.check_for_region(self.media.filename)
54-
return filename_search_asin.group(0) + '_' + self.region_override
55-
elif manual_search_asin:
63+
if manual_search_asin:
5664
log.info('ASIN found in manual search')
5765
self.check_for_region(manual_asin)
5866
return manual_search_asin.group(0) + '_' + self.region_override
@@ -137,14 +145,14 @@ def search_asin(self, input):
137145
Searches for ASIN in a string.
138146
"""
139147
if input:
140-
return re.search(asin_regex, urllib.unquote(input).decode('utf8'))
148+
return re.search(asin_regex, input)
141149

142150
def search_region(self, input):
143151
"""
144152
Searches for region in a string.
145153
"""
146154
if input:
147-
return re.search(region_regex, urllib.unquote(input).decode('utf8'))
155+
return re.search(region_regex, input)
148156

149157
def validate_author_name(self):
150158
"""

0 commit comments

Comments
 (0)