diff options
-rw-r--r-- | anidb.py | 14 | ||||
-rw-r--r-- | pyanidb.conf | 5 | ||||
-rw-r--r-- | pyanidb/hash.py | 8 |
3 files changed, 24 insertions, 3 deletions
@@ -1,5 +1,9 @@ #!/usr/bin/env python +# Get rid of annoying warning about API mismatch. +import warnings +warnings.filterwarnings('ignore', 'Python C API version mismatch for module _multihash: This Python has API version 1013, module _multihash has version 1012.', RuntimeWarning) + import pyanidb, pyanidb.hash import ConfigParser, optparse, os, sys, getpass @@ -37,6 +41,8 @@ op.add_option('-s', '--suffix', help = 'File suffix for recursive matching.', op.add_option('-c', '--no-cache', help = 'Do not use cached values.', action = 'store_false', dest = 'cache', default = int(config.get('cache', '1'))) +op.add_option('-m', '--multihash', help = 'Calculate additional checksums.', + action = 'store_true', dest = 'multihash', default = False) op.add_option('-i', '--identify', help = 'Identify files.', action = 'store_true', dest = 'identify', default = False) op.add_option('-a', '--add', help = 'Add files to mylist.', @@ -111,13 +117,19 @@ if options.login: hashed = unknown = 0 -for file in pyanidb.hash.hash_files(files, options.cache): +for file in pyanidb.hash.hash_files(files, options.cache, (('ed2k', 'md5', 'sha1', 'crc32') if options.multihash else ('ed2k',))): print blue('Hashed:'), 'ed2k://|file|%s|%d|%s|%s' % (file.name, file.size, file.ed2k, ' (cached)' if file.cached else '') fid = (file.size, file.ed2k) hashed += 1 try: + # Multihash. + if options.multihash: + print blue('MD5:'), file.md5 + print blue('SHA1:'), file.sha1 + print blue('CRC32:'), file.crc32 + # Identify. if options.identify: diff --git a/pyanidb.conf b/pyanidb.conf index 89807a0..52e55f9 100644 --- a/pyanidb.conf +++ b/pyanidb.conf @@ -4,5 +4,8 @@ username = foo password = password -suffix = avi ogm mkv +suffix = avi ogm mkv mp4 format = _[%group]_%anime_-_%epno%ver_[%CRC].%suf + +# Uncomment this to disable caching. +#cache = 0
\ No newline at end of file diff --git a/pyanidb/hash.py b/pyanidb/hash.py index d655d53..a748f9e 100644 --- a/pyanidb/hash.py +++ b/pyanidb/hash.py @@ -29,12 +29,18 @@ class File: def write_cache(self): try: + self.clear_cache() xattr.setxattr(self.name, 'user.pyanidb.mtime', str(int(self.mtime))) for n in ('ed2k', 'md5', 'sha1', 'crc32'): if hasattr(self, n): xattr.setxattr(self.name, 'user.pyanidb.' + n, getattr(self, n)) except IOError: pass + + def clear_cache(self): + for name in xattr.listxattr(self.name): + if name.startswith('user.pyanidb.'): + xattr.removexattr(self.name, name) class Hashthread(threading.Thread): def __init__(self, filelist, hashlist, algorithms, cache, *args, **kwargs): @@ -51,7 +57,7 @@ class Hashthread(threading.Thread): except IndexError: return -def hash_files(files, cache = False, num_threads = 1, algorithms = ('ed2k',)): +def hash_files(files, cache = False, algorithms = ('ed2k',), num_threads = 1): hashlist = [] threads = [] for x in xrange(num_threads): |