diff --git a/comicvinecacher.py b/comicvinecacher.py index 1816d58..8bd10d3 100644 --- a/comicvinecacher.py +++ b/comicvinecacher.py @@ -25,15 +25,20 @@ import sys import os import datetime +from settings import ComicTaggerSettings + class ComicVineCacher: - def __init__(self, settings_folder ): - self.settings_folder = settings_folder + def __init__(self ): + self.settings_folder = ComicTaggerSettings.getSettingsFolder() self.db_file = os.path.join( self.settings_folder, "cv_cache.db") if not os.path.exists( self.db_file ): self.create_cache_db() + def clearCache( self ): + os.unlink( self.db_file ) + def create_cache_db( self ): # this will wipe out any existing version diff --git a/comicvinetalker.py b/comicvinetalker.py index adf4dcb..08003d5 100644 --- a/comicvinetalker.py +++ b/comicvinetalker.py @@ -62,7 +62,7 @@ class ComicVineTalker(QObject): # before we search online, look in our cache, since we might have # done this same search recently - cvc = ComicVineCacher( ComicTaggerSettings.getSettingsFolder() ) + cvc = ComicVineCacher( ) if not refresh_cache: cached_search_results = cvc.get_search_results( series_name ) @@ -134,7 +134,7 @@ class ComicVineTalker(QObject): # before we search online, look in our cache, since we might already # have this info - cvc = ComicVineCacher( ComicTaggerSettings.getSettingsFolder() ) + cvc = ComicVineCacher( ) cached_volume_result = cvc.get_volume_info( series_id ) if cached_volume_result is not None: @@ -284,11 +284,11 @@ class ComicVineTalker(QObject): # before we search online, look in our cache, since we might already # have this info - cvc = ComicVineCacher( ComicTaggerSettings.getSettingsFolder() ) + cvc = ComicVineCacher( ) return cvc.get_issue_select_details( issue_id ) def cacheIssueSelectDetails( self, issue_id, image_url, thumb_url, month, year ): - cvc = ComicVineCacher( ComicTaggerSettings.getSettingsFolder() ) + cvc = ComicVineCacher( ) cvc.add_issue_select_details( issue_id, image_url, thumb_url, month, year ) diff --git a/imagefetcher.py b/imagefetcher.py index dd5ac36..028e9b3 100644 --- a/imagefetcher.py +++ b/imagefetcher.py @@ -46,6 +46,12 @@ class ImageFetcher(QObject): if not os.path.exists( self.db_file ): self.create_image_db() + def clearCache( self ): + os.unlink( self.db_file ) + if os.path.isdir( self.cache_folder ): + shutil.rmtree( self.cache_folder ) + + def fetch( self, url, user_data=None, blocking=False ): """ If called with blocking=True, this will block until the image is diff --git a/issueidentifier.py b/issueidentifier.py index 54de091..0372bc2 100644 --- a/issueidentifier.py +++ b/issueidentifier.py @@ -42,7 +42,7 @@ class IssueIdentifier: ResultOneGoodMatch = 4 ResultMultipleGoodMatches = 5 - def __init__(self, comic_archive, cv_api_key ): + def __init__(self, comic_archive, settings ): self.comic_archive = comic_archive self.image_hasher = 1 @@ -58,13 +58,13 @@ class IssueIdentifier: self.strong_score_thresh = 8 # used to eliminate series names that are too long based on our search string - self.length_delta_thresh = 5 + self.length_delta_thresh = settings.id_length_delta_thresh # used to eliminate unlikely publishers - self.publisher_blacklist = [ 'panini comics', 'abril', 'scholastic book services' ] + #self.publisher_blacklist = [ 'panini comics', 'abril', 'scholastic book services' ] + self.publisher_blacklist = [ s.strip().lower() for s in settings.id_publisher_blacklist.split(',') ] self.additional_metadata = GenericMetadata() - self.cv_api_key = cv_api_key self.output_function = IssueIdentifier.defaultWriteOutput self.callback = None self.search_result = self.ResultNoMatches @@ -239,8 +239,9 @@ class IssueIdentifier: if keys['month'] is not None: self.log_msg( "\tMonth : " + keys['month'] ) + self.log_msg("Publisher Blacklist: " + str(self.publisher_blacklist)) - comicVine = ComicVineTalker( self.cv_api_key ) + comicVine = ComicVineTalker( ) #self.log_msg( ( "Searching for " + keys['series'] + "...") self.log_msg( "Searching for {0} #{1} ...".format( keys['series'], keys['issue_number']) ) diff --git a/issueselectionwindow.py b/issueselectionwindow.py index df9a7d8..967f529 100644 --- a/issueselectionwindow.py +++ b/issueselectionwindow.py @@ -98,8 +98,6 @@ class IssueSelectionWindow(QtGui.QDialog): row += 1 - #TODO look for given issue in list, and select that one - self.twList.setSortingEnabled(True) self.twList.sortItems( 0 , QtCore.Qt.AscendingOrder ) diff --git a/settings.py b/settings.py index 50d02be..4e385be 100644 --- a/settings.py +++ b/settings.py @@ -43,6 +43,10 @@ class ComicTaggerSettings: last_main_window_x = 0 last_main_window_y = 0 + # identifier settings + id_length_delta_thresh = 5 + id_publisher_blacklist = "panini comics, abril, scholastic book services" + @staticmethod def getSettingsFolder(): if platform.system() == "Windows": @@ -117,6 +121,11 @@ class ComicTaggerSettings: self.last_main_window_x = self.config.getint( 'auto', 'last_main_window_x' ) if self.config.has_option('auto', 'last_main_window_y'): self.last_main_window_y = self.config.getint( 'auto', 'last_main_window_y' ) + + if self.config.has_option('identifier', 'id_length_delta_thresh'): + self.id_length_delta_thresh = self.config.getint( 'identifier', 'id_length_delta_thresh' ) + if self.config.has_option('identifier', 'id_publisher_blacklist'): + self.id_publisher_blacklist = self.config.get( 'identifier', 'id_publisher_blacklist' ) def save( self ): @@ -136,6 +145,12 @@ class ComicTaggerSettings: self.config.set( 'auto', 'last_main_window_height', self.last_main_window_height ) self.config.set( 'auto', 'last_main_window_x', self.last_main_window_x ) self.config.set( 'auto', 'last_main_window_y', self.last_main_window_y ) + + if not self.config.has_section( 'identifier' ): + self.config.add_section( 'identifier' ) + + self.config.set( 'identifier', 'id_length_delta_thresh', self.id_length_delta_thresh ) + self.config.set( 'identifier', 'id_publisher_blacklist', self.id_publisher_blacklist ) with open( self.settings_file, 'wb') as configfile: self.config.write(configfile) diff --git a/settingswindow.py b/settingswindow.py index 2cf60ba..8d7a054 100644 --- a/settingswindow.py +++ b/settingswindow.py @@ -23,8 +23,9 @@ import os from PyQt4 import QtCore, QtGui, uic from settings import ComicTaggerSettings -from comicvinetalker import * - +from comicvinecacher import ComicVineCacher +from imagefetcher import ImageFetcher +import utils windowsRarHelp = """
In order to write to CBR/RAR archives, @@ -48,10 +49,8 @@ macRarHelp = """
""" - class SettingsWindow(QtGui.QDialog): - - + def __init__(self, parent, settings ): super(SettingsWindow, self).__init__(parent) @@ -72,45 +71,34 @@ class SettingsWindow(QtGui.QDialog): self.lblRarHelp.setText( macRarHelp ) # Copy values from settings to form - self.leCVAPIKey.setText( self.settings.cv_api_key ) self.leRarExePath.setText( self.settings.rar_exe_path ) self.leUnrarExePath.setText( self.settings.unrar_exe_path ) + self.leNameLengthDeltaThresh.setText( str(self.settings.id_length_delta_thresh) ) + self.tePublisherBlacklist.setPlainText( self.settings.id_publisher_blacklist ) - - self.btnTestKey.clicked.connect(self.testAPIKey) self.btnBrowseRar.clicked.connect(self.selectRar) - self.btnBrowseUnrar.clicked.connect(self.selectUnrar) + self.btnBrowseUnrar.clicked.connect(self.selectUnrar) + self.btnClearCache.clicked.connect(self.clearCache) def accept( self ): # Copy values from form to settings and save - self.settings.cv_api_key = str(self.leCVAPIKey.text()) self.settings.rar_exe_path = str(self.leRarExePath.text()) self.settings.unrar_exe_path = str(self.leUnrarExePath.text()) # make sure unrar program is now in the path for the UnRAR class utils.addtopath(os.path.dirname(self.settings.unrar_exe_path)) + if not str(self.leNameLengthDeltaThresh.text()).isdigit(): + QtGui.QMessageBox.information(self,"Settings", "The Name Length Delta Threshold must be a number!") + return + + self.settings.id_length_delta_thresh = int(self.leNameLengthDeltaThresh.text()) + self.settings.id_publisher_blacklist = str(self.tePublisherBlacklist.toPlainText()) + self.settings.save() QtGui.QDialog.accept(self) - def testAPIKey( self ): - # TODO hourglass - - palette = self.lblResult.palette() - bad_color = QtGui.QColor(255, 0, 0) - good_color = QtGui.QColor(0, 255, 0) - - comicVine = ComicVineTalker( str(self.leCVAPIKey.text()) ) - if comicVine.testKey( ): - palette.setColor(self.lblResult.foregroundRole(), good_color) - self.lblResult.setText("Good Key!") - else: - palette.setColor(self.lblResult.foregroundRole(), bad_color) - self.lblResult.setText("Bad Key :(") - - self.lblResult.setPalette(palette) - def selectRar( self ): self.selectFile( self.leRarExePath, "RAR" ) @@ -118,6 +106,9 @@ class SettingsWindow(QtGui.QDialog): def selectUnrar( self ): self.selectFile( self.leUnrarExePath, "UnRAR" ) + def clearCache( self ): + ImageFetcher().clearCache() + ComicVineCacher( ).clearCache() def selectFile( self, control, name ): diff --git a/settingswindow.ui b/settingswindow.ui index 1dbf710..71609e9 100644 --- a/settingswindow.ui +++ b/settingswindow.ui @@ -6,8 +6,8 @@