From 8e32f3c75593afcc0135010f4a6c3000a8c270ec Mon Sep 17 00:00:00 2001
From: "beville@gmail.com"
Date: Tue, 20 Nov 2012 08:57:12 +0000
Subject: [PATCH] Added some setting for clearing cache and tuning the issue
identifier
git-svn-id: http://comictagger.googlecode.com/svn/trunk@68 6c5673fe-1810-88d6-992b-cd32ca31540c
---
comicvinecacher.py | 9 +-
comicvinetalker.py | 8 +-
imagefetcher.py | 6 +
issueidentifier.py | 11 +-
issueselectionwindow.py | 2 -
settings.py | 15 ++
settingswindow.py | 45 ++--
settingswindow.ui | 470 +++++++++++++++++++++++----------------
tagger.py | 2 +-
taggerwindow.py | 1 -
todo.txt | 33 +--
volumeselectionwindow.py | 3 +-
12 files changed, 348 insertions(+), 257 deletions(-)
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 @@
0
0
- 750
- 403
+ 753
+ 440
@@ -16,192 +16,286 @@
false
-
-
-
- 530
- 340
- 191
- 30
-
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Ok
-
-
-
-
-
- 20
- 20
- 581
- 61
-
-
-
- <html><head/><body><p>To perform online searches using ComicVine, you must first register and request an API key. You can start here: <a href="http://api.comicvine.com/"><span style=" text-decoration: underline; color:#0000ff;">http://api.comicvine.com/</span></a></p></body></html>
-
-
- Qt::RichText
-
-
- false
-
-
- true
-
-
- true
-
-
-
-
-
- 20
- 90
- 581
- 41
-
-
-
-
- QFormLayout::AllNonFixedFieldsGrow
-
- -
-
-
- Comic Vine API Key
-
-
-
- -
-
-
-
-
-
-
-
- 20
- 150
- 611
- 61
-
-
-
- <html><head/><body><p>In order to read/write to CBR/RAR archives, you will need to have the shareware tools from <a href="www.win-rar.com/download.html"><span style=" text-decoration: underline; color:#0000ff;">WinRAR</span></a> installed. </p></body></html>
-
-
- Qt::RichText
-
-
- Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft
-
-
- true
-
-
- true
-
-
-
-
-
- 20
- 220
- 611
- 71
-
-
-
-
- QFormLayout::AllNonFixedFieldsGrow
-
- -
-
-
- RAR program
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- UnRAR program
-
-
-
- -
-
-
- true
-
-
-
-
-
-
-
-
- 640
- 220
- 41
- 21
-
-
-
- ...
-
-
-
-
-
- 640
- 250
- 41
- 21
-
-
-
- ...
-
-
-
-
-
- 610
- 90
- 94
- 21
-
-
-
- Test Key
-
-
-
-
-
- 620
- 120
- 71
- 20
-
-
-
-
-
-
+
+ -
+
+
-
+
+
+ 0
+
+
+
+ General
+
+
+
-
+
+
+
+
+
+
+ -
+
+
-
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ ComicTagger keeps a cache of online data to improve speed. If you need to free up the disk space, or the responses seems out of date, clear it.
+
+
+ true
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Clear Cache
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ <html><head/><body><p>In order to read/write to CBR/RAR archives, you will need to have the shareware tools from <a href="www.win-rar.com/download.html"><span style=" text-decoration: underline; color:#0000ff;">WinRAR</span></a> installed. </p></body></html>
+
+
+ Qt::RichText
+
+
+ Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft
+
+
+ true
+
+
+ true
+
+
+ Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse
+
+
+
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 120
+ 0
+
+
+
+
+ 200
+ 16777215
+
+
+
+ RAR program
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ true
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ ...
+
+
+
+
+
+ -
+
+
-
+
+
+
+ 120
+ 0
+
+
+
+ UnRAR program
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+ Identifier
+
+
+ -
+
+
+ <html><head/><body><p>These settings are for the automatic issue identifier which searches online for matches. They will not affect "manual" searching.</p></body></html>
+
+
+ true
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ QFormLayout::AllNonFixedFieldsGrow
+
+
-
+
+
+ <html><head/><body><p>The "Name Length Delta Threshold" is for eliminating automatic search matches that are too long compared to your series name search. The higher it is, the more likely to have a good match, but each search will take longer and use more bandwidth. Too low, and only the very closest lexical matches will be explored.</p></body></html>
+
+
+ true
+
+
+
+ -
+
+
+ Name Length Delta Threshold:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ <html><head/><body><p>The "Publisher Blacklist" is for eliminating automatic matches to certain publishers that you know are incorrect. Useful for avoiding international re-prints with same covers or series names. Enter publisher names separated by commas.</p></body></html>
+
+
+ true
+
+
+
+ -
+
+
+ Publisher Blacklist:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
diff --git a/tagger.py b/tagger.py
index e4420f0..6128904 100755
--- a/tagger.py
+++ b/tagger.py
@@ -155,7 +155,7 @@ def process_file_cli( filename, opts, settings ):
# finally, search online
if opts.search_online:
- ii = IssueIdentifier( ca, "" )
+ ii = IssueIdentifier( ca, settings )
if md is None or md.isEmpty:
print "No metadata given to search online with!"
diff --git a/taggerwindow.py b/taggerwindow.py
index 6b6d586..6dd1a9e 100644
--- a/taggerwindow.py
+++ b/taggerwindow.py
@@ -912,7 +912,6 @@ class TaggerWindow( QtGui.QMainWindow):
ok_to_mod = True
if self.isDupeCredit( new_role, new_name):
# delete the dupe credit from list
- #TODO warn user!!
reply = QtGui.QMessageBox.question(self,
self.tr("Duplicate Credit!"),
self.tr("This will create a duplicate credit entry. Would you like to merge the entries, or create a duplicate?"),
diff --git a/todo.txt b/todo.txt
index 3a3f99e..da73b15 100644
--- a/todo.txt
+++ b/todo.txt
@@ -2,19 +2,6 @@
Features
----------------
-Raw Tag Block Window
-
-Settings/Preferences Dialog
- Remove API Key
- Add clear cache
- Add reset settings
- Tab w/Identifier Settings
- Add publisher blacklist
- other Identifier tunings
-
-save Last tag style
-save Last "Open" folder (include dragged)
-
Add class for warning/info messages with "Don't show again" checkbox.
Add list of these flags to settings
@@ -22,19 +9,23 @@ Style sheets for windows/mac/linux
Better stripping of html from CV text
+Add warning message to allow writing CBI to RAR, and ask them to contact CBL ! :-)
+
+Move RAR/CBL test into ComicArchive class, isWriteable
+
+
-----------------
Bugs
----------------
-Unicode errors when piping or redirecting stdout
-
-Broke windows installer graphics somehow
Windows zip and rar: set proper path for writing to archive
SERIOUS BUG: rebuilding zips!
http://stackoverflow.com/questions/11578443/trigger-io-errno-18-cross-device-link
-OSX:
+Frozen apps better finding of resource files
+
+OSX
toolbar
weird unrar complaints
Page browser sizing
@@ -49,14 +40,12 @@ Check all HTTP responses for errors
Lots of error checking
-
-------------
Future
------------
File rename
-Dialog??
-
TaggerWindow entry fields
Special tabbed Dialog needed for:
@@ -70,7 +59,6 @@ CLI
interactive for choices option?
--- or defer choices to end, by keeping special log of those files
-
Add warning message to allow writing CBI to RAR, and ask them to contact CBL ! :-)
Scrape alternate Covers from ComicVine issue pages
@@ -88,19 +76,14 @@ Wizard for converting between tag styles
App option to covert RAR to ZIP
-
Archive function to detect tag blocks out of sync
-
Idea: Support only CBI or CIX for any given file, and not both
If user selects different one, warn about potential loss/re-arranging of data
Longer term:
Think about mass tagging and (semi) automatic volume selection
-
--
-
----------------------------------------------
COMIC RACK Questions
diff --git a/volumeselectionwindow.py b/volumeselectionwindow.py
index 55e77e3..f0a56f7 100644
--- a/volumeselectionwindow.py
+++ b/volumeselectionwindow.py
@@ -124,8 +124,7 @@ class VolumeSelectionWindow(QtGui.QDialog):
self.iddialog.rejected.connect( self.identifyCancel )
self.iddialog.show()
- self.ii = IssueIdentifier( self.comic_archive, self.cv_api_key )
-
+ self.ii = IssueIdentifier( self.comic_archive, self.settings )
md = GenericMetadata()
md.series = self.series_name