Made image hashing use thumbnails from CV for faster downloads
Commented out hashing routines that use scipy and numpy, so that cxfreeze does make the dist explode in size: those routines are only marginally, if that, better git-svn-id: http://comictagger.googlecode.com/svn/trunk@26 6c5673fe-1810-88d6-992b-cd32ca31540c
This commit is contained in:
parent
b56adcc8c3
commit
cb427f49b8
@ -229,7 +229,7 @@ class ComicVineCacher:
|
||||
return result
|
||||
|
||||
|
||||
def add_issue_image_url( self, issue_id, image_url ):
|
||||
def add_issue_image_url( self, issue_id, image_url, thumb_image_url ):
|
||||
|
||||
con = lite.connect( self.db_file )
|
||||
|
||||
@ -239,6 +239,7 @@ class ComicVineCacher:
|
||||
|
||||
data = {
|
||||
"image_url": image_url,
|
||||
"thumb_image_url": thumb_image_url,
|
||||
"timestamp": timestamp
|
||||
}
|
||||
self.upsert( cur, "issues" , "id", issue_id, data)
|
||||
@ -251,13 +252,13 @@ class ComicVineCacher:
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
|
||||
cur.execute("SELECT image_url FROM Issues WHERE id=?", [ issue_id ])
|
||||
cur.execute("SELECT image_url,thumb_image_url FROM Issues WHERE id=?", [ issue_id ])
|
||||
row = cur.fetchone()
|
||||
|
||||
if row[0] is None :
|
||||
return None
|
||||
return None, None
|
||||
else:
|
||||
return row[0]
|
||||
return row[0],row[1]
|
||||
|
||||
|
||||
def upsert( self, cur, tablename, pkname, pkval, data):
|
||||
|
@ -231,15 +231,15 @@ class ComicVineTalker:
|
||||
|
||||
return newstring
|
||||
|
||||
def fetchIssueCoverURL( self, issue_id ):
|
||||
def fetchIssueCoverURLs( self, issue_id ):
|
||||
|
||||
# before we search online, look in our cache, since we might already
|
||||
# have this info
|
||||
cvc = ComicVineCacher( ComicTaggerSettings.getSettingsFolder() )
|
||||
cached_image_url = cvc.get_issue_image_url( issue_id )
|
||||
cached_image_url,cached_thumb_url = cvc.get_issue_image_url( issue_id )
|
||||
|
||||
if cached_image_url is not None:
|
||||
return cached_image_url
|
||||
return cached_image_url,cached_thumb_url
|
||||
|
||||
issue_url = "http://api.comicvine.com/issue/" + str(issue_id) + "/?api_key=" + self.api_key + "&format=json&field_list=image"
|
||||
resp = urllib2.urlopen(issue_url)
|
||||
@ -249,7 +249,7 @@ class ComicVineTalker:
|
||||
print ( "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] ))
|
||||
return None
|
||||
|
||||
cvc.add_issue_image_url( issue_id, cv_response['results']['image']['super_url'] )
|
||||
return cv_response['results']['image']['super_url']
|
||||
cvc.add_issue_image_url( issue_id, cv_response['results']['image']['super_url'], cv_response['results']['image']['thumb_url'] )
|
||||
return cv_response['results']['image']['super_url'], cv_response['results']['image']['thumb_url']
|
||||
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
import Image
|
||||
import StringIO
|
||||
|
||||
|
||||
|
||||
|
||||
class ImageHasher(object):
|
||||
def __init__(self, path=None, data=None, width=8, height=8):
|
||||
#self.hash_size = size
|
||||
@ -39,6 +36,8 @@ class ImageHasher(object):
|
||||
return result
|
||||
|
||||
def average_hash2( self ):
|
||||
pass
|
||||
"""
|
||||
# Got this one from somewhere on the net. Not a clue how the 'convolve2d'
|
||||
# works!
|
||||
|
||||
@ -56,8 +55,10 @@ class ImageHasher(object):
|
||||
0)
|
||||
#print "{0:016x}".format(result)
|
||||
return result
|
||||
|
||||
"""
|
||||
|
||||
def dct_average_hash(self):
|
||||
pass
|
||||
"""
|
||||
# Algorithm source: http://syntaxcandy.blogspot.com/2012/08/perceptual-hash.html
|
||||
|
||||
@ -96,6 +97,7 @@ class ImageHasher(object):
|
||||
7. Construct the hash. Set the 64 bits into a 64-bit integer. The order does not
|
||||
matter, just as long as you are consistent.
|
||||
"""
|
||||
"""
|
||||
import numpy
|
||||
import scipy.fftpack
|
||||
numpy.set_printoptions(threshold=10000, linewidth=200, precision=2, suppress=True)
|
||||
@ -132,9 +134,8 @@ class ImageHasher(object):
|
||||
|
||||
#print "{0:016x}".format(result)
|
||||
return result
|
||||
"""
|
||||
|
||||
|
||||
|
||||
#accepts 2 hashes (longs or hex strings) and returns the hamming distance
|
||||
|
||||
@staticmethod
|
||||
|
@ -122,7 +122,7 @@ class IssueSelectionWindow(QtGui.QDialog):
|
||||
# We don't yet have an image URL for this issue. Make a request for URL, and hold onto it
|
||||
# TODO: this should be reworked... too much UI latency, maybe chain the NAMs??
|
||||
if record['url'] == None:
|
||||
record['url'] = ComicVineTalker( self.cv_api_key ).fetchIssueCoverURL( self.issue_id )
|
||||
record['url'], dummy = ComicVineTalker( self.cv_api_key ).fetchIssueCoverURLs( self.issue_id )
|
||||
|
||||
self.labelThumbnail.setText("loading...")
|
||||
self.nam = QNetworkAccessManager()
|
||||
|
@ -160,9 +160,9 @@ def cliProcedure( opts, settings ):
|
||||
# look for a matching issue number
|
||||
if num_s == search_issue_number:
|
||||
# found a matching issue number! now get the issue data
|
||||
img_url = comicVine.fetchIssueCoverURL( issue['id'] )
|
||||
#TODO get the URL, and calc hash!!
|
||||
url_image_data = urllib.urlopen(img_url).read()
|
||||
img_url, thumb_url = comicVine.fetchIssueCoverURLs( issue['id'] )
|
||||
#TODO get the image from URL, and calc hash!!
|
||||
url_image_data = urllib.urlopen(thumb_url).read()
|
||||
|
||||
if opts.image_hasher == '3':
|
||||
url_image_hash = ImageHasher( data=url_image_data ).dct_average_hash()
|
||||
@ -177,7 +177,7 @@ def cliProcedure( opts, settings ):
|
||||
match['issue_number'] = num_s
|
||||
match['url_image_hash'] = url_image_hash
|
||||
match['issue_title'] = issue['name']
|
||||
match['img_url'] = img_url
|
||||
match['img_url'] = thumb_url
|
||||
match_list.append(match)
|
||||
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user