1
'''Interface for image and video thumbnailers'''
4
__copyright__ = "2008, Paul Hummer"
5
__author__ = "Paul Hummer <paul@ironlionsoftware.no.spam.com>"
14
from entertainerlib.exceptions import ThumbnailerException
15
from entertainerlib.utils.configuration import Configuration
17
class Thumbnailer(object):
18
""" Thumbnailer interface for video and image thumbnailers. """
23
def __init__(self, filename, thumb_type):
25
self.config = Configuration()
26
thumb_dir = os.path.join(self.config.THUMB_DIR, thumb_type)
27
self.filename = filename
29
filehash = hashlib.md5()
32
filehash.update(self.filename)
33
self.filename_hash = filehash.hexdigest()
35
if not os.path.exists(self.filename):
36
raise ThumbnailerException(
37
'File to thumbnail does not exist : %s' % self.filename)
39
if os.path.exists(thumb_dir):
40
if os.path.isfile(filename):
41
self._thumb_file = os.path.join(thumb_dir,
42
self.filename_hash + '.jpg')
44
raise ThumbnailerException(
45
'Thumbnailer filename is a folder : %s' % self.filename)
47
raise ThumbnailerException('Unknown thumbnail type : %s' % (
51
'''Get the hash of the filename'''
52
return self.filename_hash
54
def create_thumbnail(self):
56
Implement this method in deriving classes.
58
Method should create a new thumbnail and save it to the Entertainer's
59
thumbnail directory in JPEG format. Thumbnail filename should be a MD5
60
hash of the absolute path of the original file.
62
raise NotImplementedError