Add a literal search option
In order to bypass processing of search results and search terms
This commit is contained in:
parent
3a3d67cbd0
commit
8b227afbb2
@ -202,6 +202,70 @@ class ComicVineTalker(QObject):
|
||||
raise ComicVineTalkerException(
|
||||
ComicVineTalkerException.Unknown, "Error on Comic Vine server")
|
||||
|
||||
def literalSearchForSeries(self, series_name, callback=None):
|
||||
|
||||
# normalize unicode and convert to ascii. Does not work for everything eg ½ to 1⁄2 not 1/2
|
||||
search_series_name = unicodedata.normalize('NFKD', series_name).encode('ascii', 'ignore').decode('ascii')
|
||||
|
||||
params = {
|
||||
'api_key': self.api_key,
|
||||
'format': 'json',
|
||||
'resources': 'volume',
|
||||
'query': search_series_name,
|
||||
'field_list': 'volume,name,id,start_year,publisher,image,description,count_of_issues',
|
||||
'page': 1
|
||||
}
|
||||
|
||||
cv_response = self.getCVContent(self.api_base_url + "/search", params)
|
||||
|
||||
search_results = list()
|
||||
|
||||
# see http://api.comicvine.com/documentation/#handling_responses
|
||||
|
||||
limit = cv_response['limit']
|
||||
current_result_count = cv_response['number_of_page_results']
|
||||
total_result_count = cv_response['number_of_total_results']
|
||||
|
||||
# 8 Dec 2018 - Comic Vine changed query results again. Terms are now
|
||||
# ORed together, and we get thousands of results. Good news is the
|
||||
# results are sorted by relevance, so we can be smart about halting
|
||||
# the search.
|
||||
# 1. Don't fetch more than some sane amount of pages.
|
||||
max_results = 50
|
||||
|
||||
total_result_count = min(total_result_count, max_results)
|
||||
|
||||
if callback is None:
|
||||
self.writeLog(
|
||||
"Found {0} of {1} results\n".format(
|
||||
cv_response['number_of_page_results'],
|
||||
cv_response['number_of_total_results']))
|
||||
search_results.extend(cv_response['results'])
|
||||
page = 1
|
||||
|
||||
if callback is not None:
|
||||
callback(current_result_count, total_result_count)
|
||||
|
||||
# see if we need to keep asking for more pages...
|
||||
while current_result_count < total_result_count:
|
||||
if callback is None:
|
||||
self.writeLog(
|
||||
"getting another page of results {0} of {1}...\n".format(
|
||||
current_result_count,
|
||||
total_result_count))
|
||||
page += 1
|
||||
|
||||
params['page'] = page
|
||||
cv_response = self.getCVContent(self.api_base_url + "/search", params)
|
||||
|
||||
search_results.extend(cv_response['results'])
|
||||
current_result_count += cv_response['number_of_page_results']
|
||||
|
||||
if callback is not None:
|
||||
callback(current_result_count, total_result_count)
|
||||
|
||||
return search_results
|
||||
|
||||
def searchForSeries(self, series_name, callback=None, refresh_cache=False):
|
||||
|
||||
# normalize unicode and convert to ascii. Does not work for everything eg ½ to 1⁄2 not 1/2
|
||||
|
@ -389,6 +389,8 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
self.actionSearchOnline.setStatusTip('Search online for tags')
|
||||
self.actionSearchOnline.triggered.connect(self.queryOnline)
|
||||
|
||||
self.actionLiteralSearch.triggered.connect(self.literalSearch)
|
||||
|
||||
self.actionAutoIdentify.setShortcut('Ctrl+I')
|
||||
self.actionAutoIdentify.triggered.connect(self.autoIdentifySearch)
|
||||
|
||||
@ -426,6 +428,8 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
QtGui.QIcon(ComicTaggerSettings.getGraphic('parse.png')))
|
||||
self.actionSearchOnline.setIcon(
|
||||
QtGui.QIcon(ComicTaggerSettings.getGraphic('search.png')))
|
||||
self.actionLiteralSearch.setIcon(
|
||||
QtGui.QIcon(ComicTaggerSettings.getGraphic('search.png')))
|
||||
self.actionAutoIdentify.setIcon(
|
||||
QtGui.QIcon(ComicTaggerSettings.getGraphic('auto.png')))
|
||||
self.actionAutoTag.setIcon(
|
||||
@ -441,6 +445,7 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
self.toolBar.addAction(self.actionSearchOnline)
|
||||
self.toolBar.addAction(self.actionAutoIdentify)
|
||||
self.toolBar.addAction(self.actionAutoTag)
|
||||
self.toolBar.addAction(self.actionLiteralSearch)
|
||||
self.toolBar.addAction(self.actionClearEntryForm)
|
||||
self.toolBar.addAction(self.actionPageBrowser)
|
||||
|
||||
@ -1047,7 +1052,10 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
|
||||
self.queryOnline(autoselect=True)
|
||||
|
||||
def queryOnline(self, autoselect=False):
|
||||
def literalSearch(self):
|
||||
self.queryOnline(autoselect=False,literal=True)
|
||||
|
||||
def queryOnline(self, autoselect=False, literal=False):
|
||||
|
||||
issue_number = str(self.leIssueNum.text()).strip()
|
||||
|
||||
@ -1085,7 +1093,9 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
cover_index_list,
|
||||
self.comic_archive,
|
||||
self.settings,
|
||||
autoselect)
|
||||
autoselect,
|
||||
literal
|
||||
)
|
||||
|
||||
title = "Search: '" + series_name + "' - "
|
||||
selector.setWindowTitle(title + "Select Series")
|
||||
|
@ -1196,6 +1196,7 @@
|
||||
<addaction name="actionParse_Filename"/>
|
||||
<addaction name="actionSearchOnline"/>
|
||||
<addaction name="actionAutoIdentify"/>
|
||||
<addaction name="actionLiteralSearch"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionApplyCBLTransform"/>
|
||||
</widget>
|
||||
@ -1393,6 +1394,14 @@
|
||||
<string>Search online for tags,auto-identify best match, and save to archive</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLiteralSearch">
|
||||
<property name="text">
|
||||
<string>Literal Search</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>perform a literal search on the series and return the first 50 results</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
@ -41,20 +41,26 @@ class SearchThread(QtCore.QThread):
|
||||
searchComplete = pyqtSignal()
|
||||
progressUpdate = pyqtSignal(int, int)
|
||||
|
||||
def __init__(self, series_name, refresh):
|
||||
def __init__(self, series_name, refresh, literal=False):
|
||||
QtCore.QThread.__init__(self)
|
||||
self.series_name = series_name
|
||||
self.refresh = refresh
|
||||
self.error_code = None
|
||||
self.literal = literal
|
||||
|
||||
def run(self):
|
||||
comicVine = ComicVineTalker()
|
||||
try:
|
||||
self.cv_error = False
|
||||
self.cv_search_results = comicVine.searchForSeries(
|
||||
self.series_name,
|
||||
callback=self.prog_callback,
|
||||
refresh_cache=self.refresh)
|
||||
if self.literal:
|
||||
self.cv_search_results = comicVine.literalSearchForSeries(
|
||||
self.series_name,
|
||||
callback=self.prog_callback)
|
||||
else:
|
||||
self.cv_search_results = comicVine.searchForSeries(
|
||||
self.series_name,
|
||||
callback=self.prog_callback,
|
||||
refresh_cache=self.refresh)
|
||||
except ComicVineTalkerException as e:
|
||||
self.cv_search_results = []
|
||||
self.cv_error = True
|
||||
@ -93,7 +99,7 @@ class IdentifyThread(QtCore.QThread):
|
||||
class VolumeSelectionWindow(QtWidgets.QDialog):
|
||||
|
||||
def __init__(self, parent, series_name, issue_number, year, issue_count,
|
||||
cover_index_list, comic_archive, settings, autoselect=False):
|
||||
cover_index_list, comic_archive, settings, autoselect=False, literal=False):
|
||||
super(VolumeSelectionWindow, self).__init__(parent)
|
||||
|
||||
uic.loadUi(
|
||||
@ -123,6 +129,7 @@ class VolumeSelectionWindow(QtWidgets.QDialog):
|
||||
self.immediate_autoselect = autoselect
|
||||
self.cover_index_list = cover_index_list
|
||||
self.cv_search_results = None
|
||||
self.literal = literal
|
||||
|
||||
self.twList.resizeColumnsToContents()
|
||||
self.twList.currentItemChanged.connect(self.currentItemChanged)
|
||||
@ -294,7 +301,7 @@ class VolumeSelectionWindow(QtWidgets.QDialog):
|
||||
self.progdialog.setModal(True)
|
||||
self.progdialog.setMinimumDuration(300)
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
self.search_thread = SearchThread(self.series_name, refresh)
|
||||
self.search_thread = SearchThread(self.series_name, refresh, self.literal)
|
||||
self.search_thread.searchComplete.connect(self.searchComplete)
|
||||
self.search_thread.progressUpdate.connect(self.searchProgressUpdate)
|
||||
self.search_thread.start()
|
||||
|
Loading…
x
Reference in New Issue
Block a user